aznishboy

QuickCrab

Jan 26th, 2012
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.85 KB | None | 0 0
  1. import info.gridworld.actor.*;
  2. import info.gridworld.grid.*;
  3. import java.awt.Color;
  4. import java.util.ArrayList;
  5.  
  6. public class QuickCrab extends CrabCritter{
  7.     public ArrayList<Location> getMoveLocations(){
  8.         ArrayList<Location> locs = new ArrayList<Location>();
  9.         Grid gr = getGrid();  
  10.         secondValid(locs,getDirection() + Location.LEFT);
  11.         secondValid(locs,getDirection() + Location.RIGHT);
  12.         if (locs.size() == 0)
  13.             return super.getMoveLocations();
  14.         return locs;
  15.     }
  16.     private void secondValid(ArrayList<Location> locs,int dir){
  17.         Grid gr = getGrid();
  18.         Location loc = getLocation();  
  19.         Location temp = loc.getAdjacentLocation(dir);
  20.         if(gr.isValid(temp) && gr.get(temp) == null){
  21.             Location loc2 = temp.getAdjacentLocation(dir);
  22.             if(gr.isValid(loc2) && gr.get(loc2)== null)
  23.                 locs.add(loc2);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment