示例#1
0
  /**
   * @param 0 <= x < dungeon.width
   * @param 0 <= y < dungeon.height
   */
  public Chara(Dungeon dungeon) {
    this.dungeon = dungeon;

    // if no room then re-generate x, y
    do {
      x = PSUDO_RANDOM.nextInt(dungeon.width());
      y = PSUDO_RANDOM.nextInt(dungeon.height());

    } while (!dungeon.isRoom(x, y));
  }
示例#2
0
  /**
   * move the chara to the specified direction.
   *
   * @return <code>true</code> if the chara was successfully moved. <code>false</code> otherwise.
   */
  public boolean moveTo(Direction direction) {

    int newx = getNewLocationX(direction);
    int newy = getNewLocationY(direction);

    boolean newxOk = isInRange(newx, 0, dungeon.width());
    boolean newyOk = isInRange(newy, 0, dungeon.height());

    // check if the new location is a room.
    boolean allOk = newxOk && newyOk && dungeon.isRoom(newx, newy);
    if (allOk) {
      x = newx;
      y = newy;
    }

    return allOk;
  }