-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Break out common code from RoShamBo1.java, reuse in patterns
- Loading branch information
1 parent
ede3954
commit a75a55d
Showing
8 changed files
with
156 additions
and
569 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// enums/Item.java | ||
// (c)2021 MindView LLC: see Copyright.txt | ||
// We make no guarantees that this code is fit for any purpose. | ||
// Visit http://OnJava8.com for more book information. | ||
package enums; | ||
|
||
public interface Item { | ||
Outcome compete(Item it); | ||
Outcome eval(Paper p); | ||
Outcome eval(Scissors s); | ||
Outcome eval(Rock r); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// enums/Paper.java | ||
// (c)2021 MindView LLC: see Copyright.txt | ||
// We make no guarantees that this code is fit for any purpose. | ||
// Visit http://OnJava8.com for more book information. | ||
package enums; | ||
import static enums.Outcome.*; | ||
|
||
public class Paper implements Item { | ||
@Override public Outcome compete(Item it) { | ||
return it.eval(this); | ||
} | ||
@Override | ||
public Outcome eval(Paper p) { return DRAW; } | ||
@Override | ||
public Outcome eval(Scissors s) { return WIN; } | ||
@Override | ||
public Outcome eval(Rock r) { return LOSE; } | ||
@Override public String toString() { | ||
return "Paper"; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// enums/Rock.java | ||
// (c)2021 MindView LLC: see Copyright.txt | ||
// We make no guarantees that this code is fit for any purpose. | ||
// Visit http://OnJava8.com for more book information. | ||
package enums; | ||
import static enums.Outcome.*; | ||
|
||
public class Rock implements Item { | ||
@Override public Outcome compete(Item it) { | ||
return it.eval(this); | ||
} | ||
@Override | ||
public Outcome eval(Paper p) { return WIN; } | ||
@Override | ||
public Outcome eval(Scissors s) { return LOSE; } | ||
@Override | ||
public Outcome eval(Rock r) { return DRAW; } | ||
@Override public String toString() { | ||
return "Rock"; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// enums/Scissors.java | ||
// (c)2021 MindView LLC: see Copyright.txt | ||
// We make no guarantees that this code is fit for any purpose. | ||
// Visit http://OnJava8.com for more book information. | ||
package enums; | ||
import static enums.Outcome.*; | ||
|
||
public class Scissors implements Item { | ||
@Override public Outcome compete(Item it) { | ||
return it.eval(this); | ||
} | ||
@Override | ||
public Outcome eval(Paper p) { return LOSE; } | ||
@Override | ||
public Outcome eval(Scissors s) { return DRAW; } | ||
@Override | ||
public Outcome eval(Rock r) { return WIN; } | ||
@Override public String toString() { | ||
return "Scissors"; | ||
} | ||
} |
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
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