-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathRacingGameController.java
More file actions
51 lines (44 loc) · 1.42 KB
/
RacingGameController.java
File metadata and controls
51 lines (44 loc) · 1.42 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 controller.res.CarInfoDto;
import domain.state.CarState;
import java.util.List;
import java.util.stream.Collectors;
import service.RacingGameService;
import view.InputView;
import view.OutputView;
public class RacingGameController {
private final RacingGameService racingGameService;
public RacingGameController() {
this.racingGameService = new RacingGameService();
}
public void carInit(){
while(true){
try{
var carName = InputView.readCarName();
racingGameService.trackInit(carName);
break;
}catch (IllegalArgumentException e){
OutputView.printError(e.getMessage());
}
}
}
public int gameCountInit(){
while(true){
try{
return InputView.readGameCount();
}catch (IllegalArgumentException e){
OutputView.printError(e.getMessage());
}
}
}
public void runGame(){
var gameCount = gameCountInit();
OutputView.printResultOutput();
for(int i = 0; i < gameCount; i++){
racingGameService.runStep();
var cars = racingGameService.getCars();
OutputView.printStep(cars.stream().map(CarInfoDto::toDTO).toList());
}
OutputView.printResult(racingGameService.getWinners().stream().map(CarInfoDto::toDTO).toList());
}
}