Class GamePiece
java.lang.Object
GamePiece
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
Human
The base class for GamePieces that are displayed on the game panel.
-
Field Summary
Modifier and TypeFieldDescriptionprivate Graphics
protected int
size of the character inside the imageprotected Image
animated gif of the game piece, to be displayed on the Game boardprotected int
size of the imageprotected static String
Location of the image files.protected int
coordinate of top-left corner of the GamePieceprotected int
coordinate of top-left corner of the GamePiece -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclone()
Returns a clone of this GamePiecevoid
draw()
Draws the GamePiece on the canvasint
Returns the width of the game piece's character (not necessarily the same as the image's width).int
Returns the width of this game piece's imageint
getXPos()
Returns the game piece's x coordinateint
getYPos()
Returns the game piece's y coordinatevoid
The GamePiece takes its turn (nothing for this class)
-
Field Details
-
img
animated gif of the game piece, to be displayed on the Game board -
xcoord
protected int xcoordcoordinate of top-left corner of the GamePiece -
ycoord
protected int ycoordcoordinate of top-left corner of the GamePiece -
img_width
protected int img_widthsize of the image -
char_width
protected int char_widthsize of the character inside the image -
brush
-
imgDir
Location of the image files. When using Eclipse, use bin/. Without Eclipse structure, use ./
-
-
Constructor Details
-
GamePiece
Creates a GamePiece at the given x and y coordinates.- Parameters:
x
- the x-coordinate of the top-left corner of the game piecey
- the y-coordinate of the top-left corner of the game pieceg
- the Graphics object used to draw the game piece's image
-
-
Method Details
-
getXPos
public int getXPos()Returns the game piece's x coordinate- Returns:
- the x coordinate of this game piece
-
getYPos
public int getYPos()Returns the game piece's y coordinate- Returns:
- the y coordinate of this game piece
-
getImageWidth
public int getImageWidth()Returns the width of this game piece's image- Returns:
- the width of this game piece's image
-
getCharacterWidth
public int getCharacterWidth()Returns the width of the game piece's character (not necessarily the same as the image's width).- Returns:
- the width of the game piece's character
-
draw
public void draw()Draws the GamePiece on the canvas -
takeTurn
The GamePiece takes its turn (nothing for this class)- Parameters:
game
- the game that contains this game piece (and others)
-
clone
Returns a clone of this GamePiece- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-