package cse1030; /** * A class for representing monsters in a game. A monster has an amount of life * represented by an integer value. The amount of life is determined by the * current value of a toughness range. As new monsters are created, the current * value of the toughness range increases. The maximum value of the toughness * range can never exceed a maximum life value that is determined by the class. * * @author CSE1030Z * */ public class Monster { private static int MAX_LIFE = 50; private static Range toughness = new Range(20, MAX_LIFE, 20); private int life; /** * Create a monster. Each new monster created will cause the starting life of * the next monster to increase by 1, up to the maximum of the current * toughness range. */ public Monster() { this.life = Monster.toughness.getValue(); Monster.toughness.setValue(this.life + 1); } /** * Return the amount of life that the monster has. * * @return the amount of life that the monster has */ public int getLife() { return this.life; } /** * Return the current toughness range for monsters. Clients cannot change the * toughness range for monsters using this method. * * @return the current toughness range for monsters */ public static Range getToughness() { return new Range(toughness.getMinimum(), toughness.getMaximum(), toughness.getValue()); } /** * Set the toughness range for monsters. * *

* There is a maximum monster life value set by the class. If * t.getMaximum() is greater than the class determined maximum * life value, the stored toughness range will not exceed this maximum value. * * @param t * the new toughness for monsters */ public static void setToughness(Range t) { Monster.toughness = new Range(t.getMinimum(), t.getMaximum(), t.getValue()); if (Monster.toughness.getMaximum() > Monster.MAX_LIFE) { Monster.toughness.setMaximum(Monster.MAX_LIFE); } } }