Example #1
0
        public Race(Track track, List <IParticipant> participants, int laps)
        {
            Track                 = track;
            Participants          = participants;
            _previousSectionTimes = new Dictionary <IParticipant, TimeSpan>();
            _currentBreakdowns    = new Dictionary <IParticipant, DateTime>();

            foreach (IParticipant p in participants)
            {
                p.LapsInCurrentRace = 0;
                _previousSectionTimes.Add(p, TimeSpan.Zero);
            }
            StartTime    = DateTime.Now;
            lapsToFinish = laps;


            _random = new Random(DateTime.Now.Millisecond);
            //RandomizeEquipment();
            _positions = new Dictionary <Section, SectionData>();
            PlaceParticipantsStart(track, participants);
            _timer          = new System.Timers.Timer(500);
            _timer.Elapsed += OnTimedEvent;

            RaceStarted?.Invoke(this, new EventArgs());
            RaceFinished        += Data.Competition.RaceFinished;
            FinishedParticipants = new Dictionary <IParticipant, int>();
        }
Example #2
0
        public void HandleEvent(RaceStarted raceStarted)
        {
            var xxx  = Stopwatch.StartNew();
            var race = this._raceRepository.Get(raceStarted.RaceId);

            this.FireTeamRaceStartedEvents(race, raceStarted.Date);
            StatsPrinter.Print("RaceStarted", xxx.ElapsedMilliseconds);
        }
Example #3
0
 public void StartRace(double raceLength)
 {
     RaceStarted?.Invoke(Name);
     RaceLength    = raceLength;
     RaceStartTime = DateTime.Now;
     RaceEndTime   = null;
     Position      = 0;
     Rank          = 1;
     Running       = true;
     Speed         = GetRandomSpeed(MaxSpeed);
 }