コード例 #1
0
ファイル: Database.cs プロジェクト: Total1880/Cycling
        public void AddCyclist()
        {
            var cyclist = new Cyclist(_allCyclist.Count + 1, random);

            _allCyclist.Add(cyclist);
            Console.Clear();
        }
コード例 #2
0
ファイル: Database.cs プロジェクト: Total1880/Cycling
        public Database()
        {
            string input;

            Console.WriteLine("How many cyclist do you want to have (4 or more)");
            input = Console.ReadLine();

            if (input == "")
            {
                _numberOfCyclist = 10;
            }
            else
            {
                if (Convert.ToInt32(input) < 4)
                {
                    input = "4";
                }
                _numberOfCyclist = Convert.ToInt32(input);
            }

            Console.Clear();

            for (int i = 0; i < _numberOfCyclist; i++)
            {
                var cyclist = new Cyclist(_allCyclist.Count + 1, random);

                _allCyclist.Add(cyclist);
                Console.Clear();
            }
        }
コード例 #3
0
ファイル: Database.cs プロジェクト: Total1880/Cycling
        public void UpgradeRandomCyclists()
        {
            var max         = Math.Round(Convert.ToDouble(_allCyclist.Count / 3));
            var cyclistPlus = new Cyclist();
            int maxPotential;

            cyclistPlus = _allCyclist[random.Next(0, _allCyclist.Count)];

            foreach (var cyclist in _allCyclist)
            {
                if (cyclistPlus.GetId == cyclist.GetId)
                {
                    maxPotential = cyclist.Strength + cyclist.GetSprint;
                    int sprint = random.Next(0, 2);
                    if (sprint == 0)
                    {
                        if (cyclist.GetSprint <= max && cyclist.GetPotential > maxPotential)
                        {
                            cyclist.GetSprint += 1;
                        }
                    }
                    else
                    {
                        if (cyclist.Strength <= max && cyclist.GetPotential > maxPotential)
                        {
                            cyclist.Strength += 1;
                        }
                    }
                }
            }
        }
コード例 #4
0
        private void Sprint()
        {
            Random  random        = new Random();
            Cyclist winner        = new Cyclist();
            var     sprintranking = new List <Cyclist>();
            int     j             = 0;

            foreach (var cyclist in _allCyclist)
            {
                if (cyclist.Position == _allCyclist[0].Position)
                {
                    _sprinters.Add(cyclist);
                }
            }

            foreach (var cyclist in _sprinters)
            {
                for (int i = 0; i < 10; i++)
                {
                    cyclist.SprintPosition += random.Next(0, (3 + cyclist.GetSprint));
                }
            }

            sprintranking = this.GetRanking(_sprinters, true);
            _winner       = sprintranking[0];

            foreach (var cyclist in sprintranking)
            {
                _allCyclist[j] = cyclist;
                j++;
            }
            Console.WriteLine("The winner in the sprint is {0}.", _winner.Name);
        }
コード例 #5
0
ファイル: Database.cs プロジェクト: Total1880/Cycling
        public void UpgradeCyclists(List <Cyclist> ranking, Cyclist winner, bool sprint)
        {
            var max = Math.Round(Convert.ToDouble(_allCyclist.Count / 3));
            int maxPotential;
            var upgradedCyclist = random.Next(0, 4);

            ranking[0].Points += 3;
            ranking[1].Points += 2;
            ranking[2].Points += 1;

            if (upgradedCyclist < 3)
            {
                foreach (var cyclist in _allCyclist)
                {
                    if (ranking[upgradedCyclist].GetId == cyclist.GetId)
                    {
                        maxPotential = cyclist.Strength + cyclist.GetSprint;
                        if (sprint)
                        {
                            if (cyclist.GetSprint <= max && cyclist.GetPotential > maxPotential)
                            {
                                cyclist.GetSprint += 1;
                            }
                        }
                        else
                        {
                            if (cyclist.Strength <= max && cyclist.GetPotential > maxPotential)
                            {
                                cyclist.Strength += 1;
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (var cyclist in _allCyclist)
                {
                    if (winner.GetId == cyclist.GetId)
                    {
                        maxPotential = cyclist.Strength + cyclist.GetSprint;
                        if (sprint)
                        {
                            if (cyclist.GetSprint <= max && cyclist.GetPotential > maxPotential)
                            {
                                cyclist.GetSprint += 1;
                            }
                        }
                        else
                        {
                            if (cyclist.Strength <= max && cyclist.GetPotential > maxPotential)
                            {
                                cyclist.Strength += 1;
                            }
                        }
                    }
                }
            }
        }
コード例 #6
0
ファイル: Database.cs プロジェクト: Total1880/Cycling
 public void DowngradeCyclists(Cyclist cyclistMin)
 {
     foreach (var cyclist in _allCyclist)
     {
         if (cyclistMin.GetId == cyclist.GetId)
         {
             int sprint = random.Next(0, 2);
             if (sprint == 0)
             {
                 if (cyclist.GetSprint > 0)
                 {
                     cyclist.GetSprint -= 1;
                 }
             }
             else
             {
                 if (cyclist.Strength > 0)
                 {
                     cyclist.Strength -= 1;
                 }
             }
         }
     }
 }