forked from woowacourse-precourse/java-baseball-6
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.java
More file actions
59 lines (46 loc) · 2.03 KB
/
Application.java
File metadata and controls
59 lines (46 loc) · 2.03 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package baseball;
import baseball.rule.CountNums;
import baseball.rule.CreateRandomNum;
import baseball.rule.*;
import camp.nextstep.edu.missionutils.Console;
import java.util.*;
public class Application {
public static void main(String[] args) {
boolean playAgain = true;
View.PrintGameStart();
while (playAgain) {
//난수 생성
List<Integer> computerNumbers = CreateRandomNum.ComputerRandomNumbers();
boolean gameWon = true;
//사용자 입력 및 게임 실행
while (gameWon) {
String userInput = View.readUserNumbers();
InputValidator.validate(userInput);
List<Integer> userNumbers = Conversion.convertToIntegerList(userInput); // 입력값 -> 정수
Result result = CountNums.getResult(computerNumbers, userNumbers); // strike, ball 계산
if (result.isAllStrike()) { // result.isAllStrike()
System.out.println("3스트라이크");
System.out.println("3개의 숫자를 모두 맞히셨습니다! 게임 종료");
gameWon = false;
} else if (!result.isNothing()) {
System.out.printf("%d볼 %d스트라이크\n", result.balls, result.strikes);
} else {
System.out.println("낫싱");
}
}
// 게임 재시작 여부
System.out.println("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요.");
String restart = Console.readLine(); // 1 또는 2 입력
if (restart.equals("1")) {
playAgain = true;
} else if (restart.equals("2")) {
playAgain = false;
} else {
System.out.println("잘못된 값을 입력하셨습니다. 게임을 종료합니다.");
throw new IllegalArgumentException();
}
}
View.PrintGameEnd();
Console.close();
}
}