-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathBaseballGame.java
More file actions
56 lines (45 loc) · 1.97 KB
/
BaseballGame.java
File metadata and controls
56 lines (45 loc) · 1.97 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 static java.util.UUID.randomUUID;
import baseball.domain.Computer;
import baseball.domain.ComputerDigit;
import baseball.domain.UserDigit;
import baseball.presentation.GameManager;
import baseball.domain.Referee;
import baseball.presentation.GameStatus;
import baseball.presentation.MessagePrinter;
import baseball.presentation.RandomNumberGenerator;
import baseball.presentation.input.Input;
import baseball.presentation.input.InputProvider;
import java.util.List;
import java.util.Scanner;
public class BaseballGame {
public static void launch() throws IllegalAccessException {
final Computer computer = new Computer(new RandomNumberGenerator());
final Referee referee = new Referee();
final InputProvider inputProvider = new Input(new Scanner(System.in));
final GameManager gameManager = new GameManager(new MessagePrinter(), inputProvider);
boolean isApplicationOver = false;
while (!isApplicationOver) {
GameStatus gameStatus = gameManager.init();
String gameId = randomUUID().toString();
ComputerDigit computerDigit = null;
if (gameStatus.equals(GameStatus.START)) {
List<Integer> computerDigits = gameManager.getComputerDigits(computer);
computerDigit = new ComputerDigit(gameId, computerDigits);
} else if (gameStatus.equals(GameStatus.QUIT)) {
gameManager.applicationOver();
}
boolean isOut = false;
int tryCount = 0;
while (!isOut) {
tryCount++;
List<Integer> userDigits = gameManager.getUserDigits();
UserDigit userDigit = new UserDigit(gameId, tryCount, userDigits);
isOut = referee.judge(computerDigit, userDigit);
String callMessage = referee.getCallMessage();
gameManager.call(callMessage);
}
gameManager.gameOver();
}
}
}