Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public boolean move(int y, int x) {
- if (!(0 <= y && y < 8) || !(0 <= x && x < 8)) { // Checks if the chosen coord. is out of bounds.
- this.currentMessage = "Please choose a position within the board!";
- return false;
- }
- if (board[y][x] != null) { // Om rutan har en pjäs.
- if (board[y][x].getWhite() == white) { // Om det är ens egna färg.
- activePiece = board[y][x];
- return true;
- }
- else if (activePiece == null){ // Om det är första draget och motståndarens färg.
- this.currentMessage = "Välj en pjäs av din egna färg.";
- return false;
- }
- else { // Om det är andra draget - attackera motståndare.
- if (activePiece.checkMove(y, x, board)) { // Kollar om pjäsens drag är giltigt.
- makeMove(y, x);
- return true;
- }
- }
- }
- else if (activePiece == null) { // Om rutan är tom och det är första draget.
- this.currentMessage = "Välj en pjäs.";
- return false;
- }
- else { // Om rutan är tom och det är andra draget.
- if (activePiece.checkMove(y, x, board)) { // Kollar om pjäsens drag är giltigt.
- makeMove(y, x);
- return true;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement