Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. @Override
  2. public boolean move(int y, int x) {
  3. if (!(0 <= y && y < 8) || !(0 <= x && x < 8)) { // Checks if the chosen coord. is out of bounds.
  4. this.currentMessage = "Please choose a position within the board!";
  5. return false;
  6. }
  7.  
  8. if (board[y][x] != null) { // Om rutan har en pjäs.
  9. if (board[y][x].getWhite() == white) { // Om det är ens egna färg.
  10. activePiece = board[y][x];
  11. return true;
  12. }
  13. else if (activePiece == null){ // Om det är första draget och motståndarens färg.
  14. this.currentMessage = "Välj en pjäs av din egna färg.";
  15. return false;
  16. }
  17. else { // Om det är andra draget - attackera motståndare.
  18. if (activePiece.checkMove(y, x, board)) { // Kollar om pjäsens drag är giltigt.
  19. makeMove(y, x);
  20. return true;
  21. }
  22. }
  23. }
  24. else if (activePiece == null) { // Om rutan är tom och det är första draget.
  25. this.currentMessage = "Välj en pjäs.";
  26. return false;
  27. }
  28. else { // Om rutan är tom och det är andra draget.
  29. if (activePiece.checkMove(y, x, board)) { // Kollar om pjäsens drag är giltigt.
  30. makeMove(y, x);
  31. return true;
  32. }
  33. }
  34. return false;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement