Class Player
The entity that will be controller by user input, this functions just like
a base
Entity
but with an inventory to hold keys.- Author:
- Abdul
-
Nested Class Summary
Nested classes/interfaces inherited from class nz.ac.vuw.ecs.swen225.gp22.domain.Entity
Entity.Action, Entity.Direction
-
Field Summary
-
Constructor Summary
ConstructorDescriptionPlayer
(Maze.Point entityPos, Entity.Direction facingDir) Default constructor, sets the position and direction of the player. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addKey
(ColorableTile.Color color) Adds a key to the player's inventory.void
consumeKey
(ColorableTile.Color color) Consumes a key from the player's inventory.boolean
hasKey
(ColorableTile.Color color) Checks if the player has a key of a certain color.int
keyCount()
void
Combines methods setDir() and move().void
ping()
Non-player entities will act based on how often this is called.void
Clears all the keys that the player has.void
unping()
Undoes the effects of ping().Methods inherited from class nz.ac.vuw.ecs.swen225.gp22.domain.Entity
deleteEntity, getDir, getPos, hasAction, id, move, move, move, move, pollAction, setDir, setPos
Methods inherited from class nz.ac.vuw.ecs.swen225.gp22.domain.Observable
addObserver, removeObserver, updateObservers
-
Constructor Details
-
Player
Default constructor, sets the position and direction of the player.- Parameters:
entityPos
- Point to set the position field to.facingDir
- Direction to set the direction field to.
-
-
Method Details
-
ping
public void ping()Description copied from class:Entity
Non-player entities will act based on how often this is called. -
unping
public void unping()Description copied from class:Entity
Undoes the effects of ping(). -
moveAndTurn
Description copied from class:Entity
Combines methods setDir() and move().- Overrides:
moveAndTurn
in classEntity<Player>
- Parameters:
dir
- The new direction of the entity.
-
resetItems
public void resetItems()Clears all the keys that the player has. -
addKey
Adds a key to the player's inventory.- Parameters:
color
- Color of the key.
-
consumeKey
Consumes a key from the player's inventory.- Parameters:
color
- Color of the key.
-
hasKey
Checks if the player has a key of a certain color.- Parameters:
color
- Color of the key.- Returns:
- Whether or not the key is in the player's inventory.
-
keyCount
public int keyCount()- Returns:
- The number of keys the player has.
-
getAllKeys
- Returns:
- An immutable list of the keys collected.
-