Exemple #1
0
        internal void PlayMatch(Random rand)
        {
            if (Player1 == null)
            {
                Console.WriteLine("This match is between:");
                Console.WriteLine("Home: " + Team1.Player1.FirstName + " " +
                                  Team1.Player1.MiddleName + " " +
                                  Team1.Player1.LastName + " and " +
                                  Team1.Player2.FirstName + " " +
                                  Team1.Player2.MiddleName + " " +
                                  Team1.Player2.LastName);
                Console.WriteLine("VS");
                Console.WriteLine("Away: " + Team2.Player1.FirstName + " " +
                                  Team2.Player1.MiddleName + " " +
                                  Team2.Player1.LastName + " and " +
                                  Team2.Player2.FirstName + " " +
                                  Team2.Player2.MiddleName + " " +
                                  Team2.Player2.LastName);
            }
            else
            {
                Console.WriteLine("This match is between: ");
                Console.WriteLine("Home: " + Player1.FirstName + " " +
                                  Player1.MiddleName + " " +
                                  Player1.LastName);
                Console.WriteLine("VS");
                Console.WriteLine("Away: " + Player2.FirstName + " " +
                                  Player2.MiddleName + " " +
                                  Player2.LastName);
            }

            while (SetsWon1 < SetsToWin && SetsWon2 < SetsToWin)
            {
                Points1 = 0;
                Points2 = 0;
                int points = 0;

                while (Points1 < PointsMax && Points2 < PointsMax)
                {
                    points = rand.Next(1, 4);
                    if (points == 1)
                    {
                        Points1++;
                    }
                    else if (points == 2)
                    {
                        Points2++;
                    }
                    if (Points1 == PointsMax)
                    {
                        SetsWon1++;
                        Console.WriteLine("Home wins set: " + Points1 + "-" + Points2);
                    }
                    else if (Points2 == PointsMax)
                    {
                        SetsWon2++;
                        Console.WriteLine("Away wins set: " + Points1 + "-" + Points2);
                    }
                }


                if (TypeofGame == GameType.Mensingle || TypeofGame == GameType.WomenSingle)
                {
                    if (SetsWon1 == SetsToWin)
                    {
                        WinnerSingle = Player1;
                    }
                    else if (SetsWon2 == SetsToWin)
                    {
                        WinnerSingle = Player2;
                    }
                }
                else if (TypeofGame == GameType.MenDouble || TypeofGame == GameType.WomenDouble || TypeofGame == GameType.Mixdouble)
                {
                    if (SetsWon1 == SetsToWin)
                    {
                        WinnerDouble = Team1;
                    }
                    else if (SetsWon2 == SetsToWin)
                    {
                        WinnerDouble = Team2;
                    }
                }
            }
            if (WinnerSingle == null)
            {
                Console.WriteLine("The winners of the match is: " + WinnerDouble.Player1.FirstName + " " +
                                  WinnerDouble.Player1.MiddleName + " " +
                                  WinnerDouble.Player1.LastName + " and " +
                                  WinnerDouble.Player2.FirstName + " " +
                                  WinnerDouble.Player2.MiddleName + " " +
                                  WinnerDouble.Player2.LastName + ": " + SetsWon1 + "-" + SetsWon2 + "!");
            }
            else
            {
                Console.WriteLine("The winner of the match is: " + WinnerSingle.FirstName + " " +
                                  WinnerSingle.MiddleName + " " +
                                  WinnerSingle.LastName + ": " + SetsWon1 + "-" + SetsWon2 + "!");
            }
            Console.WriteLine("");
        }