-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameController.java
More file actions
67 lines (53 loc) · 1.81 KB
/
GameController.java
File metadata and controls
67 lines (53 loc) · 1.81 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
60
61
62
63
64
65
66
67
package baseball.controller;
import baseball.model.*;
import baseball.view.InputView;
import baseball.view.OutputView;
import java.util.List;
import static baseball.model.GameProcessDecider.GAME_RESTART;
import static baseball.model.GameStatus.GAME_RUNNING;
import static baseball.model.GameStatus.GAME_TERMINATE;
public class GameController {
private static GameStatus gameStatus;
private Computer computer;
private User user;
public GameController() {
computer = new Computer();
gameStatus = GAME_RUNNING;
}
public void run() {
// 게임 시작
OutputView.printGameStart();
while (gameStatus.isGameNotTerminated()) {
// User - Baseball 입력
readUserBaseballInput();
// 게임 결과 확인
Result result = judgeGameByReferee();
OutputView.printGameResult(result);
// 게임 클리어 확인
checkGameClear(result);
}
}
private void readUserBaseballInput() {
List<Integer> userBaseballs = InputView.readUserBaseballs();
user = new User(userBaseballs);
}
private Result judgeGameByReferee() {
return Referee.judge(computer.getBaseballs(), user.getBaseballs());
}
private void checkGameClear(final Result result) {
if (result.isGameClear()) {
OutputView.printGameClear();
determineGameRestartOrEnd();
}
}
private void determineGameRestartOrEnd() {
int userCommand = InputView.readUserRestartCommand();
GameProcessDecider decider = GameProcessDecider.getDecider(userCommand);
if (decider == GAME_RESTART) {
computer = new Computer();
gameStatus = GAME_RUNNING;
} else {
gameStatus = GAME_TERMINATE;
}
}
}