-
-
Save egonelbre/2243a7ebf60e66bf377fa8ef737566b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player { | |
public String myName = ""; | |
public Player(String playerName){ | |
myName = playerName.clone(); | |
} | |
public String name(){ | |
return myName; | |
} | |
public void say(){ | |
System.out.println("[" + this.name() + "] says hello!"); | |
} | |
} | |
class Interview { | |
public Interview(){} | |
//TODO: not sure how can I use Player here instead of Object | |
public void DoInterview(Object player1, Object player2) { | |
System.out.println("[Interviewer] Hello!"); | |
if(player1 is player2){ | |
System.out.println("Equality"); | |
} | |
} | |
} | |
context Battle { | |
String Id; | |
public Battle(String battleId, Player firstPlayer, Player secondPlayer){ | |
Id = battleId.clone(); | |
Bear = firstPlayer; | |
Lion = secondPlayer; | |
} | |
role Bear { | |
public void say(){ | |
System.out.println(" [" + this.name() + "] Grrrr..." ); | |
} | |
public void fight(){ | |
Bear.say(); | |
Lion.fight(); | |
} | |
} requires { | |
String name(); | |
} | |
role Lion { | |
public void say(){ | |
System.out.println(" [" + this.name() + "] Meow..." ); | |
} | |
public void fight(){ | |
Lion.say(); | |
} | |
} requires { | |
String name(); | |
} | |
public void start(){ | |
System.out.println(Id + " battle commencing"); | |
Bear.fight(); | |
} | |
public void interview(){ | |
new Interview().DoInterview(Lion, Bear); | |
} | |
} | |
class Tournament { | |
public Tournament(){} | |
public void run(){ | |
Player player = new Player("Jack"); | |
Player cpu = new Player("Cyborg"); | |
Battle b1 = new Battle("1", player, cpu); | |
Battle b2 = new Battle("2", cpu, player); | |
Battle b3 = new Battle("3", cpu, cpu); | |
b1.start(); | |
b2.start(); | |
b3.start(); | |
b1.interview(); | |
b3.interview(); | |
} | |
} | |
new Tournament().run() | |
/* GOLD: | |
line 33: WARNING: Both class `Player' and Role `Bear' contain the same script signature `say()'. This results in several scripts of the same name in the same object and may not behave as you expected. | |
line 34: WARNING: Both class `Player' and Role `Lion' contain the same script signature `say()'. This results in several scripts of the same name in the same object and may not behave as you expected. | |
2 warnings, 0 errors. | |
___________________________________________________________ | |
Object of type Player playing too many roles, including Bear | |
In Context `Battle': Lion. | |
In Context `Battle': Bear. | |
Objects may play Role(s) only in one Context at a time (note: this does not apply to Stage Props). | |
Further execution may exhibit undefined behaviour. | |
Object of type Player playing too many roles, including Lion | |
In Context `Battle': Bear. | |
In Context `Battle': Lion. | |
Objects may play Role(s) only in one Context at a time (note: this does not apply to Stage Props). | |
Further execution may exhibit undefined behaviour. | |
Object of type Player playing too many roles, including Bear | |
In Context `Battle': Lion. | |
In Context `Battle': Bear. | |
In Context `Battle': Bear. | |
Objects may play Role(s) only in one Context at a time (note: this does not apply to Stage Props). | |
Further execution may exhibit undefined behaviour. | |
Object of type Player playing too many roles, including Lion | |
In Context `Battle': Lion. | |
In Context `Battle': Bear. | |
In Context `Battle': Bear, Lion. | |
Objects may play Role(s) only in one Context at a time (note: this does not apply to Stage Props). | |
Further execution may exhibit undefined behaviour. | |
1 battle commencing | |
[Jack] Grrrr... | |
[Cyborg] Meow... | |
2 battle commencing | |
[Cyborg] Grrrr... | |
[Jack] Meow... | |
3 battle commencing | |
[Cyborg] Grrrr... | |
[Cyborg] Meow... | |
[Interviewer] Hello! | |
[Interviewer] Hello! | |
Equality | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player { | |
public String myName = ""; | |
public Player(String playerName){ | |
myName = playerName.clone(); | |
} | |
public String name(){ | |
return myName; | |
} | |
public void say(){ | |
System.out.println("[" + this.name() + "] says hello!"); | |
} | |
} | |
class Interview { | |
public Interview(){} | |
//TODO: not sure how can I use Player here instead of Object | |
public void DoInterview(Object player1, Object player2) { | |
System.out.println("[Interviewer] Hello!"); | |
if(player1 is player2){ | |
System.out.println("Equality"); | |
} | |
} | |
} | |
context Battle { | |
String Id; | |
public Battle(String battleId, Player firstPlayer, Player secondPlayer){ | |
Id = battleId.clone(); | |
Bear = firstPlayer; | |
Lion = secondPlayer; | |
} | |
role Bear { | |
public void intimidate(){ | |
System.out.println(" [" + this.name() + "] Grrrr..." ); | |
} | |
public void fight(){ | |
Bear.intimidate(); | |
Lion.fight(); | |
} | |
} requires { | |
String name(); | |
} | |
role Lion { | |
public void intimidate(){ | |
System.out.println(" [" + this.name() + "] Meow..." ); | |
} | |
public void fight(){ | |
Lion.intimidate(); | |
} | |
} requires { | |
String name(); | |
} | |
public void start(){ | |
System.out.println(Id + " battle commencing"); | |
Bear.fight(); | |
} | |
public void interview(){ | |
new Interview().DoInterview(Lion, Bear); | |
} | |
} | |
class Tournament { | |
public Tournament(){} | |
public void run(){ | |
Player player = new Player("Jack"); | |
Player cpu = new Player("Cyborg"); | |
Battle b1 = new Battle("1", player, cpu); | |
Battle b2 = new Battle("2", cpu, player); | |
Battle b3 = new Battle("3", cpu, cpu); | |
b1.start(); | |
b2.start(); | |
b3.start(); | |
b1.interview(); | |
b3.interview(); | |
} | |
} | |
new Tournament().run() | |
/*GOLD: | |
0 warnings, 0 errors. | |
___________________________________________________________ | |
Object of type Player playing too many roles, including Bear | |
In Context `Battle': Lion. | |
In Context `Battle': Bear. | |
Objects may play Role(s) only in one Context at a time (note: this does not apply to Stage Props). | |
Further execution may exhibit undefined behaviour. | |
Object of type Player playing too many roles, including Lion | |
In Context `Battle': Bear. | |
In Context `Battle': Lion. | |
Objects may play Role(s) only in one Context at a time (note: this does not apply to Stage Props). | |
Further execution may exhibit undefined behaviour. | |
Object of type Player playing too many roles, including Bear | |
In Context `Battle': Lion. | |
In Context `Battle': Bear. | |
In Context `Battle': Bear. | |
Objects may play Role(s) only in one Context at a time (note: this does not apply to Stage Props). | |
Further execution may exhibit undefined behaviour. | |
Object of type Player playing too many roles, including Lion | |
In Context `Battle': Lion. | |
In Context `Battle': Bear. | |
In Context `Battle': Bear, Lion. | |
Objects may play Role(s) only in one Context at a time (note: this does not apply to Stage Props). | |
Further execution may exhibit undefined behaviour. | |
1 battle commencing | |
2 battle commencing | |
3 battle commencing | |
[Interviewer] Hello! | |
[Interviewer] Hello! | |
Equality | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player { | |
public String myName = ""; | |
public Player(String playerName){ | |
myName = playerName.clone(); | |
} | |
public String name(){ | |
return myName; | |
} | |
public void say(){ | |
System.out.println("[" + this.name() + "] says hello!"); | |
} | |
} | |
class Interview { | |
public Interview(){} | |
//TODO: not sure how can I use Player here instead of Object | |
public void DoInterview(Object player1, Object player2) { | |
System.out.println("[Interviewer] Hello!"); | |
if(player1 is player2){ | |
System.out.println("Equality"); | |
} | |
} | |
} | |
context Battle { | |
String Id; | |
public Battle(String battleId, Player firstPlayer, Player secondPlayer){ | |
Id = battleId.clone(); | |
Bear = firstPlayer; | |
Lion = secondPlayer; | |
} | |
role Bear { | |
public void intimidate(){ | |
System.out.println(" [" + this.name() + "] Grrrr..." ); | |
} | |
public void fight(){ | |
Bear.intimidate(); | |
Lion.fight(); | |
} | |
} requires { | |
String name(); | |
} | |
role Lion { | |
public void intimidate(){ | |
System.out.println(" [" + this.name() + "] Meow..." ); | |
} | |
public void fight(){ | |
Lion.intimidate(); | |
} | |
} requires { | |
String name(); | |
} | |
public void start(){ | |
System.out.println(Id + " battle commencing"); | |
Bear.fight(); | |
} | |
public void interview(){ | |
new Interview().DoInterview(Lion, Bear); | |
} | |
} | |
class Tournament { | |
public Tournament(){} | |
public void run(){ | |
Player player = new Player("Jack"); | |
Player cpu = new Player("Cyborg"); | |
Battle b1 = new Battle("1", player, cpu); | |
b1.start(); | |
b1.interview(); | |
Battle b2 = new Battle("2", cpu, player); | |
b2.start(); | |
Battle b3 = new Battle("3", cpu, cpu); | |
b3.start(); | |
b3.interview(); | |
} | |
} | |
new Tournament().run() | |
/*GOLD: | |
0 warnings, 0 errors. | |
___________________________________________________________ | |
1 battle commencing | |
[Jack] Grrrr... | |
[Cyborg] Meow... | |
[Interviewer] Hello! | |
Object of type Player playing too many roles, including Bear | |
In Context `Battle': Lion. | |
In Context `Battle': Bear. | |
Objects may play Role(s) only in one Context at a time (note: this does not apply to Stage Props). | |
Further execution may exhibit undefined behaviour. | |
Object of type Player playing too many roles, including Lion | |
In Context `Battle': Bear. | |
In Context `Battle': Lion. | |
Objects may play Role(s) only in one Context at a time (note: this does not apply to Stage Props). | |
Further execution may exhibit undefined behaviour. | |
2 battle commencing | |
[Cyborg] Grrrr... | |
[Jack] Meow... | |
Object of type Player playing too many roles, including Bear | |
In Context `Battle': Lion. | |
In Context `Battle': Bear. | |
In Context `Battle': Bear. | |
Objects may play Role(s) only in one Context at a time (note: this does not apply to Stage Props). | |
Further execution may exhibit undefined behaviour. | |
Object of type Player playing too many roles, including Lion | |
In Context `Battle': Lion. | |
In Context `Battle': Bear. | |
In Context `Battle': Bear, Lion. | |
Objects may play Role(s) only in one Context at a time (note: this does not apply to Stage Props). | |
Further execution may exhibit undefined behaviour. | |
3 battle commencing | |
[Cyborg] Grrrr... | |
[Cyborg] Meow... | |
[Interviewer] Hello! | |
Equality | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment