game
Class PieceViz

java.lang.Object
  extended by game.PieceViz
All Implemented Interfaces:
Subscriber<PieceEvent>
Direct Known Subclasses:
CircViz, RectViz

public abstract class PieceViz
extends java.lang.Object
implements Subscriber<PieceEvent>

This class is responsible for displaying graphics associated with game pieces in the graphics panel. The separation of the piece's behavior from its visual representation keeps each part simpler and makes things more flexible.

Author:
Ron Cytron, with some changes by Jon Turner

Field Summary
protected  nip.GraphicsPanel panel
           
protected  Piece piece
           
 
Constructor Summary
PieceViz(Piece piece, java.awt.Color c, nip.GraphicsPanel panel)
           
 
Method Summary
 boolean isDead()
          Subscribers must be able to say when they are still alive or are dead.
protected abstract  nip.Graphic newGraphic()
          Implemented by subclasses to provide a new graphic that represents the piece.
protected abstract  boolean newSize()
          Implemented by subclasses to report whenever the piece changes in size.
 void observeEvent(PieceEvent pe)
          Called whenever the Piece position or status changes and updates the graphic accordingly.
protected  void setGraphic(nip.Graphic graphic)
          Set the Shape for this visualization of a Piece.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

panel

protected final nip.GraphicsPanel panel

piece

protected final Piece piece
Constructor Detail

PieceViz

public PieceViz(Piece piece,
                java.awt.Color c,
                nip.GraphicsPanel panel)
Method Detail

setGraphic

protected void setGraphic(nip.Graphic graphic)
Set the Shape for this visualization of a Piece. Can be changed as the program runs. This is used mainly to change the size of a piece as the game progresses.

Parameters:
graphic - is the new graphic to be used to represent the piece.

newSize

protected abstract boolean newSize()
Implemented by subclasses to report whenever the piece changes in size.

Returns:
true if the piece size has just changed

newGraphic

protected abstract nip.Graphic newGraphic()
Implemented by subclasses to provide a new graphic that represents the piece. Used to replace a piece which has changed in size.

Returns:
the new graphic

observeEvent

public void observeEvent(PieceEvent pe)
Called whenever the Piece position or status changes and updates the graphic accordingly.

Specified by:
observeEvent in interface Subscriber<PieceEvent>
Parameters:
pe - is the event associated with the piece

isDead

public boolean isDead()
Description copied from interface: Subscriber
Subscribers must be able to say when they are still alive or are dead.

Specified by:
isDead in interface Subscriber<PieceEvent>
Returns:
true if this Subscriber is no longer interested in receiving notifications of events from its Publisher.