Difference between revisions of "Creature class assignment"

From WLCS
(New page: === Purpose === * The purpose of this class is to '''encapsulate''' all the attributes and methods of a single Creature object === Attributes === The Creature class should use variables ...)
 
Line 22: Line 22:
  
 
=== Methods ===
 
=== Methods ===
 +
The Creature class should have the following methods:
 +
 +
'''Constructors:'''
 +
Creature(): the default constructor should initialize hit points to 50, strength to 15, skill to 15, armor class to 5, name to "Somebody", type to "nondescript creature", pronoun to "its", and weapon to a new Weapon created with the Weapon() default constructor.
 +
 +
Creature(int hp, int str, int skl, int ac, String name, String type, String pronoun): a specific constructor that lets the programmer specify all the attributes of a creature except the weapon, which is still set a new Weapon object created with the Weapon() default constructor.
 +
 +
'''Accessors/Mutators:'''
 +
* All the attributes are declared private, so you should create accessor and mutator methods for each attribute.  The name of the accessor/mutator should follow the standard Java naming conventions (i.e. getHitPoints(), setDamageModifier(), getName(), etc.).
 +
 +
'''Other methods:'''
 +
* boolean isAlive(): returns true if the creature is alive (that is, if its hit points are greater than zero) and false otherwise.
 +
 +
* boolean tryToAttack(int targetAC): uses the Random class (see below) to get a random number between 0 and skill, where skill is the skill of the creature.  Returns true if the resulting random number is greater than or equal to the targetAC parameter (which represents the opponent's armor class) and false otherwise.
 +
 +
* int calcHitDamage(): computes the damage done if the creature scores a hit.  This is a function of the creature's strength, adjusted to account for the weapon being wielded (i.e. a sword does more damage than bare hands). Generates a random number between zero and strength (where strength is the strength of the creature) and adjusts it by adding the damage modifier of the weapon being wielded, then returns this adjusted number.
 +
 +
* void takeDamage(int amount): decrements the creature's hit points by amount.
 +
 +
* String constructHitString(Creature opponent): returns a string of the form: "<name> the <type> <weapon hit verb> <opponent name> the <opponent type> with <pronoun> <weapon name>".  For example, "Frodo the hobbit slashes Aaron Bloomfield the mighty warrior with his sword".
 +
 +
* String constructMissString(Creature opponent): like constructHitString() but using the weapon's miss verb.  For example, "Gnash the orc misses Frodo the hobbit with its spear".

Revision as of 09:54, 21 April 2010

Purpose

  • The purpose of this class is to encapsulate all the attributes and methods of a single Creature object

Attributes

The Creature class should use variables to represent the following attributes:

  • hit points (int): the amount of damage a creature can take before it dies. A creature's hit points are reduced when an opponent scores a hit: when the warrior successfully attacks the monster, it decreases the monster's hit points, and if the monster takes a bite out of the warrior, the warrior's hit points go down. If hit points reach or drops below zero, the creature dies.
  • strength (int): the maximum damage a creature can inflict. The strength represents the maximum number of hit points that will be deducted from the opponent if the creature scores a hit.
  • skill (int): the likelihood of a creature scoring a hit. This is an integer between 0 and 25. The higher the skill, the more likely the creature is to score a hit.
  • armor class (int): the armor class or AC of a creature represents how hard it is to damage. It is an integer between 0 and 20. The higher the AC, the less likely an opponent is to score a hit.
  • name (String): the name of the creature (e.g., "Frodo" or "Aaron Bloomfield").
  • type (String): a word or phrase describing the race or class of the creature (e.g., "hobbit" or "mighty warrior").
  • pronoun (String): the appropriate possessive pronoun to use for this creature (e.g., "his", "her", "its").
  • weapon (Weapon): a reference to the Weapon object wielded by the creature.

Methods

The Creature class should have the following methods:

Constructors: Creature(): the default constructor should initialize hit points to 50, strength to 15, skill to 15, armor class to 5, name to "Somebody", type to "nondescript creature", pronoun to "its", and weapon to a new Weapon created with the Weapon() default constructor.

Creature(int hp, int str, int skl, int ac, String name, String type, String pronoun): a specific constructor that lets the programmer specify all the attributes of a creature except the weapon, which is still set a new Weapon object created with the Weapon() default constructor.

Accessors/Mutators:

  • All the attributes are declared private, so you should create accessor and mutator methods for each attribute. The name of the accessor/mutator should follow the standard Java naming conventions (i.e. getHitPoints(), setDamageModifier(), getName(), etc.).

Other methods:

  • boolean isAlive(): returns true if the creature is alive (that is, if its hit points are greater than zero) and false otherwise.
  • boolean tryToAttack(int targetAC): uses the Random class (see below) to get a random number between 0 and skill, where skill is the skill of the creature. Returns true if the resulting random number is greater than or equal to the targetAC parameter (which represents the opponent's armor class) and false otherwise.
  • int calcHitDamage(): computes the damage done if the creature scores a hit. This is a function of the creature's strength, adjusted to account for the weapon being wielded (i.e. a sword does more damage than bare hands). Generates a random number between zero and strength (where strength is the strength of the creature) and adjusts it by adding the damage modifier of the weapon being wielded, then returns this adjusted number.
  • void takeDamage(int amount): decrements the creature's hit points by amount.
  • String constructHitString(Creature opponent): returns a string of the form: "<name> the <type> <weapon hit verb> <opponent name> the <opponent type> with <pronoun> <weapon name>". For example, "Frodo the hobbit slashes Aaron Bloomfield the mighty warrior with his sword".
  • String constructMissString(Creature opponent): like constructHitString() but using the weapon's miss verb. For example, "Gnash the orc misses Frodo the hobbit with its spear".