Class Player

  • All Implemented Interfaces:
    Constants, java.lang.Runnable

    public class Player
    extends Object
    implements Constants
    This class contains the player
    • Field Detail

      • MAX_HEALTH

        public static final int MAX_HEALTH
        The maximum health of the player
        See Also:
        Constant Field Values
    • Method Detail

      • getInstance

        public static Player getInstance​(Scene scene,
                                         Cell cell)
        Create the Player instance
        Parameters:
        scene - The scene the player is in
        cell - The cell the player is in
        Returns:
        Returns the instance
      • deleteInstance

        public void deleteInstance()
        Delete the Player instance
      • keyPressed

        public void keyPressed​(java.awt.event.KeyEvent event)
        Handle keys being pressed in the game
        Parameters:
        event - The event from the keyboard
      • keyPressed

        public void keyPressed​(int keyCode)
        Handle keys being pressed in the game
        Parameters:
        keyCode - The key code to handle
      • moveUp

        protected boolean moveUp()
        Move the player up
        Overrides:
        moveUp in class Object
        Returns:
        Returns true if the player moved
      • moveDown

        protected boolean moveDown()
        Move the player down
        Overrides:
        moveDown in class Object
        Returns:
        Returns true if the player moved
      • moveLeft

        protected boolean moveLeft()
        Move the player to the left
        Overrides:
        moveLeft in class Object
        Returns:
        Returns true if the player moved
      • moveRight

        protected boolean moveRight()
        Move the player to the right
        Overrides:
        moveRight in class Object
        Returns:
        Returns true if the player moved
      • interact

        public void interact()
        Interact with an object in the game
      • hasKey

        public boolean hasKey()
        Checks if the player has a key
        Returns:
        Returns true if the player has a key or false if they have no keys
      • hasTaintedGem

        public boolean hasTaintedGem()
        Check if player has a tainted gem in his inventory
        Returns:
        Returns true if he has one or false otherwise
      • getGemCount

        public int getGemCount()
        Get the number of gems the player has
        Returns:
        Returns the number of gems the player has
      • attacked

        public void attacked()
        This is called when the player gets attacked
      • getHealth

        public int getHealth()
        Get the current health of the player
        Returns:
        Returns the health value
      • getAi

        public AI getAi()
        Get the AI in use by the player
        Returns:
        Returns the current AI in use
      • getInventoryGems

        public java.util.List<Gem> getInventoryGems​(boolean all)
        Get the gems the player has
        Parameters:
        all - Whether or not to return the gems that are still in transition to inventory
        Returns:
        Returns an array of the gems the player is carrying
      • loseHealth

        public void loseHealth​(int amount)
        Lose a variable amount of health
        Parameters:
        amount - The amount to lose
      • gainHealth

        public void gainHealth​(int amount)
        Gain a variable amount of health
        Parameters:
        amount - The amount of health to gain
      • run

        public void run()
        This runs when the thread starts
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class Object