示例#1
0
 /**
  * Initialize this new Food with given x-coordinate, y-coordinate and world.
  *
  * @param world The world this food is placed in.
  * @param xCoordinate The x-coordinate for this new food.
  * @param yCoordinate The y-coordinate for this new food.
  * @post | new.getWorld() == world
  * @post | new.getXCoordinate() == xCoordinate
  * @post | new.getYCoordinate() == yCoordinate
  * @post | new.getActive() == true
  */
 @Raw
 public Food(World world, double xCoordinate, double yCoordinate) {
   setWorld(world);
   setXCoordinate(xCoordinate);
   setYCoordinate(yCoordinate);
   setActive(true);
 }
示例#2
0
 /**
  * Remove the given food from the set of food rations attached to this world.
  *
  * @param food The food to be removed
  * @post | !new.hasAsFood(food)
  * @post | if (hasAsFood(food)) | ((new food).getWorld() == null)
  * @throws IllegalArgumentException() | !hasAsFood(food)
  */
 public void removeAsFood(Food food) throws IllegalArgumentException {
   if (!hasAsFood(food)) throw new IllegalArgumentException();
   this.foodRations.remove(food);
   food.setWorld(null);
 }
示例#3
0
 /**
  * Add the given food to the set of food rations attached to this world.
  *
  * @param food The food to be added.
  * @post | new.hasAsFood(food)
  * @post | (new food).getWorld() == this
  * @throws IllegalArgumentException("You can't add this food.") | !canHaveAsFood(food)
  * @throws IllegalArgumentException("You can't add this food.") | ( (food != null) | &&
  *     (food.getWorld() != null) )
  */
 public void addAsFood(Food food) throws IllegalArgumentException {
   if (!canHaveAsFood(food)) throw new IllegalArgumentException("You can't add this food.");
   if (food.getWorld() != null) throw new IllegalArgumentException("You can't add this food.");
   this.foodRations.add(food);
   food.setWorld(this);
 }