-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathRacingController.js
More file actions
36 lines (29 loc) · 1000 Bytes
/
RacingController.js
File metadata and controls
36 lines (29 loc) · 1000 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
import ConsoleView from "../view/ConsoleView.js"
import Validator from "../model/Validator.js"
import CarRace from "../model/CarRace.js";
class RacingController {
constructor() {
this.view = new ConsoleView();
this.race = new CarRace();
}
async run() {
try {
const carNames = await this.view.getCarNames();
Validator.validateCarNames(carNames);
const tryCount = await this.view.getTryCount();
Validator.validateTryCount(tryCount);
this.race.initCars(carNames);
this.view.printStart();
for (let i = 0; i < tryCount; i++) {
this.race.playRound();
this.view.printRound(this.race.getCars());
}
const winners = this.race.getWinners();
this.view.printWinners(winners);
} catch (error) {
this.view.printError(error);
throw error;
}
}
}
export default RacingController;