Effects - UQcsse3200/2024-studio-2 GitHub Wiki

Introduction The AbstractEffect interface defines the contract for all effects that can be applied by items in the game, such as potions. Implementing this interface allows developers to create various effects that can be applied to game entities, including healing, damage buffs, and more. This modular design ensure that effects can be reused and combined across different items and game scenarios.

Expected Behaviour

  • Effect Application: Any class implementing the AbstractEffect interface must provide an apply() method, which encapsulates the logic for applying the effect.
  • **Description: ** Implementing classes must also provide a getDescription() method, which returns a human-readable description of the effect. This can be useful for debugging, logging, or displaying information to the player.

Example Implementations HealEffect A concrete implementation of 'Effect' that heals a player or entity by a specified amount:

public class HealEffect implements AbstractEffect {

    private int healingAmount;

    public HealEffect(int healingAmount) {
        this.healingAmount = healingAmount;
    }

    @Override
    public void apply() {
        // Insert Healing Logic Here
        System.out.println("Player healed by " + healingAmount + " points.");
    }
    @Override
    public String getDescription() {
        return "Heals the player by " + healingAmount + " points.";
    }
}

Integration

  • Creating New Effects: To add a new effect, simply implement the AbstractEffect interface and define the logic within the apply() method. Add a corresponding getDescription() method to provide a brief summary of the effect.
  • **Combining Effects: ** Multiple effects can be combined in items like potions by adding instances of different AbstractEffect implementations to the possibleEffects list.

Key Points

  • **Modularity: ** The AbstractEffect interface promotes modular design, allowing effects to be easily created, reused, and combined.
  • Extendibility: New effects can be created by implementing the AbstractEffect interface, offering great flexibility in defining item behaviors.
  • **Documentation: ** The getDescription() method ensures that each effect can provide useful information for both developers and players.

Subclasses

The following subclasses that inherit from Effects are: