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
FieldsModifier and TypeFieldDescriptionprivate Graphicsprotected intsize of the character inside the imageprotected Imageanimated gif of the game piece, to be displayed on the Game boardprotected intsize of the imageprotected static StringLocation of the image files.protected intcoordinate of top-left corner of the GamePieceprotected intcoordinate of top-left corner of the GamePiece -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()Returns a clone of this GamePiecevoiddraw()Draws the GamePiece on the canvasintReturns the width of the game piece's character (not necessarily the same as the image's width).intReturns the width of this game piece's imageintgetXPos()Returns the game piece's x coordinateintgetYPos()Returns the game piece's y coordinatevoidThe 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:
clonein classObject- Throws:
CloneNotSupportedException
-