-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
36 lines (31 loc) · 1.07 KB
/
Game.java
File metadata and controls
36 lines (31 loc) · 1.07 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
package baseball.controller;
import baseball.domain.Number;
import baseball.domain.Result;
import baseball.validator.InputValidator;
import baseball.view.InputView;
import baseball.view.OutputView;
import static baseball.view.OutputView.printStaticNotice;
import static baseball.view.constants.StaticNotice.GAME_START;
public class Game {
public void start() {
printStaticNotice(GAME_START);
do {
Number computerNumber = Number.generateRandomNumbers();
play(computerNumber);
} while (!askRestartOrExit());
}
private void play(Number computerNumber) {
while (true) {
Number playerNumber = Number.inputPlayerNumbers();
Result result = Result.create(playerNumber, computerNumber);
OutputView.printMessage(result.createResultMessage());
if (result.checkGameOver()) {
break;
}
}
}
private boolean askRestartOrExit() {
String input = InputView.askRestartOrExit();
return InputValidator.isValidRestartFlag(input);
}
}