Пример #1
0
        public void Start()
        {
            "Welcome To nim, his name is Fred.".ToConsole();

            while (true) {

                "Game Mode?".ToConsole();
                "1) PvP".ToConsole();
                "2) PvE (You First)".ToConsole();
                "3) PvE (AI First)".ToConsole();
                "4) EvE".ToConsole();
                "5) Train".ToConsole();
                "6) Exit".ToConsole();

                int roundsToPlay = 1;

                switch (IOHelper.PromptForInputInt("Option?", 1, 6)) {
                    case 1:
                        Player1 = new HumanPlayer("Player 1");
                        Player2 = new HumanPlayer("Player 2");
                        break;
                    case 2:
                        Player1 = new HumanPlayer("Player 1");
                        Player2 = new AIPlayer("Player 2", StateStore);
                        break;
                    case 3:
                        Player1 = new HumanPlayer("Player 1");
                        Player2 = new AIPlayer("Player 2", StateStore);
                        break;
                    case 4:
                        roundsToPlay = IOHelper.PromptForInputInt("Number of rounds to play?", 1);
                        Player1 = new AIPlayer("Player 1", StateStore);
                        Player2 = new AIPlayer("Player 2", StateStore);
                        break;
                    case 5:
                        roundsToPlay = IOHelper.PromptForInputInt("Number of rounds to train?", 1);
                        Player1 = new AIPlayer("Player 1", StateStore);
                        Player2 = new AIPlayer("Player 2", StateStore);
                        while (roundsToPlay-- >= 1)
                            DoGame();
                        roundsToPlay = 0;
                        break;
                    default:
                        return;
                }

                Console.WriteLine();

                while (roundsToPlay-- >= 1) {

                    ("\nGame Winner is: " + DoGame()).ToConsole();
                    IOHelper.Pause();
                    Console.WriteLine();
                }

                ("Database weight is now: " + StateStore.GetWeight()).ToConsole();
                "And again we player...".ToConsole();
                Console.WriteLine();
            }
        }
Пример #2
0
 public void PlayerInput()
 {
     HumanPlayer player1 = new HumanPlayer(writer, readLine);
     ComputerPlayer computerPlayer = new ComputerPlayer();
     game.newGame();
     Random randgen = new Random();
     int rand = randgen.Next(0, 2);
     bool isPlayerTurn = rand % 2 == 0;
     if (isPlayerTurn){
         writer("Congradulations, you get to go first!");
     }else{
         writer("The computer goes first.");
     }
     while (!game.gameIsOver())
     {
         if (isPlayerTurn)
         {
             player1.makeMove(game);
         }
         else
         {
             computerPlayer.makeMove(game);
         }
         isPlayerTurn = !isPlayerTurn;
         if (game.gameIsOver() && isPlayerTurn)
         {
             writer("You win!");
         }
         else if (game.gameIsOver())
         {
             writer("You lose");
         }
     }
     game.endGame();
 }