Add 5 different actions which implement action interface
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:
- HealthAction: Uses the player's addHealth method to either add or subtract health.
- ScoreAction: Uses the player's addScore method to either add or subtract score.
- GoldAction: Uses the player's addGold method to either add or subtract score.
- InventoryAddAction: Adds a non-null and non-blank String to the players inventory. Uses the addToInventory method
- 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