Class GamePiece

java.lang.Object
GamePiece
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
Human

class GamePiece extends Object implements Cloneable
The base class for GamePieces that are displayed on the game panel.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Graphics
     
    protected int
    size of the character inside the image
    protected Image
    animated gif of the game piece, to be displayed on the Game board
    protected int
    size of the image
    protected static String
    Location of the image files.
    protected int
    coordinate of top-left corner of the GamePiece
    protected int
    coordinate of top-left corner of the GamePiece
  • Constructor Summary

    Constructors
    Constructor
    Description
    GamePiece(int x, int y, Graphics g)
    Creates a GamePiece at the given x and y coordinates.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a clone of this GamePiece
    void
    Draws the GamePiece on the canvas
    int
    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 image
    int
    Returns the game piece's x coordinate
    int
    Returns the game piece's y coordinate
    void
    takeTurn(Game game)
    The GamePiece takes its turn (nothing for this class)

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • img

      protected Image img
      animated gif of the game piece, to be displayed on the Game board
    • xcoord

      protected int xcoord
      coordinate of top-left corner of the GamePiece
    • ycoord

      protected int ycoord
      coordinate of top-left corner of the GamePiece
    • img_width

      protected int img_width
      size of the image
    • char_width

      protected int char_width
      size of the character inside the image
    • brush

      private Graphics brush
    • imgDir

      protected static String imgDir
      Location of the image files. When using Eclipse, use bin/. Without Eclipse structure, use ./
  • Constructor Details

    • GamePiece

      public GamePiece(int x, int y, Graphics g)
      Creates a GamePiece at the given x and y coordinates.
      Parameters:
      x - the x-coordinate of the top-left corner of the game piece
      y - the y-coordinate of the top-left corner of the game piece
      g - 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

      public void takeTurn(Game game)
      The GamePiece takes its turn (nothing for this class)
      Parameters:
      game - the game that contains this game piece (and others)
    • clone

      public GamePiece clone() throws CloneNotSupportedException
      Returns a clone of this GamePiece
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException