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 Equipments
protected int
protected HashMap<ShopBuilding,
Integer> protected int
protected int
protected List<Equipments>
protected int
protected int
protected int
protected Equipments
protected 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 recordint
returns the attack value of the playerretrieve the list of previously bought buildingsint
returns the current health of the playerint
returns the defense multiplierretrieves all the previously bought equipmentint
getGold()
retrieve the gold status for playerretrieve the list of items in player's inventory, may be extended to different lists depending on types of itemint
getState()
void
getStateFromMemento
(Memento memento) returns the states of the player from the specified mementoint
getStone()
retrieve the stone status for playerreturns the weapon enum of the previously saved recordint
getWood()
retrieve the wood status for playerconverts the originator object to a memento to store in the caretakervoid
setArmor
(Equipments armor) sets the armor enumvoid
setAttack
(int attack) saves the attack value for the player, this includes the boost for player from different weapons bought in the shopvoid
setBuildings
(HashMap<ShopBuilding, Integer> buildings) record the list of buildings in the inventoryvoid
setCurrentHealth
(int health) saves the current health of the playervoid
setDefense
(int defense) sets the defense multipliervoid
setEquipmentsList
(List<Equipments> equipmentsList) record the list of equipment in the inventoryvoid
setGold
(int gold) saves the amount of gold that the player currently havevoid
stores the current state of player's inventory itemsvoid
setStone
(int stone) saves the amount of stone that the player currently havevoid
setWeapon
(Equipments weapon) sets the weapon enumvoid
setWood
(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
-