-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathController.java
More file actions
51 lines (42 loc) · 1.29 KB
/
Controller.java
File metadata and controls
51 lines (42 loc) · 1.29 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
package controller;
import model.Game;
import model.GameResult;
import model.Numbers;
import view.InputView;
import view.OutputView;
import java.util.List;
public class Controller {
private final InputView inputView = new InputView();
private final OutputView outputView = new OutputView();
public void run() {
while (true) {
int result = play();
if (result == 2) break;
}
}
private int play() {
Game game = new Game();
while (true) {
try {
outputView.OutputInputNumber();
Numbers userNumbers = new Numbers(inputView.InputUserNumbers());
GameResult result = game.getResult(userNumbers);
outputView.OutputResult(result);
if (result.isFinish()) {
break;
}
} catch (IllegalArgumentException e) {
outputView.OutputError(e.getMessage());
}
}
outputView.OutputWin();
while (true) {
try {
outputView.OutputInputCommand();
return game.getCommand(inputView.InputCommand());
} catch (IllegalArgumentException e) {
outputView.OutputError(e.getMessage());
}
}
}
}