Ejemplo n.º 1
0
  /**
   * Sets the face and passable value of the tile at the specified (x, y) location.
   *
   * @param face the new face of the tile
   * @param passable the new passable value of the tile
   * @param x the x value of the position being updated
   * @param y the y value of the position being updated
   */
  public void setTile(ColoredChar face, boolean passable, int x, int y) {
    Guard.argumentIsNotNull(face);
    Guard.argumentsInsideBounds(x, y, width, height);

    grid[x][y].face = face;
    grid[x][y].passable = passable;
  }
Ejemplo n.º 2
0
  /**
   * Sets the count for a particular value in the specified {@code Categorical} distribution.
   *
   * @param key the key of the {@code Categorical} being modified
   * @param value the value whose count is being set
   * @param count the new count of the value
   */
  public void setCount(K key, V value, int count) {
    Guard.argumentsAreNotNull(key, value);
    Guard.argumentIsNonNegative(count);

    int change = count - getCountGiven(key, value);
    totals.setCount(value, totals.getCount(value) + change);
    getCategorical(key).setCount(value, count);
  }
Ejemplo n.º 3
0
  /**
   * Removes an {@code Actor} from the {@code World}. The {@code Actor} must be both bound to this
   * {@code World} and not held by another {@code Actor}. However, if the {@code Actor} is expired,
   * it may always be removed.
   *
   * @param actor the {@code Actor} to be removed
   */
  public void removeActor(Actor actor) {
    Guard.argumentIsNotNull(actor);
    Guard.verifyState(actor.bound(this));
    Guard.verifyState(!actor.held() || actor.expired());

    unregisterActor(actor);
    removeFromGrid(actor);
    actor.setWorld(null);
  }
Ejemplo n.º 4
0
  /**
   * Adds an {@code Actor} to the {@code World} at the specified location.
   *
   * @param actor the {@code World} being added
   * @param x the x location of the {@code Actor}
   * @param y the y location of the {@code Actor}
   */
  public void addActor(Actor actor, int x, int y) {
    Guard.argumentIsNotNull(actor);
    Guard.argumentsInsideBounds(x, y, width, height);
    Guard.verifyState(!actor.bound());
    Guard.verifyState(!actor.held());

    actor.setWorld(this);
    actor.setXY(x, y);
    addToGrid(actor);
    registerActor(actor);
  }
Ejemplo n.º 5
0
  /**
   * Gets a randomly chosen open tile on the {@code World} within the given bounds. If after 100
   * randomly selected tiles are closed, then each tile will be checked and the first open tile
   * found is returned. If the entire {@code World} is closed, null is returned.
   *
   * @param dice the random number generator used to randomly select tiles
   * @param x1 the bounds left most value
   * @param y1 the bounds upper most value
   * @param x2 the bounds right most value
   * @param y2 the bounds bottom most value
   * @return a randomly chosen open tile
   */
  public Coordinate getOpenTile(Dice dice, int x1, int y1, int x2, int y2) {
    Guard.argumentIsNotNull(dice);
    Guard.argumentsInsideBounds(x1, y1, width, height);
    Guard.argumentsInsideBounds(x2, y2, width, height);

    for (int i = 0; i < 100; i++) {
      int x = dice.nextInt(x1, x2);
      int y = dice.nextInt(y1, y2);
      if (passableAt(x, y)) return new Coordinate(x, y);
    }

    for (int x = x1; x <= x2; x++)
      for (int y = y1; y <= y2; y++) if (passableAt(x, y)) return new Coordinate(x, y);

    return null;
  }
Ejemplo n.º 6
0
  /**
   * Constructs a new {@code World} with the given dimensions. Both width and height must be
   * positive integers.
   *
   * @param width the width of the new {@code World}
   * @param height the height of the new {@code World}
   */
  public World(int width, int height) {
    Guard.argumentsArePositive(width, height);

    this.width = width;
    this.height = height;
    grid = new Tile[width][height];
    for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) grid[x][y] = new Tile();
    register = new HashSet<Actor>();

    drawOrder = new ArrayList<Class<? extends Actor>>();
    drawOrder.add(Actor.class);

    actOrder = new ArrayList<Class<? extends Actor>>();
    actOrder.add(Actor.class);
  }
