private async Task GoGo(Rally rally) { Status = VehicleStatus.Running; while (Status != VehicleStatus.Broken) { await Task.Delay(TimeSpan.FromSeconds(_simulationResolutionTimeInSeconds)); Distance += (decimal)(_maxSpeed * _simulationResolutionTimeInSeconds) / 3600; if (Distance >= rally.Distance) { Status = VehicleStatus.Finished; FinishedAt = DateTime.UtcNow; break; } var healthStatus = _healtStatusProvider.GetHealtStatus(); if (healthStatus == HealthStatus.HeavyMalfunction) { _malfunctionHistory.Add(Malfunction.CreateHeavy()); Status = VehicleStatus.Broken; } else if (healthStatus == HealthStatus.LightMalfunction) { _malfunctionHistory.Add(Malfunction.CreateLight()); await Repair(); } } OnVehicleFinishedRally(); }
public void StartRally(Rally rally) { if (Status != VehicleStatus.WaitingStart) { throw new InvalidOperationException("Vehicle has already started rally."); } GoGo(rally); }
public override Result Start() { return(Result.Create(Rally._vehicles.Any(), ErrorMessages.CannotStartRallyWithNoVehicles) .OnSuccess(() => { Rally._state = new RallyRunning(Rally); Rally.OnStarted(); foreach (var vehicle in Rally._vehicles.Values) { vehicle.StartRally(Rally); } })); }
public RallyState(Rally rally) { Rally = rally; }
public RallyFinished(Rally rally) : base(rally) { rally.IsFinished = true; }
public RallyRunning(Rally rally) : base(rally) { }
public RallyPending(Rally rally) : base(rally) { }