Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean hasCapturableEnemy(Piece[][] board, int startX, int startY, int endX, int endY) {
- //If the Pawn belong to the Upper Team (Faces downward)
- if(board[startX][startY] != null && board[startX][startY].getTeam() == Player.UP) {
- //If a Piece exists on a diagonally adjacent tile, return true
- if(startX - endX == -1 && Math.abs(startY - endY) == 1) {
- if( (board[startX + 1][startY - 1] != null && board[startX + 1][startY - 1].getTeam() != Player.UP) ||
- (board[startX + 1][startY + 1] != null && board[startX + 1][startY + 1].getTeam() != Player.UP)) {
- return true;
- }
- }
- }
- if(board[startX][startY] != null && board[startX][startY].getTeam() == Player.DOWN) {
- //If the Pawn belongs to the Down Team (Faces upward)
- if(startX - endX == 1 && Math.abs(startY - endY) == 1) {
- //If a Piece exists on a diagonally adjacent tile, return true
- if( (board[startX - 1][startY - 1] != null && board[startX - 1][startY - 1].getTeam() != Player.DOWN) ||
- (board[startX - 1][startY + 1] != null && board[startX - 1][startY + 1].getTeam() != Player.DOWN)) {
- return true;
- }
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement