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 image
    protected java.awt.Image img
    image displayed to represent the game piece
    protected int img_width
    size of the image
    protected static java.lang.String imgDir
    Location of the image files.
    protected int xcoord
    coordinates of the top-left corner of the image
    protected 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 GamePiece
    void draw()
    Draws the GamePiece on the canvas
    int getCharacterWidth()
    Returns the width of the GamePiece's character
    int getImageWidth()
    Returns the width of the GamePiece's image
    int getXPos()
    Returns the x coordinate of the GamePiece
    int getYPos()
    Returns the y coordinate of the GamePiece
    void move​(Game game)
    Moves the object to the next spot (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 java.awt.Image img
      image displayed to represent the game piece
    • xcoord

      protected int xcoord
      coordinates of the top-left corner of the image
    • ycoord

      protected int ycoord
      coordinates of the top-left corner of the image
    • 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 java.awt.Graphics brush
    • imgDir

      protected static java.lang.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, java.awt.Graphics g)
      Create a GamePiece with the given characteristics.
      Parameters:
      x - the x coordinate of where the GamePiece is on the board
      y - the y coordinate of where the GamePiece is on the board
      g - 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

      public void move​(Game game)
      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

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