Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        private async Task Repair()
        {
            Status = VehicleStatus.Repairing;
            await Task.Delay(_repairmentDuration);

            Status = VehicleStatus.Running;
        }
Ejemplo n.º 3
0
 public Vehicle(VehicleType type, string id, string teamName, string model, DateTime manufacturingDate, int maxSpeed,
                TimeSpan repairmentDuration, int simulationResolutionTimeInSeconds, IProvideHealthStatus healtStatusProvider)
 {
     Type                = type;
     Id                  = id;
     TeamName            = teamName;
     Model               = model;
     ManufacturingDate   = manufacturingDate;
     _maxSpeed           = maxSpeed;
     _repairmentDuration = repairmentDuration;
     _simulationResolutionTimeInSeconds = simulationResolutionTimeInSeconds;
     _malfunctionHistory  = new List <Malfunction>();
     _healtStatusProvider = healtStatusProvider;
     Distance             = 0;
     Status = VehicleStatus.WaitingStart;
 }