51 lines
1.2 KiB
Java
51 lines
1.2 KiB
Java
|
//: enums/RoShamBo2.java
|
|||
|
// <20>2015 MindView LLC: see Copyright.txt
|
|||
|
// Switching one enum on another.
|
|||
|
package enums;
|
|||
|
import static enums.Outcome.*;
|
|||
|
|
|||
|
public enum RoShamBo2 implements Competitor<RoShamBo2> {
|
|||
|
PAPER(DRAW, LOSE, WIN),
|
|||
|
SCISSORS(WIN, DRAW, LOSE),
|
|||
|
ROCK(LOSE, WIN, DRAW);
|
|||
|
private Outcome vPAPER, vSCISSORS, vROCK;
|
|||
|
RoShamBo2(Outcome paper,Outcome scissors,Outcome rock) {
|
|||
|
this.vPAPER = paper;
|
|||
|
this.vSCISSORS = scissors;
|
|||
|
this.vROCK = rock;
|
|||
|
}
|
|||
|
@Override
|
|||
|
public Outcome compete(RoShamBo2 it) {
|
|||
|
switch(it) {
|
|||
|
default:
|
|||
|
case PAPER: return vPAPER;
|
|||
|
case SCISSORS: return vSCISSORS;
|
|||
|
case ROCK: return vROCK;
|
|||
|
}
|
|||
|
}
|
|||
|
public static void main(String[] args) {
|
|||
|
RoShamBo.play(RoShamBo2.class, 20);
|
|||
|
}
|
|||
|
} /* Output:
|
|||
|
ROCK vs. ROCK: DRAW
|
|||
|
SCISSORS vs. ROCK: LOSE
|
|||
|
SCISSORS vs. ROCK: LOSE
|
|||
|
SCISSORS vs. ROCK: LOSE
|
|||
|
PAPER vs. SCISSORS: LOSE
|
|||
|
PAPER vs. PAPER: DRAW
|
|||
|
PAPER vs. SCISSORS: LOSE
|
|||
|
ROCK vs. SCISSORS: WIN
|
|||
|
SCISSORS vs. SCISSORS: DRAW
|
|||
|
ROCK vs. SCISSORS: WIN
|
|||
|
SCISSORS vs. PAPER: WIN
|
|||
|
SCISSORS vs. PAPER: WIN
|
|||
|
ROCK vs. PAPER: LOSE
|
|||
|
ROCK vs. SCISSORS: WIN
|
|||
|
SCISSORS vs. ROCK: LOSE
|
|||
|
PAPER vs. SCISSORS: LOSE
|
|||
|
SCISSORS vs. PAPER: WIN
|
|||
|
SCISSORS vs. PAPER: WIN
|
|||
|
SCISSORS vs. PAPER: WIN
|
|||
|
SCISSORS vs. PAPER: WIN
|
|||
|
*///:~
|