Class Human

All Implemented Interfaces:
Cloneable

class Human extends GamePiece
Represents a Human in the Game
  • Field Details

    • dx

      private int dx
      the distance, in pixels, to move in the x direction on each step
    • dy

      private int dy
      the distance, in pixels, to move in the y direction on each step
    • STEP

      private static final int STEP
      the default amount to move each step, in pixels
      See Also:
  • Constructor Details

    • Human

      public Human(int x, int y, Graphics g)
      Creates the Human at the given x and y coordinates.
      Parameters:
      x - the x-coordinate of the top-left corner of the Human
      y - the y-coordinate of the top-left corner of the Human
      g - the Graphics object used to draw the Human's image
  • Method Details

    • takeTurn

      public void takeTurn(Game game)
      Human takes turn, moving based on its current direction
      Overrides:
      takeTurn in class GamePiece
      Parameters:
      game - the game that contains this game piece (and others)
    • getChangeInX

      public int getChangeInX()
      Returns this Human's change in the x direction, in pixels
      Returns:
      the change in x, in pixels
    • getChangeInY

      public int getChangeInY()
      Returns this Human's change in the y direction, in pixels
      Returns:
      the change in y, in pixels
    • setDirection

      public void setDirection(int horizontalDirection, int verticalDirection)
      Sets which direction Human should go
      Parameters:
      horizontalDirection - -1 means left, 1 means right, 0 means no horizontal movement
      verticalDirection - -1 means up, 1 means down, 0 means no vertical movement
    • clone

      public Human clone() throws CloneNotSupportedException
      Returns a clone of this Human
      Overrides:
      clone in class GamePiece
      Throws:
      CloneNotSupportedException