Esempio n. 1
0
        // Finish countdown is triggered by first result
        // The race is finished after either
        //      1. All participants finish
        //      2. The finish count down expires
        // In case 1, the race duration ends with the last participant adding their result
        // In case 2, the race duration ends with the last car that added a result before the countdown expired
        public void AddLapResult(IPAddress ipAddress, TimeSpan lapTime) // assuming all lap times are sent in order for now
        {
            Lap addedLap = _lapTimerManager.AddLapResult(ipAddress, lapTime);
            int id       = _lapTimerManager.GetLapTimerByIPAddress(ipAddress).GetId();

            if (_raceState != RaceState.Registration && _raceState != RaceState.StartCountdown)
            {
                _races.Last().AddLapResult(id, addedLap);
            }

            if (_raceState == RaceState.InProgress)
            {
                if (_races.Last().HasAnyParticipantFinished())
                {
                    if (_lapTimerManager.GetAllLapTimers().Count == 1)
                    {
                        FinishRace(0);
                    }
                    else
                    {
                        FinishRace();
                    }
                }
            }
            else if (_raceState == RaceState.FinishCountdown)
            {
                if (_races.Last().HaveAllParticipantsFinished())
                {
                    CancelCountdown();
                    FinishRace(0);
                }
            }
        }
Esempio n. 2
0
 public void AddLapResult(int id, Lap lap)
 {
     _participantsAndResults[id].Add(lap);
     if (_participantsAndResults[id].Count >= _numberOfLaps && !_finishedParticipants.Contains(id))
     {
         _finishedParticipants.Add(id);
     }
 }
Esempio n. 3
0
        public Lap AddLap(TimeSpan timeSpan)
        {
            int nextLapNumber = _laps.Count() + 1;
            Lap newLap        = new Lap(nextLapNumber, timeSpan);

            _laps.Add(newLap);
            return(newLap);
        }
Esempio n. 4
0
        public Lap GetFastestLap()
        {
            Lap fastestLap = new Lap(0, new TimeSpan(0));

            if (_laps.Count() > 0)
            {
                fastestLap = _laps[0];

                for (int i = 1; i < _laps.Count(); i++)
                {
                    if (_laps[i].Time < fastestLap.Time)
                    {
                        fastestLap = _laps[i];
                    }
                }
            }

            return(fastestLap);
        }