forked from woowacourse-precourse/java-baseball-6
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathNumberChecker.java
More file actions
35 lines (32 loc) · 1.06 KB
/
NumberChecker.java
File metadata and controls
35 lines (32 loc) · 1.06 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
package baseball;
import java.util.*;
import camp.nextstep.edu.missionutils.Randoms;
public class NumberChecker {
public boolean checkNumber(List<Integer> computerNum, List<Integer> userNum) {
int strike = 0;
int ball = 0;
for (int i = 0; i < 3; i++) {
if (userNum.get(i).equals(computerNum.get(i))) {
strike++;
} else if (computerNum.contains(userNum.get(i))) {
ball++;
}
}
if (strike == 0 && ball == 0) {
System.out.println("낫싱");
} else if (strike == 3) {
System.out.println(strike + "스트라이크");
System.out.println("3개의 숫자를 모두 맞히셨습니다! 게임 종료");
return false; // 게임 종료
} else {
if (ball > 0) {
System.out.print(ball + "볼 ");
}
if (strike > 0) {
System.out.print(strike + "스트라이크");
}
System.out.println();
}
return true;
}
}