Добавил логику изменения водителя

related #4
parent fa72463e
import { Driver } from "../Driver";
import { Truck } from "../Truck";
export abstract class TruckState {
......@@ -9,7 +10,7 @@ export abstract class TruckState {
public abstract name: string;
public abstract changeDriver(): void;
public abstract changeDriver(driver: Driver): void;
public abstract startRun(): void;
......
import { Driver } from "../../Driver";
import { TruckState } from "../TruckState";
import { InRepairState } from "./InRepairState";
import { InRunState } from "./InRunState";
function getRandomDriver (): Driver {
const names: string[] = ['Петя', 'Вася', 'Миша', 'Саша', 'Кирилл', 'Иван', 'Матвей'];
const surnames: string[] = ['Иванов', 'Дмитриенко', 'Петрушка', 'Царёв', 'Победнский'];
const age: number = Math.floor(Math.random() * (100 - 25) + 25);
const experience: number = Math.floor(Math.random() * ((age - 18) - 1) + 1);
const ranName = names[Math.floor(Math.random() * (names.length - 0) + 0)];
const ranSurName = surnames[Math.floor(Math.random() * (surnames.length - 0) + 0)];
return new Driver(ranName, ranSurName, age, experience);
};
export class InBaseState extends TruckState {
public name: string = 'На базе';
public changeDriver(): void {
public changeDriver(driver: Driver): void {
this.truck.driver = getRandomDriver();
console.log('Водитель поменян успешно');
};
......@@ -18,4 +30,5 @@ export class InBaseState extends TruckState {
this.truck.changeState(new InRepairState());
console.log('Грузовик успешно отправился на починку');
};
};
\ No newline at end of file
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment