Пример #1
0
        private bool getPlayerMove(Player i_Player, Board i_Board, BoardPainter i_BoardPainter,
                                   ref GameCell io_FirstCell, ref GameCell io_SecondCell)
        {
            bool isHuman = i_Player.Type == ePlayerType.Human;

            //// Get First Half of Move - Human + Computer
            i_BoardPainter.ClearAndPaintBoard();
            bool didNotQuit = getPlayerHalfMove(i_Player, i_Board, ref io_FirstCell);

            if (didNotQuit)
            {
                //// Show Board Between the moves
                i_BoardPainter.ClearAndPaintBoard();

                //// Make computer sleep between moves
                if (!isHuman)
                {
                    Thread.Sleep(2000);
                }

                //// Get Second Half of Move
                if (isHuman)
                {
                    didNotQuit = getPlayerHalfMove(i_Player, i_Board, ref io_SecondCell);
                }
                else
                {
                    io_SecondCell = i_Player.ComputerAiMove(i_Board, io_FirstCell);
                }
            }

            return(didNotQuit);
        }
Пример #2
0
        private bool runSingleGame(Player i_FirstPlayer, Player i_SecondPlayer, Board i_Board)
        {
            GameManager  gameManager     = new GameManager(i_FirstPlayer, i_SecondPlayer, i_Board);
            bool         gameStillActive = true;
            Player       currentPlayer   = i_FirstPlayer;
            BoardPainter boardPainter    = new BoardPainter(i_Board);

            while (gameStillActive)
            {
                GameCell firstCell  = null;
                GameCell secondCell = null;

                //// Get a move from the player / computer - if player quits returns false
                gameStillActive = getPlayerMove(currentPlayer, i_Board, boardPainter, ref firstCell, ref secondCell);
                if (!gameStillActive)
                {
                    break;
                }

                if (i_SecondPlayer.Type == ePlayerType.Computer)
                {
                    i_SecondPlayer.ComputerRememberCell(firstCell);
                    i_SecondPlayer.ComputerRememberCell(secondCell);
                }

                boardPainter.ClearAndPaintBoard();

                currentPlayer = gameManager.ExecuteMove(currentPlayer, firstCell, secondCell);
                if (gameManager.IsGameOver())
                {
                    break;
                }
            }

            if (gameStillActive)
            { // Finished game without quitting
                announceWinner(i_FirstPlayer, i_SecondPlayer);
                gameStillActive = stillWantToPlay();
            }

            return(gameStillActive);
        }