-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
35 lines (29 loc) · 978 Bytes
/
Game.java
File metadata and controls
35 lines (29 loc) · 978 Bytes
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
package baseball.controller;
import baseball.domain.Number;
import baseball.domain.Result;
import baseball.view.InputView;
import baseball.view.OutputView;
import java.util.Objects;
import static baseball.config.GlobalConfig.GAME_RESTART_FLAG;
import static baseball.view.constants.PrintMessage.GAME_START;
public class Game {
public void start() {
OutputView.printInformation(GAME_START);
do {
play(Number.generateRandomNumbers());
} while (!isRestart());
}
private void play(Number computerNumber) {
while (true) {
Number playerNumber = Number.inputPlayerNumbers();
Result result = Result.create(playerNumber, computerNumber);
result.print();
if (result.checkGameOver()) {
break;
}
}
}
private static boolean isRestart() {
return Objects.equals(InputView.askRestartOrExit(), GAME_RESTART_FLAG.toString());
}
}