-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJudgeNum.java
73 lines (65 loc) · 1.25 KB
/
JudgeNum.java
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package process;
import state.Number;
public class JudgeNum {
private int hit;
private int brow;
private Number num;
private String[] printNum = new String[3];
// Number作成
JudgeNum() {
Number num = new Number();
this.num = num;
}
// Hit&Brow判定メソッド
void answerNum(int[] in) {
// 答え
int[] ans = num.getNum();
hit = 0;
brow = 0;
// hit判定
for (int i = 0; i < 3; i++) {
// hit判定
if (ans[i] == in[i]) {
hit++;
printNum[i] = Integer.toString(in[i]);
} else {
// hitが3の場合クリア
if (hit == 3)
return;
// Brow判定
for (int j = 0; j < 3; j++) {
// 同一はHitのみなので処理しない
if (ans[i] == in[j] && i != j) {
brow++;
}
}
}
}
}
// 出力
void printNum() {
System.out.print("CPU > ");
for (int i = 0; i < 3; i++) {
if (null == printNum[i]) {
printNum[i] = "■";
}
System.out.print(printNum[i] + " ");
}
System.out.println();
}
// Debug用
void debugNum() {
int[] debugNum = num.getNum();
System.out.print("CPU > ");
for (int i = 0; i < 3; i++) {
System.out.print(debugNum[i] + " ");
}
System.out.println();
}
int getHit() {
return this.hit;
}
int getBrow() {
return this.brow;
}
}