Advertisement
kuchuz

PBO-C EAS : King

Jan 11th, 2021
1,197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. package chessgui.pieces;
  2.  
  3. import chessgui.Board;
  4.  
  5. public class King extends Piece {
  6.  
  7.     public King(int x, int y, boolean is_white, String file_path, Board board)
  8.     {
  9.         super(x,y,is_white,file_path, board);
  10.     }
  11.    
  12.     @Override
  13.     public boolean canMove(int destination_x, int destination_y){
  14.         // Jika posisi target sudah ada buah catur dan itu milik kita, tidak boleh jalan
  15.         Piece target = board.getPiece(destination_x, destination_y);
  16.         if(target != null){
  17.             if(target.isWhite() && this.isWhite()) return false;
  18.             if(target.isBlack() && this.isBlack()) return false;
  19.         }
  20.  
  21.         // Jika jarak lebih dari 1 petak, tidak boleh jalan
  22.         if(Math.abs(this.getX() - destination_x)>1 || Math.abs(this.getY() - destination_y)>1) return false;
  23.         return true;
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement