Class Monster
- All Implemented Interfaces:
InteractiveOnTurnStart
health and a certain Weapon.
A Monster is supposed to interact with the user at the beginning of each turn if the player is located in the same Room as the Monster. The interaction consists in a fight between the Player and the Monster and ends with either one of them dead. The Player can choose which Weapon in its inventory to use to attack the monster, the monster attack the player using his only weapon which is set a subset of Monster.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddecreaseHealth(int amount) Decreases the health of the Monster by a specified amount.intReturns the current health of the Monster.voidinteractOnTurnStart(CommandLogger commandLogger, Labyrinth labyrinth) Interacts with the user.protected voidmonsterAttacksPlayer(Player player) protected voidplayerAttacksMonster(CommandLogger commandLogger, Player player, Weapon playerWeapon) protected WeaponplayerChooseWeaponFromInventory(CommandLogger commandLogger, Player player) toString()Methods inherited from class org.progettoedids.entities.Entity
getName, getSystemName, getUUID, setName
-
Field Details
-
health
protected int health -
weapon
-
-
Constructor Details
-
Monster
Initializes a Monster.- Parameters:
systemName- The system name is used to uniquely identify a certain type of NPC. Must not be nullname- The name is displayed to the user and is used to identify an instance of an NPC by the user. Must not be nullhealth- The initial amount of health of the Monster. Must be positiveweapon- The weapon the Monster will use. Must not be null- Throws:
IllegalArgumentException- if the health is not positive
-
-
Method Details
-
getHealth
public int getHealth()Returns the current health of the Monster.- Returns:
- an integer representing the health
-
decreaseHealth
public void decreaseHealth(int amount) Decreases the health of the Monster by a specified amount.- Parameters:
amount- The amount of health to remove from the monster. Must be positive or zero
-
toString
-
interactOnTurnStart
public void interactOnTurnStart(CommandLogger commandLogger, Labyrinth labyrinth) throws GameOverException Interacts with the user. The Monster fights the Player until one of them dies.A fight consists of the Player and the Monster interleaving attacks on each other one at a time. The Player is asked to choose which of the weapon it helds in its inventory to use. The Monster weapon isn't affected by its durability. The Player weapon instead decreases his durability by one at each attack. If a Player's weapon gets worn out completely the user is prompted to choose a new Weapon. If the Player doesn't have any Weapon to fight the Monster he dies automatically.
- Parameters:
commandLogger- the CommandLogger onto which the user typed commands are saved. Must not be nulllabyrinth- the Labyrinth on which the interaction actions are performed. Must not be null- Throws:
GameOverException- if the Player dies during the interaction
-
playerChooseWeaponFromInventory
protected Weapon playerChooseWeaponFromInventory(CommandLogger commandLogger, Player player) throws GameOverException - Throws:
GameOverException
-
monsterAttacksPlayer
- Throws:
GameOverException
-
playerAttacksMonster
protected void playerAttacksMonster(CommandLogger commandLogger, Player player, Weapon playerWeapon) throws GameOverException - Throws:
GameOverException
-