-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathGameController.java
More file actions
46 lines (40 loc) · 1.59 KB
/
Copy pathGameController.java
File metadata and controls
46 lines (40 loc) · 1.59 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
package baseball.controller;
import baseball.model.computer.Computer;
import baseball.model.computer.InputValidator;
import baseball.model.computer.RandomNumberGenerator;
import baseball.model.player.Player;
import baseball.view.CommonView;
import baseball.view.InputView;
import baseball.view.OutputView;
public class GameController {
private final Computer computer;
private final InputValidator inputValidator;
private final Player player;
private final CommonView commonView;
private final InputView inputView;
private final OutputView outputView;
public GameController(Computer computer, InputValidator inputValidator, Player player, CommonView commonView, InputView inputView, OutputView outputView) {
this.computer = computer;
this.inputValidator = inputValidator;
this.player = player;
this.commonView = commonView;
this.inputView = inputView;
this.outputView = outputView;
}
public void start(){
commonView.printStartMessage();
while (player.getToken()==1){
computer.makeAnswer();
playGame();
player.setToken(inputValidator.validateRestartNumber(inputView.printRestartMessage()));
}
}
public void playGame(){
while(computer.getScore().getStrike() != RandomNumberGenerator.NUMBER_LENGTH){
player.setGuess(inputValidator.validateGameNumber(inputView.printInputMessage()));
computer.validateAnswer(player.getGuess());
outputView.printScore(computer.getScore());
}
computer.getScore().resetScore();
}
}