Skip to content

Add 5 different actions which implement action interface

Carl Gützkow requested to merge create-actions into main

closes: #6 (closed)

What are the key features of this change

The Action interface has a method execute. This method can be called on a player to change the players attributes. Each action that implements this interface has a constructor which sets the value to modify the player with. When the execute method is called, the player receive some modification based on this value. The execute method can be called several times on the same action object.

Actions added:

  1. HealthAction: Uses the player's addHealth method to either add or subtract health.
  2. ScoreAction: Uses the player's addScore method to either add or subtract score.
  3. GoldAction: Uses the player's addGold method to either add or subtract score.
  4. InventoryAddAction: Adds a non-null and non-blank String to the players inventory. Uses the addToInventory method
  5. InventoryRemoveAllAction: Removes all instances of a specified item from the players inventory. Uses the removeInstancesFromInventory method.

Tests for all actions have been added and are seperated into two files. One for the first three which uses integer addition or subtraction and a second for the two last. Tests for the player class have also been added as methods to work for the inventory actions were needed.

A list of actions are also added to the Link class. This is passed through the constructor. More actions can be added through the addAction method. Objects inside the list of actions can not be null and is checked in the constructor and in the addAction method.

Checklist

  • Javadoc
  • Relevant tests have been created
  • Build tool test passed
  • Class version is updated where relevant
Edited by Carl Gützkow

Merge request reports