Пример #1
0
  /**
   * Tests whether this jumper can move forward into a location.
   *
   * @return true if this jumper can move.
   */
  public boolean canMove() {
    // If the jumper is not in the grid, it cannot move.
    Grid<Actor> gr = getGrid();
    if (gr == null) {
      return false;
    }

    Location loc = getLocation();
    // If the location in front of the jumper is out of the grid, it cannot move.
    Location nextOne = loc.getAdjacentLocation(getDirection());
    if (!gr.isValid(nextOne)) {
      return false;
    }

    // If the location two cells in front is out of the grid, it cannot move.
    Location nextTwo = nextOne.getAdjacentLocation(getDirection());
    if (!gr.isValid(nextTwo)) {
      return false;
    }

    Actor neighbor = gr.get(nextTwo);
    return (neighbor == null) || (neighbor instanceof Flower) || (neighbor instanceof Rock);
    // ok to move into empty location or onto flower and rock.
    // not ok to move onto any other actor
  }
Пример #2
0
 private String getToolTipText(Location loc) {
   if (!toolTipsEnabled || loc == null || !grid.isValid(loc)) return null;
   Object f = grid.get(loc);
   if (f != null)
     return MessageFormat.format(
         resources.getString("cell.tooltip.nonempty"), new Object[] {loc, f});
   else
     return MessageFormat.format(resources.getString("cell.tooltip.empty"), new Object[] {loc, f});
 }
Пример #3
0
 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);
 }
Пример #4
0
  public void act() {
    Grid<Actor> gr = getGrid();
    Location location = new Location(6, 0);
    Location rightLoc = new Location(6, 19);

    if (oldActor instanceof Cave33) {
      if (getLocation().equals(new Location(3, 15))) {
        removeSelfFromGrid();
        oldActor.putSelfInGrid(gr, new Location(3, 15));
        oldActor = gr.get(new Location(11, 10));
        putSelfInGrid(gr, new Location(11, 10));
        directionSuffix = "down";
      } else {
        if (getLocation().equals(new Location(10, 10))) {
          removeSelfFromGrid();
          oldActor.putSelfInGrid(gr, new Location(10, 10));
          oldActor = gr.get(new Location(4, 15));
          putSelfInGrid(gr, new Location(4, 15));
          directionSuffix = "down";
        }
      }
    }

    if (getLocation().equals(location)) {
      if ((world2 == true) && (switched == false)) {
        ((PokemonGrid) gr).fillWorld1();
        oldActor = gr.get(new Location(6, 19));
        putSelfInGrid(gr, new Location(6, 19));
        world2 = false;
        switched = true;
      }
    } else {
      if (getLocation().equals(rightLoc)) {
        if ((world2 == false) && (switched == false)) {
          ((PokemonGrid) gr).fillWorld2();
          oldActor = gr.get(new Location(6, 0));
          putSelfInGrid(gr, new Location(6, 0));
          world2 = true;
          switched = true;
        }
      } else switched = false;
    }
  }
  public void step() {
    Grid<Actor> gr = getGrid();
    ArrayList<Actor> actors = new ArrayList<Actor>();
    for (Location loc : gr.getOccupiedLocations()) actors.add(gr.get(loc));

    for (Actor a : actors) {
      // only act if another actor hasn't removed a
      if (a.getGrid() == gr) a.act();
    }
  }
Пример #6
0
  /**
   * Draws the occupants of the grid.
   *
   * @param g2 the graphics context
   */
  private void drawOccupants(Graphics2D g2) {
    ArrayList<Location> occupantLocs = grid.getOccupiedLocations();
    for (int index = 0; index < occupantLocs.size(); index++) {
      Location loc = (Location) occupantLocs.get(index);

      int xleft = colToXCoord(loc.getCol());
      int ytop = rowToYCoord(loc.getRow());
      drawOccupant(g2, xleft, ytop, grid.get(loc));
    }
  }
Пример #7
0
 /**
  * Tests whether this jumper can move forward into a location that is empty
  *
  * @return true if this jumper can move.
  */
 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);
   // ok to move into empty location
   // not ok to move onto any other actor
 }
Пример #8
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();
 }
  public boolean canMove(Location nextLocation) {
    Grid<Actor> gr = getGrid();
    if (gr == null) {
      return false;
    }

    if (!gr.isValid(nextLocation)) {
      return false;
    }
    Actor neighbor = gr.get(nextLocation);

    return (neighbor == null) || (neighbor instanceof Flower);
  }
Пример #10
0
  /** @return list of empty locations that are two spaces to its right or left. */
  public ArrayList<Location> getMoveLocations() {
    ArrayList<Location> locs = new ArrayList<Location>();
    Grid gr = getGrid();

    Location loc1 = getLocation().getAdjacentLocation(getDirection() + Location.LEFT);
    if (gr.isValid(loc1) && gr.get(loc1) == null) {
      int[] dirs1 = {Location.LEFT};
      for (Location loc : getLocationsInDirections(dirs1, loc1))
        if (getGrid().get(loc) == null) locs.add(loc);
    }

    Location loc2 = getLocation().getAdjacentLocation(getDirection() + Location.RIGHT);
    if (gr.isValid(loc2) && gr.get(loc2) == null) {
      int[] dirs2 = {Location.RIGHT};
      for (Location loc : getLocationsInDirections(dirs2, loc2))
        if (getGrid().get(loc) == null) locs.add(loc);
    }

    if (locs.size() == 0) {
      return super.getMoveLocations();
    } else {
      return locs;
    }
  }
Пример #11
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
 }
Пример #12
0
 /**
  * CREATE A NEW METHOD GETLOCAITONSINDIRECTIONNEW NEED A LOCTION PARAMETER RETURN FURTHER LOCITON
  * SET FORM THIS LOCATION
  */
 public ArrayList<Location> getLocationsInDirectionsNew(Location locParameter) {
   ArrayList<Location> locs = new ArrayList<Location>();
   Grid gr = getGrid();
   Location loc = new Location(locParameter.getRow(), locParameter.getCol());
   // PROTECT DATA
   int[] directions = {Location.LEFT, Location.RIGHT};
   for (int d : directions) {
     Location neighborLoc = loc.getAdjacentLocation(getDirection() + d);
     if (gr.isValid(neighborLoc) && gr.get(neighborLoc) == null) {
       // JUDGE LOCATION IS VALID IN THE GRID
       // JUDGE LOCAITON IS NULL THAT CAN WALK IN
       locs.add(neighborLoc);
     }
   }
   return locs;
 }
Пример #13
0
 public void getOldActor(Grid gr, Location loc) {
   oldActor = (Actor) (gr.get(new Location(6, 10)));
 }