Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. public boolean push(Direction dir) {
  2.        
  3.         if((!dir.equals(Direction.EAST))&&(!dir.equals(Direction.WEST))){
  4.             return false;
  5.            
  6.             }
  7.        
  8.         Position curPos = owner.getPosition(this);
  9.        
  10.        
  11.             Position nextPos = curPos.moveDirection(dir);
  12.             // If next position has an object not equal to empty the rock cant move
  13.            
  14.             IBDObject nextObject = owner.get(nextPos);
  15.             if (nextObject instanceof BDEmpty&&owner.canGo(nextPos)) {
  16.                 try {
  17.                     prepareMove(nextPos.getX(), nextPos.getY());
  18.                 } catch (IllegalMoveException e) {
  19.                    
  20.                     return false;
  21.                    
  22.                 }
  23.                 owner.step();
  24.                
  25.                 return true;
  26.             }
  27.             else{
  28.                 return false;
  29.             }
  30.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement