コード例 #1
0
        public void LoadDefaultModel()
        {
            _driverRepository.AddDriver(new Driver(16, "Charles", "Leclerc"));
            _driverRepository.AddDriver(new Driver(5, "Sebastian", "Vettel"));
            _driverRepository.AddDriver(new Driver(44, "Lewis", "Hamilton"));
            _driverRepository.AddDriver(new Driver(77, "Valteri", "Bottas"));
            _driverRepository.AddDriver(new Driver(3, "Max", "Verstapen"));
            _driverRepository.AddDriver(new Driver(55, "Carlos", "Seinz"));

            _trackRepository.AddTrack(new Track(_trackRepository.GetNewID(), "Melbourne Grand Prix Circuit", "Australia", 5303000));
            _trackRepository.AddTrack(new Track(_trackRepository.GetNewID(), "Bahrein International Circuit", "Bahrein", 5412000));
            _trackRepository.AddTrack(new Track(_trackRepository.GetNewID(), "Spa-Francorchhamps", "Belgium", 7004000));
            _trackRepository.AddTrack(new Track(_trackRepository.GetNewID(), "Shangai International Circuit", "China", 5451000));
            _trackRepository.AddTrack(new Track(_trackRepository.GetNewID(), "Hanoi Circuit", "Vietnam", 5607000));


            _raceRepository.AddRace(new Race(_raceRepository.GetNewID(), "Australia GP", new DateTime(2020, 3, 15), _trackRepository.GetTrackByName("Melbourne Grand Prix Circuit")));
            _raceRepository.AddRace(new Race(_raceRepository.GetNewID(), "Bahrein GP", new DateTime(2020, 3, 22), _trackRepository.GetTrackByName("Bahrein International Circuit")));
            _raceRepository.AddRace(new Race(_raceRepository.GetNewID(), "Vietnam GP", new DateTime(2020, 4, 5), _trackRepository.GetTrackByName("Hanoi Circuit")));
            _raceRepository.AddRace(new Race(_raceRepository.GetNewID(), "China GP", new DateTime(2020, 4, 19), _trackRepository.GetTrackByName("Shangai International Circuit")));

            RaceResults raceResults = new RaceResults(_driverRepository.GetAllActiveDrivers(), _driverRepository.GetDriverByGoKart(16));

            _raceRepository.EnterResults("Australia GP", raceResults);
            _driverRepository.AddPoints(16, 26);
            _driverRepository.AddPoints(5, 18);
            _driverRepository.AddPoints(44, 15);
            _driverRepository.AddPoints(77, 12);
            _driverRepository.AddPoints(3, 10);
            _driverRepository.AddPoints(55, 8);
        }
コード例 #2
0
 private void valueChanged(RaceResults value)
 {
     if (this.RaceResultsChanged != null)
     {
         this.RaceResultsChanged(value);
     }
 }
コード例 #3
0
        public async Task <ActionResult <int> > GetDriversRacePositionTotalById(int id, int position)
        {
            var result = await _dataReader.GetDriversRaceResults(id);

            var mappedData = result.Select(x => RaceResults.MapFromDb(x)).ToList();

            return(_calculate.RacePositionCount(mappedData, position));
        }
コード例 #4
0
        public async Task <ActionResult <decimal> > GetDriverTotalPointsById(int id)
        {
            var result = await _dataReader.GetDriversRaceResults(id);

            var points = result.Select(x => RaceResults.MapFromDb(x)).ToList();

            return(_calculate.TotalDriverPoints(points));
        }
コード例 #5
0
ファイル: RaceTests.cs プロジェクト: LovreAB17/GoKartChamp
        public void Test_EnterRaceResultsToNonExistingRace()
        {
            RaceRepository raceRepository = RaceRepository.GetInstance();

            RaceResults raceResults = new RaceResults(driverRepository.GetAllActiveDrivers(), driverRepository.GetDriverByGoKart(16));

            raceRepository.EnterResults("AusGP", raceResults);
        }
コード例 #6
0
        public async Task <List <RaceResults> > GetAllDriversRaceResultsForASeason(int season)
        {
            var raceData = await _driverReader.GetDriversSeasonRaceResults(season);

            var orderedData = raceData.OrderBy(x => x.StartDate);

            return(raceData.Select(x => RaceResults.MapFromDb(x)).ToList());
        }
コード例 #7
0
        public async Task <ElectionResults> GetResults(Election election)
        {
            var request = _service.Spreadsheets.Values.BatchGet(_spreadsheetId);
            var ranges  = new List <string>();

            foreach (var race in election.Races)
            {
                var range = $"{StarSymbol}{race.Caption}!A:{ToColumnName(race.Candidates.Count+1)}";
                ranges.Add(range);
            }
            request.Ranges = new Repeatable <string>(ranges);
            var response = await request.ExecuteAsync().ConfigureAwait(false);

            var valueRanges = response.ValueRanges.ToArray();
            var results     = new ElectionResults
            {
                Title = election.Title,
                Races = new List <RaceResults>()
            };

            for (var raceIndex = 0; raceIndex < election.Races.Count; raceIndex++)
            {
                var race        = election.Races[raceIndex];
                var valueRange  = valueRanges[raceIndex];
                var raceResults = new RaceResults
                {
                    Title      = race.Caption,
                    Candidates = race.Candidates.ToArray(),
                    Votes      = new Vote[valueRange.Values.Count - 1]
                };
                var index = 0;
                foreach (var range in valueRange.Values.ToArray().Slice(1))
                {
                    var array  = range.ToArray();
                    var scores = new int[array.Length - 1];
                    for (var columnIndex = 1; columnIndex < array.Length; columnIndex++)
                    {
                        var score = int.Parse(array[columnIndex].ToString());
                        scores[columnIndex - 1] = score;
                    }
                    var vote = new Vote
                    {
                        VoterId = array[0].ToString(),
                        Scores  = scores.ToArray()
                    };
                    raceResults.Votes[index++] = vote;
                }
                results.Races.Add(raceResults);
            }
            return(results);
        }
コード例 #8
0
ファイル: RaceTests.cs プロジェクト: LovreAB17/GoKartChamp
        public void Test_EnterRaceResults()
        {
            RaceRepository raceRepository = RaceRepository.GetInstance();

            Race race = new Race(raceRepository.GetNewID(), "AusGP", new DateTime(2020, 3, 15), trackRepository.GetTrackByName("Melbourne Grand Prix Circuit"));

            raceRepository.AddRace(race);

            RaceResults raceResults = new RaceResults(driverRepository.GetAllActiveDrivers(), driverRepository.GetDriverByGoKart(16));

            raceRepository.EnterResults("AusGP", raceResults);

            Assert.IsTrue(raceRepository.GetRaceByName("AusGP").Finished);
        }
コード例 #9
0
ファイル: RaceTests.cs プロジェクト: LovreAB17/GoKartChamp
        public void Test_TryToRemoveFinishedRace()
        {
            RaceRepository raceRepository = RaceRepository.GetInstance();

            Race race = new Race(raceRepository.GetNewID(), "BelGP", new DateTime(2020, 3, 22), trackRepository.GetTrackByName("Spa-Francorchhamps"));

            raceRepository.AddRace(race);

            RaceResults raceResults = new RaceResults(driverRepository.GetAllActiveDrivers(), driverRepository.GetDriverByGoKart(5));

            raceRepository.EnterResults("BelGP", raceResults);

            raceRepository.RemoveRace(raceRepository.GetRaceByName("BelGP"));
        }
コード例 #10
0
        public void EnterResults(string inName, RaceResults inResult)
        {
            var rac = _races.Find(r => (r.Name == inName));

            if (rac != null)
            {
                rac.Finished = true;
                rac.Results  = inResult;

                NotifyObservers();
                return;
            }

            throw new RaceNotFoundException();
        }
コード例 #11
0
 private bool onRaceFinished(RaceGameEvents.RaceFinished evt)
 {
     lastRaceResults = evt.RaceResults;
     rankTimes       = evt.RankTimes;
     showEndRaceScreen();
     if (evt.RaceResults.trackId == "blue")
     {
         BlueLeaderboard.ShowFinishScreen(evt.RaceResults);
     }
     else
     {
         RedLeaderboard.ShowFinishScreen(evt.RaceResults);
     }
     return(false);
 }
コード例 #12
0
        public void ViewRaceResults(IShowRaceResultsView inForm, string inRaceName)
        {
            RaceRepository _raceRepository = RaceRepository.GetInstance();

            Race _race = _raceRepository.GetRaceByName(inRaceName);

            RaceResults _raceResult = _raceRepository.GetRaceResults(inRaceName);

            List <Driver> positions = _raceResult._positions;

            Driver fastestLap = _raceResult.FastestLap;

            List <int> points = _raceRepository.GetPoints();

            inForm.ShowModaless(_race, positions, fastestLap, points);
        }
コード例 #13
0
ファイル: RaceTests.cs プロジェクト: LovreAB17/GoKartChamp
        public void Test_GetDriverWithFastestLapInRace()
        {
            RaceRepository raceRepository = RaceRepository.GetInstance();

            Race race = new Race(raceRepository.GetNewID(), "BahGP", new DateTime(2020, 3, 22), trackRepository.GetTrackByName("Bahrein International Circuit"));

            raceRepository.AddRace(race);

            RaceResults raceResults = new RaceResults(driverRepository.GetAllActiveDrivers(), driverRepository.GetDriverByGoKart(5));

            raceRepository.EnterResults("BahGP", raceResults);

            Race getRace = raceRepository.GetRaceByName("BahGP");

            Assert.AreEqual(5, getRace.Results.FastestLap.GoKart);
        }
コード例 #14
0
        public async Task <List <DriverStats> > BuildDriversSeasonStats(int season)
        {
            List <DriverStats> driverStats = new List <DriverStats>();

            var raceData = await _driverReader.GetDriversSeasonRaceResults(season);

            var driverData = raceData.GroupBy(x => x.DriverId);

            foreach (var driver in driverData)
            {
                var result   = driver.Select(x => RaceResults.MapFromDb(x)).ToList();
                var calcData = CalculateDriverData(result);

                driverStats.Add(DriverStats.Mapper(driver.Key, calcData));
            }

            return(driverStats);
        }
コード例 #15
0
        public void Initialize(RaceResults raceResults, long[] rankTimes)
        {
            this.raceResults = raceResults;
            this.rankTimes   = rankTimes;
            CoroutineRunner.Start(loadRankEntryPrefabs(), this, "LoadRankEntryPrefabs");
            int index = 0;

            if (raceResults.trackId == "red")
            {
                index = 1;
            }
            for (int i = 0; i < SpriteSelectors.Length; i++)
            {
                SpriteSelectors[i].SelectSprite(index);
            }
            for (int i = 0; i < TintSelectors.Length; i++)
            {
                TintSelectors[i].SelectColor(index);
            }
        }
コード例 #16
0
    private void Start()
    {
        dispatcher           = Service.Get <EventDispatcher>();
        dataEntityCollection = Service.Get <CPDataEntityCollection>();
        dispatcher.DispatchEvent(default(RaceGameEvents.Start));
        DataEntityHandle localPlayerHandle = dataEntityCollection.LocalPlayerHandle;

        if (dataEntityCollection.TryGetComponent(localPlayerHandle, out localPlayerRaceData))
        {
            CompletionTime      = localPlayerRaceData.RaceResults.CompletionTime;
            RaceResultsCategory = localPlayerRaceData.RaceResults.raceResultsCategory;
            return;
        }
        localPlayerRaceData = dataEntityCollection.AddComponent <RaceData>(localPlayerHandle);
        RaceResults raceResults = new RaceResults();

        raceResults.CompletionTime      = 0L;
        raceResults.raceResultsCategory = RaceResults.RaceResultsCategory.Incomplete;
        localPlayerRaceData.RaceResults = raceResults;
    }
