Class Human
java.lang.Object
GamePiece
Human
- All Implemented Interfaces:
Cloneable
Represents a Human in the Game
-
Field Summary
Modifier and TypeFieldDescriptionprivate int
the distance, in pixels, to move in the x direction on each stepprivate int
the distance, in pixels, to move in the y direction on each stepprivate static final int
the default amount to move each step, in pixels -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclone()
Returns a clone of this Humanint
Returns this Human's change in the x direction, in pixelsint
Returns this Human's change in the y direction, in pixelsvoid
setDirection
(int horizontalDirection, int verticalDirection) Sets which direction Human should govoid
Human takes turn, moving based on its current directionMethods inherited from class GamePiece
draw, getCharacterWidth, getImageWidth, getXPos, getYPos
-
Field Details
-
dx
private int dxthe distance, in pixels, to move in the x direction on each step -
dy
private int dythe distance, in pixels, to move in the y direction on each step -
STEP
private static final int STEPthe default amount to move each step, in pixels- See Also:
-
-
Constructor Details
-
Human
Creates the Human at the given x and y coordinates.- Parameters:
x
- the x-coordinate of the top-left corner of the Humany
- the y-coordinate of the top-left corner of the Humang
- the Graphics object used to draw the Human's image
-
-
Method Details
-
takeTurn
Human takes turn, moving based on its current direction -
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 movementverticalDirection
- -1 means up, 1 means down, 0 means no vertical movement
-
clone
Returns a clone of this Human- Overrides:
clone
in classGamePiece
- Throws:
CloneNotSupportedException
-