Class CropTileComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.areas.terrain.CropTileComponent
All Implemented Interfaces:
com.badlogic.gdx.utils.Json.Serializable

public class CropTileComponent extends Component
Component which stores information about plots of land on which crops and plants can grow. Listens to a variety of trigger-able events to update state of the tile, including its water content and whether it is fertilised.
  • Field Summary

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

    enabled, entity
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new crop tile with default values
    CropTileComponent(float initialWaterContent, float soilQuality)
    Creates a new crop tile component, with a specified initial water content, and an initial soil quality (higher values indicate higher soil quality, meaning better growth rate).
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds player-triggered events listeners to the entity.
    double
    Gets the growth rate of the tile, assuming a water content value of 1 yields the maximum growth rate.
    double
    getGrowthRate(float idealWaterAmount)
    Gets the growth rate of the tile, specifying the water content of the tile which yields the maximum growth rate.
     
    float
     
    boolean
    Returns whether the tile is fertilised.
    void
    read(com.badlogic.gdx.utils.Json json, com.badlogic.gdx.utils.JsonValue jsonMap)
     
    void
    Only to be used for loading as it can go around the achievement stuff
    void
    Sets the tile to be unoccupied.
    void
    Decreases water content in the tile by a constant amount.
    void
    write(com.badlogic.gdx.utils.Json json)
    Writes in json summary of croptile state.

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

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

    Methods inherited from class java.lang.Object

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

    • CropTileComponent

      public CropTileComponent()
      Creates a new crop tile with default values
    • CropTileComponent

      public CropTileComponent(float initialWaterContent, float soilQuality)
      Creates a new crop tile component, with a specified initial water content, and an initial soil quality (higher values indicate higher soil quality, meaning better growth rate).
      Parameters:
      initialWaterContent - The initial amount of water in the crop tile. Value should be between 0 and 2 inclusive - 0 indicates tile is completely dry, and 2 indicates tile is flooded, water content of 1 leads to ideal growth rate for most plants
      soilQuality - The initial soil quality of the crop tile. Higher soil quality increases the calculated growth rate. Should be greater than 0.
  • Method Details

    • create

      public void create()
      Adds player-triggered events listeners to the entity.
      Overrides:
      create in class Component
    • update

      public void update()
      Decreases water content in the tile by a constant amount.
      Overrides:
      update in class Component
    • isFertilised

      public boolean isFertilised()
      Returns whether the tile is fertilised.
      Returns:
      True if the tile is fertilised, false otherwise.
    • getGrowthRate

      public double getGrowthRate()
      Gets the growth rate of the tile, assuming a water content value of 1 yields the maximum growth rate. The calculated growth rate is dependent on the water content and soil quality of this tile, and whether it is fertilised.
      Returns:
      The calculated growth rate of the tile with an ideal water content value of 1, which is dependent on water content, soil quality, and whether the tile has been fertilised.
    • getGrowthRate

      public double getGrowthRate(float idealWaterAmount)
      Gets the growth rate of the tile, specifying the water content of the tile which yields the maximum growth rate. The calculated growth rate is dependent on the water content and soil quality of this tile, and whether it is fertilised.
      Parameters:
      idealWaterAmount - The amount which yields the maximum growth rate.
      Returns:
      The calculated growth rate of the tile, dependent on water content, soil quality, and whether the tile has been fertilised.
    • getWaterContent

      public float getWaterContent()
    • setUnoccupied

      public void setUnoccupied()
      Sets the tile to be unoccupied.
    • getPlant

      public Entity getPlant()
    • setPlant

      public void setPlant(Entity plant)
      Only to be used for loading as it can go around the achievement stuff
      Parameters:
      plant - - the plant to set here
    • write

      public void write(com.badlogic.gdx.utils.Json json)
      Writes in json summary of croptile state. Writes to json the waterContent, soilQuality, isFertilised and plant to the json
      Specified by:
      write in interface com.badlogic.gdx.utils.Json.Serializable
      Overrides:
      write in class Component
      Parameters:
      json - which is a valid Json
    • read

      public void read(com.badlogic.gdx.utils.Json json, com.badlogic.gdx.utils.JsonValue jsonMap)
      Specified by:
      read in interface com.badlogic.gdx.utils.Json.Serializable
      Overrides:
      read in class Component