-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathControl.java
More file actions
40 lines (35 loc) · 924 Bytes
/
Control.java
File metadata and controls
40 lines (35 loc) · 924 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
36
37
38
39
40
package game;
public class Control {
private GameRule gameRule;
private UI ui;
private Computer computer;
public Control() {
this.gameRule = new GameRule();
this.ui = new UI(gameRule);
this.computer = new Computer(gameRule);
}
private boolean inGameLoop() {
int[] numbers = ui.getUserNumbers();
GameRule.Result result = computer.getResult(numbers);
ui.printResult(result);
if (result.isEnd)
return true;
return false;
}
private boolean gameLoop() {
boolean isEnd = false;
computer.updateNumbers();
while (!isEnd) {
isEnd = this.inGameLoop();
}
if (ui.getEndingStatus())
return true;
return false;
}
public void start() {
boolean isEnd = false;
while (!isEnd) {
isEnd = this.gameLoop();
}
}
}