Ejemplo n.º 7
0
  /**
   * Returns every tile that is visible at a given location, ordered such that the tile with highest
   * priority (the tile returned by look) is first, and the lowest priority is last. This last tile
   * will be the face of the actual tile itself. Note that any actor which has a null face will not
   * be included.
   *
   * @param x the x value of the location being queried
   * @param y the y value of the location being queried
   * @return every tile that is visible at a given location
   */
  public List<ColoredChar> lookAll(int x, int y) {
    Guard.argumentsInsideBounds(x, y, width, height);

    List<ColoredChar> look = new ArrayList<ColoredChar>();

    for (Class<? extends Actor> cls : drawOrder)
      for (Actor actor : getActorsAt(cls, x, y)) {
        ColoredChar face = actor.face();
        if (face != null) look.add(actor.face());
      }

    look.add(tileAt(x, y));

    return look;
  }
Ejemplo n.º 8
0
  /**
   * Returns a {@code Collection<T extends Actor>} of all {@code Actor} of the given class at the
   * given location.
   *
   * @param <T> the generic type of the class type to be returned
   * @param cls the {@code Class<T extends Actor>} of the {@code Actor} to be returned
   * @param pos the location being queried
   * @return a {@code Collection<T extends Actor>} of all {@code Actor} of the given class located
   *     at (x, y)
   */
  public final <T extends Actor> Collection<T> getActorsAt(Class<T> cls, Coordinate pos) {
    Guard.argumentIsNotNull(pos);

    return getActorsAt(cls, pos.x(), pos.y());
  }
Ejemplo n.º 9
0
 public Boolean isviewable(int x, int y) {
   Guard.argumentsInsideBounds(x, y, width, height); // �berpr�ft, ob etwas sichtbar ist
   return grid[x][y].viewable;
 }
Ejemplo n.º 10
0
  /**
   * Returns the face of the tile at the provided coordinates.
   *
   * @param coord the value of the position being queried
   * @return the face of the tile at then given {@code Coordinate}
   */
  public final ColoredChar tileAt(Coordinate coord) {
    Guard.argumentIsNotNull(coord);

    return tileAt(coord.x(), coord.y());
  }
Ejemplo n.º 11
0
  /**
   * Returns the face of the tile at the provided (x, y) coordinates.
   *
   * @param x the x value of the position being queried
   * @param y the y value of the position being queried
   * @return the face of the tile at (x, y)
   */
  public ColoredChar tileAt(int x, int y) {
    Guard.argumentsInsideBounds(x, y, width, height);

    return grid[x][y].face;
  }
Ejemplo n.º 12
0
 public void viewable(int x, int y) {
   Guard.argumentsInsideBounds(x, y, width, height); // Macht etwas sichtbar
   grid[x][y].viewable = true;
 }
Ejemplo n.º 13
0
  /**
   * Returns the count of a value given a particular {@code Categorical}.
   *
   * @param key the key to the {@code Categorical} distribution being queried
   * @param value the value whose count is being queried
   * @return the count of value given the key
   */
  public int getCountGiven(K key, V value) {
    Guard.argumentsAreNotNull(key, value);

    return frequencies.containsKey(key) ? frequencies.get(key).getCount(value) : 0;
  }
Ejemplo n.º 14
0
  /**
   * Increments the count of a value given a key.
   *
   * @param key the key of the {@code Categorical} being modified
   * @param value the value to increment
   */
  public void incrementCount(K key, V value) {
    Guard.argumentsAreNotNull(key, value);

    totals.incrementCount(value);
    getCategorical(key).incrementCount(value);
  }
