示例#1
0
 public Move(CrossesBoard boardAfterMove, IPlayer player, BoardPosition positionPlayed, MoveResult isValidMove, int moveNumber = 1, string message = "")
 {
     _boardAfterMove = boardAfterMove;
     _player         = player;
     _position       = positionPlayed;
     _message        = message;
     _moveResult     = isValidMove;
     _moveNumber     = moveNumber;
 }
示例#2
0
        public CrossesBoard Copy()
        {
            var boardCopy = new CrossesBoard();

            for (int columns = 0; columns < BOARD_SIZE; columns++)
            {
                for (int rows = 0; rows < BOARD_SIZE; rows++)
                {
                    boardCopy._board[columns, rows] = _board[columns, rows];
                }
            }
            return(boardCopy);
        }
示例#3
0
        private static bool EmptySpacesExist(CrossesBoard board)
        {
            for (int rowIndex = 0; rowIndex < CrossesBoard.BOARD_SIZE; rowIndex++)
            {
                for (int columnIndex = 0; columnIndex < CrossesBoard.BOARD_SIZE; columnIndex++)
                {
                    if (board.TokenAt(BoardPosition.At(columnIndex, rowIndex)) == GameToken.None)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#4
0
        private static void DisplayMove(Game game, Move move, CrossesBoard board, bool showInfo)
        {
            Console.Clear();
            ShowGameHeader(game);
            Console.WriteLine("Move {0}: {1}", move.Number, move.MoveText());
            Console.WriteLine(BoardVisualiser.ToString(board));

            if (showInfo)
            {
                DisplayHelper.SetTextColour(ConsoleColor.Red);
                Console.WriteLine(move.Information());
                DisplayHelper.ResetTextColour();
            }
            else
            {
                Console.WriteLine();
            }
        }
示例#5
0
        public static string ToString(CrossesBoard board)
        {
            const string TOP_LINE         = "  ┌───┬───┬───┐";
            const string HORIZONTAL_LINE  = "  ├───┼───┼───┤";
            const string VERTICAL_SECTION = "│";
            const string BOTTOM_LINE      = "  └───┴───┴───┘";
            const string NEWLINE          = "\r\n";

            Dictionary <GameToken, string> displayToken = new Dictionary <GameToken, string> {
                { GameToken.Player1, "X" },
                { GameToken.Player2, "O" },
                { GameToken.None, " " },
            };

            var output = new StringBuilder(NEWLINE);

            output.AppendLine("    0   1   2");
            output.AppendLine(TOP_LINE);

            for (int rows = 0; rows < CrossesBoard.BOARD_SIZE; rows++)
            {
                output.Append(rows + " ");
                for (int columns = 0; columns < CrossesBoard.BOARD_SIZE; columns++)
                {
                    output.Append(VERTICAL_SECTION + " ");
                    output.Append(displayToken[board.TokenAt(new BoardPosition(columns, rows))] + " ");
                }

                output.AppendLine(VERTICAL_SECTION);

                if (rows < CrossesBoard.BOARD_SIZE - 1)
                {
                    output.AppendLine(HORIZONTAL_LINE);
                }
            }

            output.AppendLine(BOTTOM_LINE);

            return(output.ToString());
        }
示例#6
0
        internal static void Show(Game game)
        {
            Console.Clear();
            ShowGameHeader(game);
            Thread.Sleep(1500);

            var previousBoard = new CrossesBoard();

            foreach (var move in game.Moves)
            {
                DisplayMove(game, move, previousBoard, showInfo: false);
                DisplayHelper.ShowAnyKeyToSkipGameMessage();

                Thread.Sleep(800);
                if (SkipRequested())
                {
                    return;
                }

                DisplayMove(game, move, move.Board, showInfo: true);

                if (move != LastMove(game))
                {
                    DisplayHelper.ShowAnyKeyToSkipGameMessage();

                    Thread.Sleep(GetPauseTimeFor(move));

                    if (SkipRequested())
                    {
                        return;
                    }
                }

                previousBoard = move.Board;
            }

            ShowGameResults(game);

            DisplayHelper.AnyKeyToContinue("\n\n[Press any key to continue...]");
        }
示例#7
0
        public GameStatus GetStatusFrom(CrossesBoard board)
        {
            foreach (var winningRow in _winningRows)
            {
                if (winningRow.All(position => board.TokenAt(position) == GameToken.Player1))
                {
                    return(GameStatus.Player1Wins);
                }

                if (winningRow.All(position => board.TokenAt(position) == GameToken.Player2))
                {
                    return(GameStatus.Player2Wins);
                }
            }

            if (!EmptySpacesExist(board))
            {
                return(GameStatus.Draw);
            }

            return(GameStatus.Ongoing);
        }