forked from hazukac/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHand.java
More file actions
41 lines (41 loc) · 1.09 KB
/
Copy pathHand.java
File metadata and controls
41 lines (41 loc) · 1.09 KB
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
32
33
34
35
36
37
38
39
40
41
public class Hand {
public static final int HANDVALUE_GU = 0;
public static final int HANDVALUE_CH = 1;
public static final int HANDVALUE_PA = 2;
public static final Hand[] hands = {
new Hand(HANDVALUE_GU),
new Hand(HANDVALUE_CH),
new Hand(HANDVALUE_PA),
};
private static final String[] names = {
"グー",
"チョキ",
"パー",
};
private int value;
private Hand(int value) {
this.value = value;
}
public static Hand getHand(int value) {
System.out.println("???? value" + value);
return Hand.hands[value];
}
public boolean isStrongerThan(Hand h) {
return this.getResult(h) == 1;
}
public boolean isWeakerThan(Hand h) {
return this.getResult(h) == -1;
}
private int getResult(Hand opponent) {
if (this.value == opponent.value) {
return 0;
}
if ((this.value + 1) % 3 == opponent.value) {
return 1;
}
return -1;
}
public String toString() {
return this.names[this.value];
}
}