forked from woowacourse-precourse/java-baseball-6
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathGameController.java
More file actions
44 lines (37 loc) · 1.49 KB
/
GameController.java
File metadata and controls
44 lines (37 loc) · 1.49 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
package baseball;
import java.util.*;
import camp.nextstep.edu.missionutils.Console;
import camp.nextstep.edu.missionutils.Randoms;
public class GameController {
public static void startGame() {
boolean again = true;
System.out.println("숫자 야구 게임을 시작합니다.");
while (again) {
NumberGenerator numberGenerator = new NumberGenerator();
List<Integer> computerNum = numberGenerator.getRandomComputerNumber();
boolean baseballGame = true;
while (baseballGame) {
InputHandler inputHandler = new InputHandler();
List<Integer> userNum = inputHandler.getUserInput();
NumberChecker numberChecker = new NumberChecker();
baseballGame = numberChecker.checkNumber(computerNum, userNum);
}
again = askForRestart();
}
}
private static boolean askForRestart() {
try {
System.out.println("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요.");
int restart = Integer.parseInt(Console.readLine());
if (restart == 1) {
return true;
} else if (restart == 2) {
return false;
} else {
throw new IllegalArgumentException();
}
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("잘못된 입력입니다. 게임을 종료합니다.");
}
}
}