Package com.deco2800.game.memento
Class Originator
java.lang.Object
com.deco2800.game.memento.Originator
Part of the memento design pattern, originator is the object to store the
states of the player, this includes the
player's inventory states (e.g. amount of gold, type of sword, items in
inventory, health and base attack value
Can be extended to save states for other entities in the future or use as
checkpoints for player to respawn
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Equipmentsprotected intprotected HashMap<ShopBuilding,Integer> protected intprotected intprotected List<Equipments>protected intprotected intprotected intprotected Equipmentsprotected int -
Constructor Summary
ConstructorsConstructorDescriptionOriginator(int state) Originator constructor which can create a new originator to store the current state of the player before entering and exiting the shop -
Method Summary
Modifier and TypeMethodDescriptiongetArmor()returns the armor enum of the previously saved recordintreturns the attack value of the playerretrieve the list of previously bought buildingsintreturns the current health of the playerintreturns the defense multiplierretrieves all the previously bought equipmentintgetGold()retrieve the gold status for playerretrieve the list of items in player's inventory, may be extended to different lists depending on types of itemintgetState()voidgetStateFromMemento(Memento memento) returns the states of the player from the specified mementointgetStone()retrieve the stone status for playerreturns the weapon enum of the previously saved recordintgetWood()retrieve the wood status for playerconverts the originator object to a memento to store in the caretakervoidsetArmor(Equipments armor) sets the armor enumvoidsetAttack(int attack) saves the attack value for the player, this includes the boost for player from different weapons bought in the shopvoidsetBuildings(HashMap<ShopBuilding, Integer> buildings) record the list of buildings in the inventoryvoidsetCurrentHealth(int health) saves the current health of the playervoidsetDefense(int defense) sets the defense multipliervoidsetEquipmentsList(List<Equipments> equipmentsList) record the list of equipment in the inventoryvoidsetGold(int gold) saves the amount of gold that the player currently havevoidstores the current state of player's inventory itemsvoidsetStone(int stone) saves the amount of stone that the player currently havevoidsetWeapon(Equipments weapon) sets the weapon enumvoidsetWood(int wood) saves the amount of gold that the player currently havetoString()
-
Field Details
-
state
protected int state -
gold
protected int gold -
stone
protected int stone -
wood
protected int wood -
currentHealth
protected int currentHealth -
attack
protected int attack -
defense
protected int defense -
weapon
-
armor
-
items
-
buildings
-
equipmentsList
-
-
Constructor Details
-
Originator
public Originator(int state) Originator constructor which can create a new originator to store the current state of the player before entering and exiting the shop- Parameters:
state- - the id of the current player state
-
-
Method Details
-
getState
public int getState() -
getWeapon
returns the weapon enum of the previously saved record- Returns:
- weapon enum
-
getArmor
returns the armor enum of the previously saved record- Returns:
- armor enum
-
setWeapon
sets the weapon enum- Parameters:
weapon- - weapon to be stored
-
setArmor
sets the armor enum- Parameters:
armor- - chestplate to be stored
-
getGold
public int getGold()retrieve the gold status for player- Returns:
- amount of gold currently held by the player
-
setGold
public void setGold(int gold) saves the amount of gold that the player currently have- Parameters:
gold- - amount of gold that the player current holds
-
setWood
public void setWood(int wood) saves the amount of gold that the player currently have- Parameters:
wood- - amount of gold that the player current holds
-
getStone
public int getStone()retrieve the stone status for player- Returns:
- amount of stone currently held by the player
-
getWood
public int getWood()retrieve the wood status for player- Returns:
- amount of wood currently held by the player
-
setStone
public void setStone(int stone) saves the amount of stone that the player currently have- Parameters:
stone- - amount of stone that the player current holds
-
setAttack
public void setAttack(int attack) saves the attack value for the player, this includes the boost for player from different weapons bought in the shop- Parameters:
attack- - attack value for player
-
getAttack
public int getAttack()returns the attack value of the player- Returns:
- - basee attack value of player
-
setDefense
public void setDefense(int defense) sets the defense multiplier- Parameters:
defense- - defense multiplier value
-
getDefense
public int getDefense()returns the defense multiplier -
getCurrentHealth
public int getCurrentHealth()returns the current health of the player- Returns:
- - current health of the player
-
setCurrentHealth
public void setCurrentHealth(int health) saves the current health of the player- Parameters:
health- - player health
-
getItemList
retrieve the list of items in player's inventory, may be extended to different lists depending on types of item- Returns:
- - the list of artefacts items in player's inventory
-
setItems
stores the current state of player's inventory items- Parameters:
items- - list of artefacts items in player's inventory
-
getEquipmentsList
retrieves all the previously bought equipment- Returns:
- list of equipments
-
setEquipmentsList
record the list of equipment in the inventory- Parameters:
equipmentsList-
-
setBuildings
record the list of buildings in the inventory- Parameters:
buildings-
-
getBuildings
retrieve the list of previously bought buildings- Returns:
- hashmap of buildings
-
saveStateToMemento
converts the originator object to a memento to store in the caretaker- Returns:
- - the new memento generated from the current originator
-
getStateFromMemento
returns the states of the player from the specified memento- Parameters:
memento- - the memento of the previous player state to read from
-
toString
-