Ejemplo n.º 15
0
  /**
   * Returns the sum of all values across a particular {@code Categorical}.
   *
   * @param key the key of the {@code Categorical} being queried
   * @return the sum of all values in the specified {@code Categorical}
   */
  public int sumCountGiven(K key) {
    Guard.argumentIsNotNull(key);

    return getCategorical(key).sumCounts();
  }
Ejemplo n.º 16
0
  /**
   * Returns true if the tile at the provided (x, y) coordinates is passable.
   *
   * @param x the x value of the position being queried
   * @param y the y value of the position being queried
   * @return true if the tile at (x, y)
   */
  public boolean passableAt(int x, int y) {
    Guard.argumentsInsideBounds(x, y, width, height);

    return grid[x][y].passable;
  }
Ejemplo n.º 17
0
  /**
   * Adds an {@code Actor} to the {@code World} at the specified location.
   *
   * @param actor the {@code World} being added
   * @param coord the location of the {@code Actor}
   */
  public final void addActor(Actor actor, Coordinate coord) {
    Guard.argumentIsNotNull(coord);

    addActor(actor, coord.x(), coord.y());
  }
Ejemplo n.º 18
0
  /**
   * Returns true if the tile at the provided {@code Coordinate} is passable.
   *
   * @param coord the value of the position being queried
   * @return true if the tile at the given {@code Coordinate}
   */
  public final boolean passableAt(Coordinate coord) {
    Guard.argumentIsNotNull(coord);

    return passableAt(coord.x(), coord.y());
  }
Ejemplo n.º 19
0
  /**
   * Returns every tile that is visible at a given location, ordered such that the tile with highest
   * priority (the tile returned by look) is first, and the lowest priority is last. This last tile
   * will be the face of the actual tile itself. Note that any actor which has a null face will not
   * be included.
   *
   * @param pos the location being queried
   * @return every tile that is visible at a given location
   */
  public final List<ColoredChar> lookAll(Coordinate pos) {
    Guard.argumentIsNotNull(pos);

    return lookAll(pos.x(), pos.y());
  }
Ejemplo n.º 20
0
  /**
   * Sets the face and passable value of the tile at the specified {@code Coordinate}.
   *
   * @param face the new face of the tile
   * @param passable the new passable value of the tile
   * @param coord the value of the position being updated
   */
  public final void setTile(ColoredChar face, boolean passable, Coordinate coord) {
    Guard.argumentIsNotNull(coord);

    setTile(face, passable, coord.x(), coord.y());
  }
Ejemplo n.º 21
0
  /**
   * Returns the face that should be drawn for the given location.
   *
   * @param pos the location being queried
   * @return the face that should be drawn for the given location.
   */
  public final ColoredChar look(Coordinate pos) {
    Guard.argumentIsNotNull(pos);

    return look(pos.x(), pos.y());
  }
Ejemplo n.º 22
0
  /**
   * Gets a randomly chosen open tile on the {@code World} within the given bounds. If after 100
   * randomly selected tiles are closed, then each tile will be checked and the first open tile
   * found is returned. If the entire {@code World} is closed, null is returned.
   *
   * @param dice the random number generator used to randomly select tiles
   * @param topLeft the bounds upper-left most value
   * @param bottomRight the bounds bottom-right most value
   * @return a randomly chosen open tile
   */
  public final Coordinate getOpenTile(Dice dice, Coordinate topLeft, Coordinate bottomRight) {
    Guard.argumentsAreNotNull(topLeft, bottomRight);

    return getOpenTile(dice, topLeft.x(), topLeft.y(), bottomRight.x(), bottomRight.y());
  }
Ejemplo n.º 23
0
  /**
   * Returns the probability of the specified value given a particular {@code Categorical}.
   *
   * @param key the key of the {@code Categorical} being queried
   * @param value the value being queried
   * @return the probability of value given the key
   */
  public double probabilityGiven(K key, V value) {
    Guard.verifyState(totals.sumCounts() > 0);

    return sumCountGiven(key) > 0 ? getCategorical(key).probability(value) : 0;
  }