Class InventoryComponent

java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.components.player.InventoryComponent

public class InventoryComponent
extends Component
A component intended to be used by the player to track their inventory. Currently only stores the gold amount but can be extended for more advanced functionality such as storing items. Can also be used as a more generic component for other entities.
  • Field Summary

    Fields inherited from class com.deco2800.game.components.Component

    enabled, entity
  • Constructor Summary

    Constructors 
    Constructor Description
    InventoryComponent​(int gold)  
  • Method Summary

    Modifier and Type Method Description
    void addGold​(int gold)
    Adds to the player's gold.
    void addToGold​(int amount)
    Add to the player's existing gold
    void create()
    Called when the entity is created and registered.
    int getGold()
    Returns the player's gold.
    java.lang.Boolean hasGold​(int gold)
    Returns if the player has a certain amount of gold.
    void setGold​(int gold)
    Sets the player's gold.

    Methods inherited from class com.deco2800.game.components.Component

    dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

  • Method Details

    • create

      public void create()
      Description copied from class: Component
      Called when the entity is created and registered. Initial logic such as calls to GetComponent should be made here, not in the constructor which is called before an entity is finished.
      Overrides:
      create in class Component
    • getGold

      public int getGold()
      Returns the player's gold.
      Returns:
      entity's health
    • hasGold

      public java.lang.Boolean hasGold​(int gold)
      Returns if the player has a certain amount of gold.
      Parameters:
      gold - required amount of gold
      Returns:
      player has greater than or equal to the required amount of gold
    • setGold

      public void setGold​(int gold)
      Sets the player's gold. Gold has a minimum bound of 0.
      Parameters:
      gold - gold
    • addToGold

      public void addToGold​(int amount)
      Add to the player's existing gold
      Parameters:
      amount - gold to be added
    • addGold

      public void addGold​(int gold)
      Adds to the player's gold. The amount added can be negative.
      Parameters:
      gold - gold to add