|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectgame.MovingBody
public abstract class MovingBody
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.
| 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 |
|---|
protected final Point ul
protected final Point lr
protected final Point start
protected boolean outOfBounds
| Constructor Detail |
|---|
public MovingBody(Trackable trajectory,
Point ul,
Point lr)
trajectory - The path to be followedul - Upper-left-hand corner of the displayable fieldlr - Lower-right-hand corner of the displayable field| Method Detail |
|---|
public Point getStart()
public void setTrajectory(Trackable t)
public abstract void respondAfterTick()
public abstract void respondToDeath()
public final void die()
die in interface Animatedpublic final boolean tick(int milliseconds)
tick in interface Animatedmilliseconds - time tick in milliseconds
public final boolean isDone()
isDone in interface Animatedprotected final Point getLocation()
protected final boolean inBounds(Point p)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||