Пример #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!");
     }
 }
Пример #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;
        }
Пример #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);
        }
Пример #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");
 }
Пример #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");
 }
Пример #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!");
     }
 }
Пример #7
0
        private bool CanMove(Position position)
        {
            Piece piece = BoardGame.Piece(position);

            return(piece == null || piece.Color != Color);
        }
Пример #8
0
 private bool Free(Position position)
 {
     return(BoardGame.Piece(position) == null);
 }
Пример #9
0
        private bool ExistEnemy(Position position)
        {
            Piece piece = BoardGame.Piece(position);

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