Exemplo n.º 1
0
        public void DoGame(GameBoard.Player player,
                           Func <GameBoard, GameBoard.Player, GameHistory.GameMove> player1Move,
                           Func <GameBoard, GameBoard.Player, GameHistory.GameMove> player2Move)
        {
            currentBoard = GameBoard.StartGame;
            ConsoleWriteLine("Start New Game");
            currentBoard.DisplayBoard();
            while (!currentBoard.Winner(player) && !currentBoard.IsTie())
            {
                //reverse player
                player = (player == GameBoard.Player.O) ? GameBoard.Player.X : GameBoard.Player.O;

                GameHistory.GameMove move = player1Move(currentBoard, player);
                ConsoleWriteLine(String.Format("The First player places {0}.", move));
                gameHistory.MakeMove(currentBoard, move);
                currentBoard.DoMove(move);
                currentBoard.DisplayBoard();
                if (currentBoard.Winner(player))
                {
                    break;
                }

                player = (player == GameBoard.Player.O) ? GameBoard.Player.X : GameBoard.Player.O;
                //query game stats to get next move
                move = player2Move(currentBoard, player);
                ConsoleWriteLine(String.Format("The Second player places {0}.", move));
                //register move in game hidtory
                gameHistory.MakeMove(currentBoard, move);
                //update current board
                currentBoard.DoMove(move);
                currentBoard.DisplayBoard();
            }
            //by default all games start with X. Game win is relative to player X
            gameHistory.RegisterGameResults(currentBoard.Winner(GameBoard.Player.X));
        }