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
     
    protected int
    size of the image
    protected static String
    Location of the image files.
    protected int
     
    protected int
     
  • 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 the 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
    • xcoord

      protected int xcoord
    • ycoord

      protected int ycoord
    • 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 game piece
      y - the y-coordinate 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
    • getYPos

      public int getYPos()
      Returns the game piece's y coordinate
    • getImageWidth

      public int getImageWidth()
      Returns the width of the 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).
    • 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