コード例 #1
0
ファイル: JumperBug.java プロジェクト: jhaag/Gridworld
 public boolean canMove() {
   Grid<Actor> gr = getGrid();
   if (gr == null) return false;
   Location loc = getLocation();
   Location next = loc.getAdjacentLocation(getDirection()).getAdjacentLocation(getDirection());
   if (!gr.isValid(next)) return false;
   Actor neighbor = gr.get(next);
   return (neighbor == null) || (neighbor instanceof Flower);
 }
コード例 #2
0
 public void move() {
   Grid<Actor> gr = getGrid();
   if (gr == null) return;
   Location loc = getLocation();
   Location next = loc.getAdjacentLocation(getDirection());
   if (gr.isValid(next)) {
     nextActor = gr.get(next);
     moveTo(next);
     if (oldActor != null) oldActor.putSelfInGrid(gr, loc);
     oldActor = nextActor;
   } else removeSelfFromGrid();
 }
コード例 #3
0
 public boolean canMove() {
   Grid<Actor> gr = getGrid();
   if (gr == null) return false;
   Location loc = getLocation();
   Location next = loc.getAdjacentLocation(getDirection());
   if (!gr.isValid(next)) return false;
   Actor neighbor = gr.get(next);
   return (neighbor == null)
       || (neighbor instanceof TallGrass)
       || (neighbor instanceof Green)
       || (neighbor instanceof Path)
       || (neighbor instanceof Cave43)
       || (neighbor instanceof Cave33);
   // not ok to move onto water or rocks
 }