game
Class MovingBody

java.lang.Object
  extended by game.MovingBody
All Implemented Interfaces:
Animated
Direct Known Subclasses:
CurveTracer, MovingGraphic, MovingGraphics

public abstract class MovingBody
extends java.lang.Object
implements Animated

An articulated class between Animated and specific classes that implement Animated. Responsibility is held here for tracking whether the motion goes out of bounds, in which case the object will no longer move and will be asked to die. The responsibility is enforced by making tick() "final", so no subclass can usurp it. Flexibility of reacting to ticks is given by abstract methods such as respondAfterTick(), which any subclass can implement and act as it pleases.

Author:
cytron

Field Summary
protected  Point lr
           
protected  boolean outOfBounds
           
protected  Point start
           
protected  Point ul
           
 
Constructor Summary
MovingBody(Trackable trajectory, Point ul, Point lr)
          Accommodates a trajectory within a space bounded by two corners with animation.
 
Method Summary
 void die()
          Fulfills the Animated interface, and allow subclasses to respond to their death.
protected  Point getLocation()
           
 Point getStart()
          Getter
protected  boolean inBounds(Point p)
           
 boolean isDone()
          Fulfills the Animated interface.
abstract  void respondAfterTick()
          Give subclasses a chance to respond to each tick
abstract  void respondToDeath()
          Give subclasses a chance to respond to their death
 void setTrajectory(Trackable t)
          Setter in case we want to change course midway through
 boolean tick(int milliseconds)
          Fulfills the Animated interface, and allows subclasses to respond after the tick.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ul

protected final Point ul

lr

protected final Point lr

start

protected final Point start

outOfBounds

protected boolean outOfBounds
Constructor Detail

MovingBody

public MovingBody(Trackable trajectory,
                  Point ul,
                  Point lr)
Accommodates a trajectory within a space bounded by two corners with animation.

Parameters:
trajectory - The path to be followed
ul - Upper-left-hand corner of the displayable field
lr - Lower-right-hand corner of the displayable field
Method Detail

getStart

public Point getStart()
Getter

Returns:
location of the trajectory when this class was instantiated.

setTrajectory

public void setTrajectory(Trackable t)
Setter in case we want to change course midway through


respondAfterTick

public abstract void respondAfterTick()
Give subclasses a chance to respond to each tick


respondToDeath

public abstract void respondToDeath()
Give subclasses a chance to respond to their death


die

public final void die()
Fulfills the Animated interface, and allow subclasses to respond to their death.

Specified by:
die in interface Animated

tick

public final boolean tick(int milliseconds)
Fulfills the Animated interface, and allows subclasses to respond after the tick. Is "final" so that no subclass can hijack this implementation of tick() by overriding it. This assures us that we can check whether the current location is in bounds or not.

Specified by:
tick in interface Animated
Parameters:
milliseconds - time tick in milliseconds
Returns:
true if we are still in bounds of the displayable field

isDone

public final boolean isDone()
Fulfills the Animated interface. We are done if our shape has moved out of bounds.

Specified by:
isDone in interface Animated
Returns:
true if the object no longer should move

getLocation

protected final Point getLocation()

inBounds

protected final boolean inBounds(Point p)