Package cs2110

Class Player

java.lang.Object
cs2110.Player
All Implemented Interfaces:
Actor

public class Player extends Object implements Actor
A player in our game simulation that accepts console input on each turn to determine which monster to attack.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The starting health level of a monster.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Player(String name, String species, GameEngine engine)
    Constructs a new player with the given `name` and `species` and initializes its health and power levels.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    attack(Actor target)
    Launches an attack against the given `target`.
    boolean
    defend(int atk)
    Responds to an attack with the given `atk` roll.
    int
    Returns the current health level for this Actor.
    Returns the name of this Actor.
    int
    Returns the base power level for this Actor.
    Returns the species of this player.
    void
    Queries the user for which living monster they'd like to attack and then launches an attack against that monster.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • STARTING_HEALTH

      public static final int STARTING_HEALTH
      The starting health level of a monster.
      See Also:
  • Constructor Details

    • Player

      public Player(String name, String species, GameEngine engine)
      Constructs a new player with the given `name` and `species` and initializes its health and power levels.
  • Method Details

    • takeTurn

      public void takeTurn()
      Queries the user for which living monster they'd like to attack and then launches an attack against that monster.
      Specified by:
      takeTurn in interface Actor
    • attack

      public void attack(Actor target)
      Description copied from interface: Actor
      Launches an attack against the given `target`.
      Specified by:
      attack in interface Actor
    • defend

      public boolean defend(int atk)
      Description copied from interface: Actor
      Responds to an attack with the given `atk` roll. Returns `true` if the defense succeeded, false otherwise.
      Specified by:
      defend in interface Actor
    • name

      public String name()
      Description copied from interface: Actor
      Returns the name of this Actor.
      Specified by:
      name in interface Actor
    • species

      public String species()
      Returns the species of this player.
    • health

      public int health()
      Description copied from interface: Actor
      Returns the current health level for this Actor.
      Specified by:
      health in interface Actor
    • power

      public int power()
      Description copied from interface: Actor
      Returns the base power level for this Actor.
      Specified by:
      power in interface Actor