-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathPlay_Controller.java
More file actions
51 lines (41 loc) · 1.32 KB
/
Copy pathPlay_Controller.java
File metadata and controls
51 lines (41 loc) · 1.32 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
package baseball.Controller;
import baseball.Service.Game_Service;
import baseball.View.RequestMessage;
import baseball.View.SystemMessage;
import camp.nextstep.edu.missionutils.Console;
public class Play_Controller {
private static final int NUM_SIZE = 3;
private static final int START = 1;
private static final int END = 9;
private static final int RETRY = 1;
private static final int GAME_OVER = 2;
Game_Service gameService = new Game_Service();
public void runGame() throws IllegalArgumentException {
setGame();
startGame();
endGame();
askRetry();
}
private void setGame() {
gameService.setGame(NUM_SIZE, START, END);
}
private void startGame() throws IllegalArgumentException {
gameService.playGame();
}
private void endGame() {
SystemMessage.printGameOverMessage();
}
private void askRetry() throws IllegalArgumentException {
RequestMessage.printRetryMessage();
if (getInputNum() == RETRY) {
runGame();
}
}
private int getInputNum() throws IllegalArgumentException {
int inputNum = Integer.parseInt(Console.readLine());
if (inputNum == 0 || inputNum > GAME_OVER) {
throw new IllegalArgumentException();
}
return inputNum;
}
}