Exemplo n.º 1
0
 public void ValidatePositionDestiny(Position origin, Position destiny)
 {
     if (!BoardGame.Piece(origin).PossibleMove(destiny))
     {
         throw new BoardException("You cannot move this piece to that destination!");
     }
 }
Exemplo n.º 2
0
        public static void PrintBoardGame(BoardGame boardGame, bool[,] possiblePositions)
        {
            ConsoleColor originalBackground  = Console.BackgroundColor;
            ConsoleColor alternateBackground = ConsoleColor.DarkGray;

            for (int i = 0; i < boardGame.Lines; i++)
            {
                Console.Write(8 - i + " ");
                for (int j = 0; j < boardGame.Columns; j++)
                {
                    if (possiblePositions[i, j])
                    {
                        Console.BackgroundColor = alternateBackground;
                    }
                    else
                    {
                        Console.BackgroundColor = originalBackground;
                    }
                    PrintPiece(boardGame.Piece(i, j));
                    Console.BackgroundColor = originalBackground;
                }
                Console.WriteLine();
            }
            Console.WriteLine("  a b c d e f g h");
            Console.BackgroundColor = originalBackground;
        }
Exemplo n.º 3
0
        public override bool[,] PossibleMoves()
        {
            bool[,] mat = new bool[BoardGame.Lines, BoardGame.Columns];

            Position pos = new Position(0, 0);

            // NO
            pos.DefineValues(Position.Line - 1, Position.Column - 1);
            while (BoardGame.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                if (BoardGame.Piece(pos) != null && BoardGame.Piece(pos).Color != Color)
                {
                    break;
                }
                pos.DefineValues(Position.Line - 1, Position.Column - 1);
            }

            // NE
            pos.DefineValues(Position.Line - 1, Position.Column + 1);
            while (BoardGame.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                if (BoardGame.Piece(pos) != null && BoardGame.Piece(pos).Color != Color)
                {
                    break;
                }
                pos.DefineValues(Position.Line - 1, Position.Column + 1);
            }

            // SE
            pos.DefineValues(Position.Line + 1, Position.Column + 1);
            while (BoardGame.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                if (BoardGame.Piece(pos) != null && BoardGame.Piece(pos).Color != Color)
                {
                    break;
                }
                pos.DefineValues(Position.Line + 1, Position.Column + 1);
            }

            // SO
            pos.DefineValues(Position.Line + 1, Position.Column - 1);
            while (BoardGame.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                if (BoardGame.Piece(pos) != null && BoardGame.Piece(pos).Color != Color)
                {
                    break;
                }
                pos.DefineValues(Position.Line + 1, Position.Column + 1);
            }

            return(mat);
        }
Exemplo n.º 4
0
 public static void PrintBoard(BoardGame board)
 {
     for (int i = 0; i < board.Lines; i++)
     {
         Console.Write(8 - i + " ");
         for (int j = 0; j < board.Columns; j++)
         {
             if (board.Piece(i, j) == null)
             {
                 Console.Write("- ");
             }
             else
             {
                 PrintPiece(board.Piece(i, j));
                 Console.Write(" ");
             }
         }
         Console.WriteLine();
     }
     Console.WriteLine(" a b c d e f g h");
 }
Exemplo n.º 5
0
 public static void PrintBoardGame(BoardGame boardGame)
 {
     for (int i = 0; i < boardGame.Lines; i++)
     {
         Console.Write(8 - i + " ");
         for (int j = 0; j < boardGame.Columns; j++)
         {
             PrintPiece(boardGame.Piece(i, j));
         }
         Console.WriteLine();
     }
     Console.WriteLine("  a b c d e f g h");
 }
Exemplo n.º 6
0
 public void ValidatePositionOrigin(Position origin)
 {
     if (BoardGame.Piece(origin) == null)
     {
         throw new BoardException("There are no pieces in the chosen position!");
     }
     if (ActualPlayer != BoardGame.Piece(origin).Color)
     {
         throw new BoardException("The piece in the chosen position is not yours!");
     }
     if (!BoardGame.Piece(origin).ExistPossibleMoves())
     {
         throw new BoardException("There are no possible movements for the chosen piece!");
     }
 }
Exemplo n.º 7
0
        private bool CanMove(Position position)
        {
            Piece piece = BoardGame.Piece(position);

            return(piece == null || piece.Color != Color);
        }
Exemplo n.º 8
0
 private bool Free(Position position)
 {
     return(BoardGame.Piece(position) == null);
 }
Exemplo n.º 9
0
        private bool ExistEnemy(Position position)
        {
            Piece piece = BoardGame.Piece(position);

            return(piece != null && piece.Color != Color);
        }