-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoShamBo3.java
More file actions
31 lines (29 loc) · 862 Bytes
/
Copy pathRoShamBo3.java
File metadata and controls
31 lines (29 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package EnumMethod;
//实现competetor的实现第一个分发
public enum RoShamBo3 implements Competitor<RoShamBo3>{
ROCK{
@Override
public OutCome compete(RoShamBo3 competitor) {
return compete(SCISSORS,competitor);
}
},
SCISSORS{
@Override
public OutCome compete(RoShamBo3 competitor) {
return compete(PAPER,competitor);
}
}
,PAPER{
@Override
public OutCome compete(RoShamBo3 competitor) {
return compete(ROCK,competitor);
}
};
//两个参数的方法实现第二个分发
OutCome compete(RoShamBo3 loser,RoShamBo3 oppo){
return ((oppo == this) ? OutCome.DRAW:((oppo == loser)?OutCome.WIN:OutCome.LOSE));
}
public static void main(String[] args) {
RoShamBo.play(RoShamBo3.class,20);
}
}