Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. public boolean hasCapturableEnemy(Piece[][] board, int startX, int startY, int endX, int endY) {
  2.  
  3. //If the Pawn belong to the Upper Team (Faces downward)
  4. if(board[startX][startY] != null && board[startX][startY].getTeam() == Player.UP) {
  5. //If a Piece exists on a diagonally adjacent tile, return true
  6. if(startX - endX == -1 && Math.abs(startY - endY) == 1) {
  7. if( (board[startX + 1][startY - 1] != null && board[startX + 1][startY - 1].getTeam() != Player.UP) ||
  8. (board[startX + 1][startY + 1] != null && board[startX + 1][startY + 1].getTeam() != Player.UP)) {
  9. return true;
  10. }
  11. }
  12. }
  13.  
  14. if(board[startX][startY] != null && board[startX][startY].getTeam() == Player.DOWN) {
  15. //If the Pawn belongs to the Down Team (Faces upward)
  16.  
  17. if(startX - endX == 1 && Math.abs(startY - endY) == 1) {
  18. //If a Piece exists on a diagonally adjacent tile, return true
  19. if( (board[startX - 1][startY - 1] != null && board[startX - 1][startY - 1].getTeam() != Player.DOWN) ||
  20. (board[startX - 1][startY + 1] != null && board[startX - 1][startY + 1].getTeam() != Player.DOWN)) {
  21. return true;
  22. }
  23. }
  24. }
  25.  
  26. return false;
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement