-
Notifications
You must be signed in to change notification settings - Fork 590
Expand file tree
/
Copy pathController.java
More file actions
57 lines (46 loc) · 1.59 KB
/
Controller.java
File metadata and controls
57 lines (46 loc) · 1.59 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
package baseball;
import baseball.service.GameService;
import baseball.view.RequestInput;
import baseball.view.SystemMessage;
import camp.nextstep.edu.missionutils.Console;
public class Controller {
final int SIZE = 3;
final int START_INCLUSIVE = 1;
final int END_INCLUSIVE = 9;
final int RETRY = 1;
final int GAME_OVER = 2;
GameService gameService = new GameService();
public void run() throws IllegalArgumentException {
setGame();
startGame();
endGame();
askRetry();
}
private void setGame() {
gameService.setGame(SIZE, START_INCLUSIVE, END_INCLUSIVE);
}
private void startGame() throws IllegalArgumentException {
gameService.playGame();
}
private void endGame() {
SystemMessage.printGameOverMessage();
}
/**
* 유저입력이 (문자 or 0 or 3 이상) : Exception
* 유저입력이 (1) : 재시작
* 유저입력이 (2) : 종료
*/
private void askRetry() throws IllegalArgumentException {
RequestInput.printRetryMessage();
if (getInputNum() == RETRY) {
run();
}
}
private int getInputNum() throws IllegalArgumentException {
int inputNum = Integer.parseInt(Console.readLine());
if (inputNum == 0 || inputNum > GAME_OVER) {
throw new IllegalArgumentException();
}
return inputNum;
}
}