OnJava8-Examples/enumerated/RoShamBo4.java

33 lines
852 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: enumerated/RoShamBo4.java
2015-05-29 14:18:51 -07:00
// <20>2015 MindView LLC: see Copyright.txt
2015-04-20 15:36:01 -07:00
package enumerated;
public enum RoShamBo4 implements Competitor<RoShamBo4> {
ROCK {
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
public Outcome compete(RoShamBo4 opponent) {
return compete(SCISSORS, opponent);
}
},
SCISSORS {
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
public Outcome compete(RoShamBo4 opponent) {
return compete(PAPER, opponent);
}
},
PAPER {
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
public Outcome compete(RoShamBo4 opponent) {
return compete(ROCK, opponent);
}
};
Outcome compete(RoShamBo4 loser, RoShamBo4 opponent) {
return ((opponent == this) ? Outcome.DRAW
: ((opponent == loser) ? Outcome.WIN
: Outcome.LOSE));
}
public static void main(String[] args) {
RoShamBo.play(RoShamBo4.class, 20);
}
} /* Same output as RoShamBo2.java *///:~