private void UnSelectPiece() { squaresMovableTo = null; selectedPiece = null; }
private void GetSelectedPiece(XNAGameBoardPostion selectedSquare) { if (gameBoard.IsPieceInThisSquare(selectedSquare.GameBoardSpace.X, selectedSquare.GameBoardSpace.Y)) selectedPiece = gameBoard.GameBoardSpaces[selectedSquare.GameBoardSpace.X, selectedSquare.GameBoardSpace.Y]; }
private void HighLightPossibleMoves(DraughtPiece selectedPiece, PlayerColours colour) { List<GamePieceMove> moves; squaresMovableTo = new List<Rectangle>(); moves = gameBoard.GetAllPossibleMovesForThisPiece(selectedPiece); foreach (GamePieceMove move in moves) { Rectangle rect = xnaGameBoard.BoardSpaces[move.NewHorizontalPostion, move.NewVerticalPostion]; squaresMovableTo.Add(rect); } }
private void SetTheGameBoard() { gameBoardSpaces = new DraughtPiece[GAMEBOARDWIDTH, GAMEBOARDHEIGHT]; for (int i = 0; i <= GAMEBOARDWIDTH - 1; i++) for (int j = 0; j <= GAMEBOARDHEIGHT - 1; j++) { if ((i == 0 || i == 2) && j % 2 == 0) gameBoardSpaces[i, j] = new DraughtPiece(PlayerColours.White,i,j); else if (i == 1 && j % 2 != 0) gameBoardSpaces[i, j] = new DraughtPiece(PlayerColours.White, i, j); else if ((i == 5 || i == 7) && j % 2 != 0) gameBoardSpaces[i, j] = new DraughtPiece(PlayerColours.Black, i, j); else if (i == 6 && j % 2 == 0) gameBoardSpaces[i, j] = new DraughtPiece(PlayerColours.Black, i, j); else gameBoardSpaces[i, j] = null; } }
public List<GamePieceMove> GetAllPossibleJumpsForThisPiece(DraughtPiece piece) { List<GamePieceMove> jumps = new List<GamePieceMove>(); GamePieceMove jump; jump = new GamePieceMove(piece, piece.HorizontalPostion - 2, piece.VerticalPostion - 2); if (IsMoveLegal(jump)) jumps.Add(jump); jump = new GamePieceMove(piece, piece.HorizontalPostion - 2, piece.VerticalPostion + 2); if (IsMoveLegal(jump)) jumps.Add(jump); jump = new GamePieceMove(piece, piece.HorizontalPostion + 2, piece.VerticalPostion - 2); if (IsMoveLegal(jump)) jumps.Add(jump); jump = new GamePieceMove(piece, piece.HorizontalPostion + 2, piece.VerticalPostion + 2); if (IsMoveLegal(jump)) jumps.Add(jump); return jumps; }
private Boolean IsPieceToBeCrowned(DraughtPiece piece) { const int BLACKSIDEOFBOARD = 7; const int WHITESIDEOFBOARD = 0; if (piece.PieceColour == PlayerColours.White) if (piece.HorizontalPostion == BLACKSIDEOFBOARD) return true; else return false; else if (piece.HorizontalPostion == WHITESIDEOFBOARD) return true; else return false; }
private Boolean IsOpponentToTheTopRight(DraughtPiece piece) { if (gameBoardSpaces[piece.HorizontalPostion + 1, piece.VerticalPostion - 1] != null) { if (gameBoardSpaces[piece.HorizontalPostion + 1, piece.VerticalPostion - 1].PieceColour == GetOpponentColour(piece.PieceColour)) return true; else return false; } else return false; }
public Boolean IsMovablePieceSelected(DraughtPiece selectedPiece, PlayerColours colour) { bool allMovesFound = true; List<GamePieceMove> allPossibleMove = GetAllPossibleMoves(colour); List<GamePieceMove> allPossibleMoveForThisPiece = GetAllPossibleMovesForThisPiece(selectedPiece); foreach (GamePieceMove move in allPossibleMoveForThisPiece) { if (!allPossibleMove.Contains(move)) allMovesFound = false; } return allMovesFound; }
public List<GamePieceMove> GetAllPossibleNormalMovesForThisPiece(DraughtPiece piece) { List<GamePieceMove> moves = new List<GamePieceMove>(); GamePieceMove move; move = new GamePieceMove(piece, piece.HorizontalPostion - 1, piece.VerticalPostion - 1); if (IsMoveLegal(move)) moves.Add(move); move = new GamePieceMove(piece, piece.HorizontalPostion - 1, piece.VerticalPostion + 1); if (IsMoveLegal(move)) moves.Add(move); move = new GamePieceMove(piece, piece.HorizontalPostion + 1, piece.VerticalPostion - 1); if (IsMoveLegal(move)) moves.Add(move); move = new GamePieceMove(piece, piece.HorizontalPostion + 1, piece.VerticalPostion + 1); if (IsMoveLegal(move)) moves.Add(move); return moves; }
public List<GamePieceMove> GetAllPossibleMovesForThisPiece(DraughtPiece piece) { List<GamePieceMove> allPossibleMovesForThisPiece = new List<GamePieceMove>(); allPossibleMovesForThisPiece.AddRange(GetAllPossibleJumpsForThisPiece(piece)); if (forcedJumpsOn && allPossibleMovesForThisPiece.Count == 0) allPossibleMovesForThisPiece.AddRange(GetAllPossibleNormalMovesForThisPiece(piece)); else if (!forcedJumpsOn) allPossibleMovesForThisPiece.AddRange(GetAllPossibleNormalMovesForThisPiece(piece)); return allPossibleMovesForThisPiece; }