Skip to content

Plant Component

abhat0 edited this page Oct 3, 2023 · 13 revisions

Welcome to the documentation page for the PlantComponent.java file for the project. This file is a core component of our game's plant system, responsible for managing various aspects of plants within the game.

Table of Contents

  • Introduction
  • Class Overview
  • Usage
  • Attributes and Methods

Introduction

The PlantComponent.java file is a fundamental building block of our game's plant mechanics. It encapsulates the essential functionalities and properties of individual plants, including health, age, growth stages, and more. By utilizing this class, we create a flexible and organized structure for managing diverse plant types within the game.

Class Overview

The PlantComponent class is derived from the base Component class, which is a common pattern in our game's entity framework. This class serves as the backbone for all plant-related operations and data management. It encompasses attributes that define the plant's health, type, age, and growth stages, among others. This is instantiated in PlantFactory using plant.json for the corresponding stats as arguments.

Usage

To incorporate the PlantComponent class into your game's plant system, follow these steps:

1. Import the necessary classes

import com.csse3200.game.components.plants.PlantComponent;

2. Instantiate the PlantComponent class and configure it with relevant parameters

PlantComponent plant = new PlantComponent(health, name, plantType, plantDescription,
                                          idealWaterLevel, adultLifeSpan, maxHealth,
                                          cropTile, growthStageThresholds, soundsArray);

3. Utilize the various methods provided by the PlantComponent class

Attributes and Methods

The PlantComponent class includes the following attributes and methods:

  • plantHealth: The current health of the plant.
  • maxHealth: The maximum health the plant can reach.
  • plantName: The user-facing name of the plant.
  • plantType: The type of the plant (e.g., food, health, defense).
  • plantDescription: A user-facing description of the plant.
  • decay: A boolean indicating whether the plant is decaying.
  • idealWaterLevel: The ideal water level for the plant's growth.
  • currentAge: The current age of the plant.
  • growthStages: enum defining the different growth stages.
  • growthStage: The current growth stage of the plant.
  • adultLifeSpan: The duration a crop plant lives before starting to decay from old age.
  • currentGrowthLevel: Used to determine when a plant enters a new growth stage (e.g from seedling to sprout)
  • cropTile: The associated CropTileComponent where the plant is planted.
  • growthstageThresholds: An array containing growth thresholds for different growth stages (e.g., Sprout, Juvenile, Adult).
  • sounds: An array holding the paths to sounds associated with the plant
  • currentMaxHealth: The current maximum health, limiting the plant's health at different growth stages.
  • maxHealthAtStages: An array specifying the maximum health a plant can have at different growth stages.
  • currentAnimator: The animation component for the plant, used to represent the plant at different growth stages.
  • animationImages: The name of the animations for each growth stage.
  • harvestYields: The yield to be dropped when this plant is harvested.
  • adultEffect: The special effect a plant has when it reaches the adult growth stage.
  • isEating: A bool indicating whether the plant is currently eating (only applies when the plant is a Space Snapper).
  • eatingCooldown: Constant used to control how long the plant (Space Snapper) waits before being able to eat again.
  • countMinutesOfDigestion: Count of minutes since the plant (Space Snapper) ate.
  • playerInProximity: Indicates whether the player is in close enough proximity for the plant to make audible sounds.
  • numOfDaysAsAdult: Used to track the number of days a plant has been in the adult stage.

For a complete list of methods and their descriptions, refer to the source code or javadoc of PlantComponent.java.

PlantComponent Test Plan

  • Test all getters and setters
  • Test methods for increasing (or decreasing) plant health
  • Test methods for changing growth level

image

Clone this wiki locally