Class Knight
- All Implemented Interfaces:
Attributes
A knight is the primary protagonist of the game. It contains stats/attributes, experience points,
and a fortune that can adjust the attributes. Additional, knights are assigned an ID, to help
separate one from another.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate FortuneStores the active fortune **if** one exists (else null)protected final intID - set as final, as may not change after building the knightprotected intkeeps track of experience points. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddXP(int xp) Adds a whole number to the knights current experience point valueGets the active fortune currently being applied to the knight.intgetArmor()Gets the armor value of the knight.Gets the damageDie value of the knight.intGets the hit modifier value of the knight.getId()Gets the knights id as an Integer (not int).intgetMaxHP()Gets the maxHP value of the knight.intgetXP()Returns the knights experience points.voidsetActiveFortune(Fortune activeFortune) Sets the active fortune.toCSV()Returns a Comma Separated value representation of the knight.toString()The toString for the knight, returns a 'knight card' examples of the card as as follows:
-
Field Details
-
activeFortune
Stores the active fortune **if** one exists (else null) -
xp
protected int xpkeeps track of experience points. May be set on load -
id
protected final int idID - set as final, as may not change after building the knight
-
-
Constructor Details
-
Knight
Basic constructor for the knight object- Parameters:
id- the ID - should be unique across all knightsname- the name of the knighthp- the max hitpoints of the knightarmor- the armor value of the knighthitmodifier- the hit modifier of the knightdamageDie- the damage dice they use on a successful hit.xp- the xp for the knight
-
-
Method Details
-
getArmor
public int getArmor()Gets the armor value of the knight. If an activeFortune is in affect, it is the armor bonus from the active fortune + the armor of the knight - else it is just the knights armor Students: hint, use super.getArmor() to get the value stored in armor. Also, if the getActiveFortune() is null, then you know there isn't one.- Specified by:
getArmorin interfaceAttributes- Overrides:
getArmorin classMOB- Returns:
- the armor value of the knight, possibly with a fortune bonus
- See Also:
-
getMaxHP
public int getMaxHP()Gets the maxHP value of the knight. If an activeFortune is in affect, it is the maxHP bonus from the active fortune + the maxHP of the knight - else it is just the knights maxHP Students: hint, use super.getMaxHP() to get the value stored in maxHP.- Specified by:
getMaxHPin interfaceAttributes- Overrides:
getMaxHPin classMOB- Returns:
- the maxHP value of the knight, possibly with a fortune bonus
- See Also:
-
getDamageDie
Gets the damageDie value of the knight. If an active fortune is in place, returns the value from the active fortune (damage die boosts replace the other damage die)- Specified by:
getDamageDiein interfaceAttributes- Overrides:
getDamageDiein classMOB- Returns:
- the damage die of the knight or the active fortune damage die
- See Also:
-
getHitModifier
public int getHitModifier()Gets the hit modifier value of the knight. If an activeFortune is in affect, it is the hit modifier bonus from the active fortune + the hit modifier of the knight - else it is just the knights hit modifier Students: hint, use super.getHitModifier() to get the value stored in hitModifier.- Specified by:
getHitModifierin interfaceAttributes- Overrides:
getHitModifierin classMOB- Returns:
- the hitModifier value of the knight, possibly with a fortune bonus
- See Also:
-
getXP
public int getXP()Returns the knights experience points.- Returns:
- the experience points as a whole number.
-
getActiveFortune
Gets the active fortune currently being applied to the knight.- Returns:
- the activeFortune currently being applied to the knight.
-
setActiveFortune
Sets the active fortune.- Parameters:
activeFortune- the fortune to set to the knight.
-
addXP
public void addXP(int xp) Adds a whole number to the knights current experience point value- Parameters:
xp- the amount to add- See Also:
-
getId
Gets the knights id as an Integer (not int). Integer is used, as toString is often used in other parts other program.- Returns:
- the Integer value of the id.
-
toString
The toString for the knight, returns a 'knight card' examples of the card as as follows:+============================+ | Morgawse | | id: 11 | | | | Health: 35 XP: 0 | | Power: D8 Armor: 14 | | | +============================+ +============================+ | Danu of Ireland | | id: 4 | | | | Health: 40 XP: 0 | | Power: D6 Armor: 16 | | | +============================+ +============================+ | Arthur | | id: 12 | | | | Health: 40 XP: 0 | | Power: D8 Armor: 16 | | | +============================+
For this assignment we use the following formatreturn "+============================+\n" + String.format("| %-27s|%n", getName()) + String.format("| id: %-23d|%n", getId()) + "| |\n" + String.format("| Health: %-6d XP: %-7d|%n", getHP(), getXP()) + String.format("| Power: %-6s Armor: %-4d|%n", getDamageDie().toString(), getArmor()) + "| |\n" + "+============================+"; -
toCSV
Returns a Comma Separated value representation of the knight. The order is as followsname,maxHP,armor,hitmodifer,damageDie,xp
for example, arthur, who has won zero battles, would return:
Arthur,40,16,2,D8,0
This is used when writing out the file to save.- Returns:
- a CSV representation of the object
-