-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathBaseballGame.java
More file actions
38 lines (34 loc) · 1.07 KB
/
BaseballGame.java
File metadata and controls
38 lines (34 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
37
38
public class BaseballGame {
private View view = new View();
private Computer computer = new Computer();
private Player player = new Player();
private boolean isRun = true;
public void run() {
while (isRun) {
try {
player.setNumbers(view.getPlayerInput());
} catch (Exception e) {
System.out.println(e.getMessage());
}
int[] scores = computer.calculateScores(player.getNumbers());
view.printScore(scores);
isRun = checkIsRun(scores);
}
}
public boolean checkIsRun(int[] scores) {
if (scores[0] != 3) return true;
try {
if (scores[0] == 3) return checkIsFinish(view.getPlayerRetryChoice());
} catch (Exception e) {
System.out.println(e.getMessage());
}
return false;
}
private boolean checkIsFinish(boolean playerRetryChoice) {
if (playerRetryChoice == true) {
computer.resetRandomNumbers();
return true;
}
return false;
}
}