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 TypeFieldDescriptionprotected final int
ID - set as final, as may not change after building the knightprotected int
keeps track of experience points. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addXP
(int xp) Adds a whole number to the knights current experience point valueGets the active fortune currently being applied to the knight.int
getArmor()
Gets the armor value of the knight.Gets the damageDie value of the knight.int
Gets the hit modifier value of the knight.getId()
Gets the knights id as an Integer (not int).int
getMaxHP()
Gets the maxHP value of the knight.int
getXP()
Returns the knights experience points.void
setActiveFortune
(Fortune activeFortune) Sets the active fortune.toCSV()
Returns a Comma Seperated value representation of the knight.toString()
The toString for the knight, returns a 'knight card' examples of the card as as follows:
-
Field Details
-
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:
getArmor
in interfaceAttributes
- Overrides:
getArmor
in 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:
getMaxHP
in interfaceAttributes
- Overrides:
getMaxHP
in 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:
getDamageDie
in interfaceAttributes
- Overrides:
getDamageDie
in 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:
getHitModifier
in interfaceAttributes
- Overrides:
getHitModifier
in 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 | | | +============================+
The split for the spacing is:- 30 characters wide
- Name uses %-27s
- id uses %-23d (as a space is required between id: and the value
- health, Power - both %-6d
- XP %-7d
- Armor: %-4d
-
toCSV
Returns a Comma Seperated 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
-