Class GamePiece
java.lang.Object
GamePiece
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
Human
class GamePiece
extends java.lang.Object
implements java.lang.Cloneable
The base class for GamePieces that are displayed on the game panel.
-
Field Summary
Fields Modifier and Type Field Description private java.awt.Graphicsbrushprotected intchar_widthsize of the character inside the imageprotected java.awt.Imageimgimage displayed to represent the game pieceprotected intimg_widthsize of the imageprotected static java.lang.StringimgDirLocation of the image files.protected intxcoordcoordinates of the top-left corner of the imageprotected intycoordcoordinates of the top-left corner of the image -
Constructor Summary
Constructors Constructor Description GamePiece(int x, int y, java.awt.Graphics g)Create a GamePiece with the given characteristics. -
Method Summary
Modifier and Type Method Description GamePiececlone()Returns a clone of this GamePiecevoiddraw()Draws the GamePiece on the canvasintgetCharacterWidth()Returns the width of the GamePiece's characterintgetImageWidth()Returns the width of the GamePiece's imageintgetXPos()Returns the x coordinate of the GamePieceintgetYPos()Returns the y coordinate of the GamePiecevoidmove(Game game)Moves the object to the next spot (nothing for this class)
-
Field Details
-
img
protected java.awt.Image imgimage displayed to represent the game piece -
xcoord
protected int xcoordcoordinates of the top-left corner of the image -
ycoord
protected int ycoordcoordinates of the top-left corner of the image -
img_width
protected int img_widthsize of the image -
char_width
protected int char_widthsize of the character inside the image -
brush
private java.awt.Graphics brush -
imgDir
protected static java.lang.String imgDirLocation of the image files. When using Eclipse, use bin/. Without Eclipse structure, use ./
-
-
Constructor Details
-
GamePiece
public GamePiece(int x, int y, java.awt.Graphics g)Create a GamePiece with the given characteristics.- Parameters:
x- the x coordinate of where the GamePiece is on the boardy- the y coordinate of where the GamePiece is on the boardg- the graphics - where the GamePiece will be displayed
-
-
Method Details
-
getXPos
public int getXPos()Returns the x coordinate of the GamePiece- Returns:
- the x coordinate of the GamePiece
-
getYPos
public int getYPos()Returns the y coordinate of the GamePiece- Returns:
- the y coordinate of the GamePiece
-
getImageWidth
public int getImageWidth()Returns the width of the GamePiece's image- Returns:
- the width of the GamePiece's image
-
getCharacterWidth
public int getCharacterWidth()Returns the width of the GamePiece's character- Returns:
- the width of the GamePiece's character
-
draw
public void draw()Draws the GamePiece on the canvas -
move
Moves the object to the next spot (nothing for this class)- Parameters:
game- - provides access to information about the other 'pieces' in the game
-
clone
Returns a clone of this GamePiece- Overrides:
clonein classjava.lang.Object- Returns:
- a clone of this GamePiece
- Throws:
java.lang.CloneNotSupportedException
-