Class Knight

Object
MOB
Knight
All Implemented Interfaces:
Attributes

public class Knight extends MOB
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 Details

    • xp

      protected int xp
      keeps track of experience points. May be set on load
    • id

      protected final int id
      ID - set as final, as may not change after building the knight
  • Constructor Details

    • Knight

      public Knight(int id, String name, int hp, int armor, int hitmodifier, DiceType damageDie, int xp)
      Basic constructor for the knight object
      Parameters:
      id - the ID - should be unique across all knights
      name - the name of the knight
      hp - the max hitpoints of the knight
      armor - the armor value of the knight
      hitmodifier - the hit modifier of the knight
      damageDie - 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 interface Attributes
      Overrides:
      getArmor in class MOB
      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 interface Attributes
      Overrides:
      getMaxHP in class MOB
      Returns:
      the maxHP value of the knight, possibly with a fortune bonus
      See Also:
    • getDamageDie

      public DiceType 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 interface Attributes
      Overrides:
      getDamageDie in class MOB
      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 interface Attributes
      Overrides:
      getHitModifier in class MOB
      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

      public Fortune getActiveFortune()
      Gets the active fortune currently being applied to the knight.
      Returns:
      the activeFortune currently being applied to the knight.
    • setActiveFortune

      public void setActiveFortune(Fortune activeFortune)
      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

      public Integer 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

      public String 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
      Overrides:
      toString in class MOB
      Returns:
      A formatted knight card
    • toCSV

      public String toCSV()
      Returns a Comma Seperated value representation of the knight. The order is as follows

      name,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