示例#1
0
        public override bool ValidMoves(int x, int y, GameBoard gameboard)
        {
            int CurrentX = this.getCurrentPosition().Item1;
            int CurrentY = this.getCurrentPosition().Item2;

            //make the rook move horizontally
            if (CurrentX == x && CurrentY != y)
            {
                //go right
                if (y > CurrentY)
                {
                    for (int i = CurrentY + 1; i < y; i++)
                    {
                        if (gameboard.getPieces()[x, i] != null)  //if there is a piece on the way of its moving forward, then return false
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    //go left
                    for (int i = CurrentY - 1; i > y; i--)
                    {
                        if (gameboard.getPieces()[x, i] != null)  //the same
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }

            //move vertically
            if (x != CurrentX && y == CurrentY)
            {
                //go down
                if (x > CurrentX)
                {
                    for (int i = CurrentX + 1; i < x; i++)
                    {
                        if (gameboard.getPieces()[i, y] != null)  //the same
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    //go up
                    for (int i = CurrentX - 1; i > x; i--)
                    {
                        if (gameboard.getPieces()[i, y] != null)  //the same
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            return(false);
        }
示例#2
0
        public void DisplayBoard(GameBoard board)
        {
            Console.Clear();
            int selectedX = board.getSelectedX();
            int selectedY = board.getSelectedY();

            Console.BackgroundColor = ConsoleColor.DarkYellow;
            const string BoardLayout =
                "┏━┳━┳━┳━┳━┳━┳━┳━┓" +
                "┃ ┃ ┃ ┃╲┃╱┃ ┃ ┃ ┃" +
                "┣━╋━╋━╋━╋━╋━╋━╋━┫" +
                "┃ ┃ ┃ ┃╱┃╲┃ ┃ ┃ ┃" +
                "┣━╋━╋━╋━╋━╋━╋━╋━┫" +
                "┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃" +
                "┣━╋━╋━╋━╋━╋━╋━╋━┫" +
                "┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃" +
                "┣━┻━┻━┻━┻━┻━┻━┻━┫" +
                "┃               ┃" +
                "┣━┳━┳━┳━┳━┳━┳━┳━┫" +
                "┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃" +
                "┣━╋━╋━╋━╋━╋━╋━╋━┫" +
                "┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃" +
                "┣━╋━╋━╋━╋━╋━╋━╋━┫" +
                "┃ ┃ ┃ ┃╲┃╱┃ ┃ ┃ ┃" +
                "┣━╋━╋━╋━╋━╋━╋━╋━┫" +
                "┃ ┃ ┃ ┃╱┃╲┃ ┃ ┃ ┃" +
                "┗━┻━┻━┻━┻━┻━┻━┻━┛";

            for (int i = 0; i < 19; i++)
            {
                Console.ForegroundColor = ConsoleColor.Black;
                if (i % 2 == 0)
                {
                    Console.Write(i / 2 + " ");
                }
                else
                {
                    Console.Write("  ");
                }

                for (int j = 0; j < 17; j++)
                {
                    if (i % 2 == 0 && j % 2 == 0 && board.getPieceName(i / 2, j / 2) != "")
                    {
                        Console.ForegroundColor = ConsoleColor.Black;
                        if (i / 2 == selectedX && j / 2 == selectedY)
                        {
                            Console.BackgroundColor = ConsoleColor.DarkGreen;
                        }
                        if (board.getPiecePlayer(i / 2, j / 2) == "red")
                        {
                            Console.ForegroundColor = ConsoleColor.DarkRed;
                        }
                        Console.Write(board.getPieceName(i / 2, j / 2));
                        if (i / 2 == selectedX && j / 2 == selectedY)
                        {
                            Console.BackgroundColor = ConsoleColor.DarkYellow;
                        }
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write(BoardLayout[i * 17 + j]);
                    }
                }
                Console.WriteLine();
            }
            Console.WriteLine("  a b c d e f g h i");
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("Currrent Player: ");
            if (board.getPlayer() == "red")
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Red");
                Console.ForegroundColor = ConsoleColor.White;
            }
            else
            {
                Console.WriteLine("Black");
            }
        }