Пример #1
0
 /// <summary>
 /// Engine of penalty kick.
 /// </summary>
 /// <param name="footballMatch">The football match.</param>
 /// <param name="isTurnA">If set to <c>true</c> then it is turn of <see cref="Team"/> A.</param>
 private void PenaltyEngine(ref FootballMatch footballMatch, bool isTurnA)
 {
     if (isTurnA)
     {
         Debug.Write($"{footballMatch.ReturnTeamA().name} is executing this penalty... ");
         if (IfTeamScored(5))
         {
             Debug.Write($"and they scored a beautiful GOAL!");
             footballMatch.AddScoreToTeamA();
         }
         else
         {
             Debug.Write($"and they missed.");
         }
     }
     else
     {
         Debug.Write($"{footballMatch.ReturnTeamB().name} is executing this penalty... ");
         if (IfTeamScored(5))
         {
             Debug.Write($"and they scored a beautiful GOAL!");
             footballMatch.AddScoreToTeamB();
         }
         else
         {
             Debug.Write($"and they missed.");
         }
     }
 }
Пример #2
0
        /// <summary>
        ///   <see cref="Engine(ref FootballMatch, int, int, int)" /> is the specified football match engine, which is responsible for executing play simulation.
        /// </summary>
        /// <param name="footballMatch">The football match.</param>
        /// <param name="isDeathmatch">If set to <c>true</c> than this is deathmatch.</param>
        private void Engine(ref FootballMatch footballMatch, bool isDeathmatch)
        {
            min = 600000;
            max = 900000;
            int  matchTime = playTime / 1000 / 60;
            int  currentTime;
            bool breaktime = false;

            Debug.WriteLine($"00': Match started.");

            for (int i = random.Next(min, max); i <= this.playTime; i += random.Next(min, max))
            {
                currentTime = i / 1000 / 60;
                Debug.Write($"{currentTime}': The ball is in possession of ");
                if (Chance() % 2 == 0)
                {
                    // Team A has the ball
                    Debug.Write($"{footballMatch.ReturnTeamA().name}. ");
                    inPossession = footballMatch.ReturnTeamA();
                    if (IfTeamScored(3))
                    {
                        Debug.WriteLine($"\tThey scored a beautiful GOAL!");
                        footballMatch.AddScoreToTeamA();
                    }
                    else
                    {
                        Debug.WriteLine($" \tThey shot... and missed.");
                    }
                }
                else
                {
                    // Team B has the ball
                    Debug.Write($"{footballMatch.ReturnTeamB().name}. ");
                    inPossession = footballMatch.ReturnTeamB();
                    if (IfTeamScored(3))
                    {
                        Debug.WriteLine($"\tThey scored a beautiful GOAL!");
                        footballMatch.AddScoreToTeamB();
                    }
                    else
                    {
                        Debug.WriteLine($" \tThey shot... and missed.");
                    }
                }
                //Thread.Sleep(i / 1000);   //Uncomment for real time.
                if (breaktime == false)
                {
                    if ((i + max) > this.playTime / 2 && breaktime == false)
                    {
                        Debug.WriteLine($"{this.playTime / 2 / 1000 / 60}': First half ended. Braktime.\t{footballMatch.ReturnTeamA().name} {footballMatch.GetScoreOfTeamA()} : {footballMatch.GetScoreOfTeamB()} {footballMatch.ReturnTeamB().name}.");
                        breaktime = true;
                        i        += max - min;
                        Debug.WriteLine($"{this.playTime / 2 / 1000 / 60}': Second half on the go.");
                    }
                }
                else if ((i + min) > this.playTime)
                {
                    i -= min / 10;
                }
            }
            Debug.WriteLine($"{matchTime}': Regular time's up.");

            if (isDeathmatch == true &&
                footballMatch.GetScoreOfTeamA() == footballMatch.GetScoreOfTeamB())
            {
                Debug.WriteLine($"90': Regular time wasn't enough.\t{footballMatch.ReturnTeamA().name} {footballMatch.GetScoreOfTeamA()} : {footballMatch.GetScoreOfTeamB()} {footballMatch.ReturnTeamB().name}.");
                Debug.WriteLine($"90': Play-off time! It's a lottery now.");
                matchTime  += playoffTime / 1000 / 60;
                breaktime   = false;
                currentTime = playTime / 1000 / 60;
                min         = 300000;
                max         = 600000;
                for (int i = random.Next(min, max); i <= playoffTime; i += random.Next(min, max))
                {
                    currentTime = (playTime + i) / 1000 / 60;
                    Debug.Write($"{currentTime}': The ball is in possession of ");
                    if (Chance() % 2 == 0)
                    {
                        // Team A has the ball
                        Debug.Write($"{footballMatch.ReturnTeamA().name}. ");
                        inPossession = footballMatch.ReturnTeamA();
                        if (IfTeamScored(3))
                        {
                            Debug.WriteLine($"\tThey scored a beautiful GOAL!");
                            footballMatch.AddScoreToTeamA();
                        }
                        else
                        {
                            Debug.WriteLine($" \tThey shot... and missed.");
                        }
                    }
                    else
                    {
                        // Team B has the ball
                        Debug.Write($"{footballMatch.ReturnTeamB().name}. ");
                        inPossession = footballMatch.ReturnTeamB();
                        if (IfTeamScored(3))
                        {
                            Debug.WriteLine($"\tThey scored a beautiful GOAL!");
                            footballMatch.AddScoreToTeamB();
                        }
                        else
                        {
                            Debug.WriteLine($" \tThey shot... and missed.");
                        }
                    }
                    //Thread.Sleep(i / 1000);
                    if (breaktime == false)
                    {
                        if ((i + max) > this.playoffTime / 2 && breaktime == false)
                        {
                            Debug.WriteLine($"{playoffTime / 2 / 1000 / 60 + playTime / 1000 / 60}': First half ended. Braktime.\t{footballMatch.ReturnTeamA().name} {footballMatch.GetScoreOfTeamA()} : {footballMatch.GetScoreOfTeamB()} {footballMatch.ReturnTeamB().name}.");
                            breaktime = true;
                            i        += max - min;
                        }
                    }
                    else if ((i + min) > this.playoffTime)
                    {
                        i -= min / 10;
                    }
                }
                Debug.WriteLine($"{(playTime + playoffTime) / 1000 / 60}': Play-off time's up.");
                if (footballMatch.GetScoreOfTeamA() == footballMatch.GetScoreOfTeamB())
                {
                    Debug.WriteLine($"{(playTime + playoffTime) / 1000 / 60}': It is time for penalty kicks.");
                    PenaltyKicksEngine(ref footballMatch);
                    Debug.WriteLine($"Penalty kicks ended. The winner is: {(footballMatch.GetScoreOfTeamA() > footballMatch.GetScoreOfTeamB() ? footballMatch.ReturnTeamA().name : footballMatch.ReturnTeamB().name)}.");
                }
            }
            Debug.WriteLine($"{matchTime}': Match ends with result:\t{footballMatch.ReturnTeamA().name} {footballMatch.GetScoreOfTeamA()} : {footballMatch.GetScoreOfTeamB()} {footballMatch.ReturnTeamB().name}.");

            if (footballMatch.GetScoreOfTeamA() > footballMatch.GetScoreOfTeamB())
            {
                footballMatch.ReturnTeamA().AddWin();
                footballMatch.ReturnTeamB().AddLoss();
            }
            else if (footballMatch.GetScoreOfTeamB() > footballMatch.GetScoreOfTeamA())
            {
                footballMatch.ReturnTeamB().AddWin();
                footballMatch.ReturnTeamA().AddLoss();
            }
            else
            {
                footballMatch.ReturnTeamA().AddDraw();
                footballMatch.ReturnTeamB().AddDraw();
            }
            footballMatch.ReturnTeamA().AddMatchPlayed();
            footballMatch.ReturnTeamB().AddMatchPlayed();
            System.Threading.Thread.Sleep(100);
        }