Пример #1
0
        public static bool?determineWinner(int computerSelection, int playerSelection)
        {
            LogInFile LogInFileo = new LogInFile(new EventLogWriter());

            try
            {
                bool?[,] winMatrix =
                {
                    { null,  false, true  },
                    { true,  null,  false },
                    { false, true,  null  }
                };


                if (winMatrix[playerSelection, computerSelection] == null)
                {
                    return(null);
                }
                return((winMatrix[playerSelection, computerSelection] == true) ? true : false);
            }
            catch (Exception ex)
            {
                LogInFileo.WriteFile(ex.ToString());
                return(null);
            }
            finally
            {
                LogInFileo.WriteFile("determineWinner method");
            }
        }
Пример #2
0
        public static void determineChampion(int playerwins, int computerwins)
        {
            LogInFile LogInFileo = new LogInFile(new EventLogWriter());

            try
            {
                if (playerwins == computerwins)
                {
                    Console.WriteLine("\n");
                    Console.WriteLine("-------Final Result------ ");
                    Console.WriteLine("Match Drawn");
                    Console.ReadKey();
                }

                else if (playerwins < computerwins)
                {
                    Console.WriteLine("\n");
                    Console.WriteLine("-------Final Result------ ");
                    Console.WriteLine("Computer Wins");
                    Console.ReadKey();
                }
                else if (playerwins > computerwins)
                {
                    Console.WriteLine("\n");
                    Console.WriteLine("-------Final Result------ ");
                    Console.WriteLine("Player Wins");
                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                LogInFileo.WriteFile(ex.ToString());
            }
            finally
            {
                LogInFileo.WriteFile("determineChampion method");
            }
            return;
        }
Пример #3
0
        public static void gamesplayed()
        {
            LogInFile LogInFileo = new LogInFile(new EventLogWriter());

            try {
                Console.BackgroundColor = ConsoleColor.White;
                Console.ForegroundColor = ConsoleColor.Black;
                Contestant     computer = new Computer();
                Contestant     player   = new Player();
                Selection      computerSelection;
                Selection      playerSelection;
                ConsoleKeyInfo input;
                bool           repeat = true;

                do
                {
                    computerSelection = computer.Select();
                    playerSelection   = player.Select();


                    Console.WriteLine("\n" + "Player Selected: " + playerSelection);
                    Console.WriteLine("\n" + "Computer Selected: " + computerSelection);


                    switch (determineWinner((int)computerSelection, (int)playerSelection))
                    {
                    case null:
                        Console.Write("\nMatch Tie");
                        Console.Write("\n");
                        Console.ReadKey();
                        break;

                    case true:
                        Console.Write("\nPlayer won!");
                        Console.Write("\n");
                        player.wins++;
                        Console.ReadKey();
                        break;

                    default:
                        Console.Write("\nPlayer lost");
                        Console.Write("\n");
                        computer.wins++;
                        Console.ReadKey();
                        break;
                    }

                    RPS.GamesPlayed++;
                    if (RPS.GamesPlayed == 3)
                    {
                        determineChampion(player.wins, computer.wins);

                        Console.WriteLine("\n" + "Play again? <y/n>");
                        Console.WriteLine("\n");
                        input = Console.ReadKey(true);

                        repeat = input.KeyChar == 'y';
                        if (repeat == true)
                        {
                            GamesPlayed = 0;
                        }
                        Console.Clear();
                    }
                    int resetPosY = Console.CursorTop;
                    int resetPosX = Console.CursorLeft;
                    Console.SetCursorPosition(resetPosX, resetPosY);
                } while (repeat);
            }
            catch (Exception ex)
            {
                LogInFileo.WriteFile(ex.ToString());
            }
            finally
            {
                LogInFileo.WriteFile("gamesplayed method");
            }
        }