public void ValidatePositionDestiny(Position origin, Position destiny) { if (!BoardGame.Piece(origin).PossibleMove(destiny)) { throw new BoardException("You cannot move this piece to that destination!"); } }
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; }
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); }
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"); }
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"); }
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!"); } }
private bool CanMove(Position position) { Piece piece = BoardGame.Piece(position); return(piece == null || piece.Color != Color); }
private bool Free(Position position) { return(BoardGame.Piece(position) == null); }
private bool ExistEnemy(Position position) { Piece piece = BoardGame.Piece(position); return(piece != null && piece.Color != Color); }