コード例 #17
0
        public void ShowFinishScreen(RaceResults raceResults)
        {
            setTime(raceResults.CompletionTime);
            setState(ScreenState.Finish);
            long   num  = raceResults.CompletionTime - raceResults.StartTime;
            string text = default(DateTime).AddMilliseconds(num).ToString("m:ss.ff");

            TimeText.text       = text;
            TimeTextShadow.text = text;
            int num2 = (int)(raceResults.raceResultsCategory - 1);

            for (int i = 0; i < TrophyIcons.Length; i++)
            {
                if (i == num2)
                {
                    TrophyIcons[i].SetActive(value: true);
                }
                else
                {
                    TrophyIcons[i].SetActive(value: false);
                }
            }
            CoroutineRunner.Start(scoreboardTimer.Start(), this, "ScoreboardTimer");
        }
コード例 #18
0
 public RaceFinished(RaceResults raceResults, long[] rankTimes)
 {
     RaceResults = raceResults;
     RankTimes   = rankTimes;
 }
コード例 #19
0
 public GympassRace()
 {
     _raceLog     = new RaceLog();
     _raceResults = new RaceResults();
 }
コード例 #20
0
        public void EnterRaceResults(IEnterResultsView inForm)
        {
            RaceRepository   raceRepository   = RaceRepository.GetInstance();
            DriverRepository driverRepository = DriverRepository.GetInstance();


            if (inForm.ShowViewModal(raceRepository.GetAllUnfinishedRaces(), driverRepository.GetAllActiveDrivers()) == true)
            {
                try
                {
                    string RaceName = inForm.RaceName;
                    if (string.IsNullOrEmpty(RaceName))
                    {
                        throw new ArgumentException("Race name is not selected!");
                    }

                    Race inRace = raceRepository.GetRaceByName(RaceName);

                    string result = inForm.Result;
                    if (string.IsNullOrEmpty(result))
                    {
                        throw new ArgumentException("Race standings is empty! Fill the textbox!");
                    }

                    List <int> driversResultsInt = this.ParseRaceStandings(result, driverRepository);

                    int fastestLap = -1;
                    if (Int32.TryParse(inForm.FastestLap, out fastestLap) == false)
                    {
                        throw new ArgumentException("The fastest lap result is not entered correctly!");
                    }
                    if (!driversResultsInt.Contains(fastestLap))
                    {
                        throw new ArgumentException("The fastest lap driver was not in the race!");
                    }


                    List <Driver> driversResults = new List <Driver>();
                    List <int>    points         = raceRepository.GetPoints();

                    for (int i = 0; i < driversResultsInt.Count(); ++i)
                    {
                        int    id    = driversResultsInt[i];
                        int    point = points[i];
                        Driver dr    = driverRepository.AddPoints(id, point);
                        driversResults.Add(dr);
                    }

                    Driver inFastestLap = driverRepository.AddPoints(fastestLap, 1);

                    RaceResults results = RaceFactory.CreateResults(driversResults, inFastestLap);

                    raceRepository.EnterResults(inRace.Name, results);
                }
                catch (RaceNotFoundException)
                {
                    MessageBox.Show("Picked race doesn't exist!");
                }
                catch (ArgumentException ex)
                {
                    MessageBox.Show(ex.Message + " Try again.");
                }
                catch (DriverNotFoundException)
                {
                    MessageBox.Show("Driver doesn't exist!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error:" + ex);
                }
            }
        }
コード例 #21
0
 public Int32 RaceResultForDriver(Driver driver)
 {
     return(RaceResults.Position(driver));
 }