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.Graphics
brush
protected int
char_width
size of the character inside the imageprotected java.awt.Image
img
image displayed to represent the game pieceprotected int
img_width
size of the imageprotected static java.lang.String
imgDir
Location of the image files.protected int
xcoord
coordinates of the top-left corner of the imageprotected int
ycoord
coordinates 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 GamePiece
clone()
Returns a clone of this GamePiecevoid
draw()
Draws the GamePiece on the canvasint
getCharacterWidth()
Returns the width of the GamePiece's characterint
getImageWidth()
Returns the width of the GamePiece's imageint
getXPos()
Returns the x coordinate of the GamePieceint
getYPos()
Returns the y coordinate of the GamePiecevoid
move(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:
clone
in classjava.lang.Object
- Returns:
- a clone of this GamePiece
- Throws:
java.lang.CloneNotSupportedException
-