|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectballwar.model.Ball
public class Ball
An concrete circular ball that moves in a line with its given velocity and bounces off the walls of a rectangularly shaped container. A ball has a location, a radius, a mass, and environment and an update strategy.
Field Summary | |
---|---|
private Color |
_color
The color of the ball. |
private IBallEnvironment |
_env
The ball's environment |
private Point2DDouble |
_location
The present location of the center of the ball. |
private double |
_mass
The mass of the ball |
private IBallMoveStrategy |
_moveStrategy
|
private IPaintStrategy |
_paintStrategy
The paint strategy used by the ball |
private int |
_radius
The radius of the ball. |
private IUpdateStrategy |
_strategy
The update strategy used by the ball |
private BallCmdSet |
_updateCmdSet
|
Constructor Summary | |
---|---|
Ball(IBallEnvironment env,
IUpdateStrategy strategy,
IPaintStrategy pstrategy)
Constructor for a ball. |
Method Summary | |
---|---|
void |
addUpdateCmd(IBallCmd cmd)
|
void |
doKill()
Kills th ball by removing it from the dispatcher. |
Color |
getColor()
Returns the current color of this Ball. |
IBallEnvironment |
getEnv()
Get the ball's environment |
Point2DDouble |
getLocation()
Returns the current center of this Ball. |
double |
getMass()
Get the ball's mass |
IBallMoveStrategy |
getMoveStrategy()
|
IPaintStrategy |
getPaintStrategy()
Returns the current paint strategy of this Ball |
int |
getRadius()
Returns the current radius for this Ball. |
IUpdateStrategy |
getStrategy()
Returns the current strategy of this Ball |
Point2DDouble |
getVelocity()
Returns the current velocity of this Ball. |
void |
kill()
"Kills" this ball by delegating the request to the strategy. |
private void |
move()
|
void |
paint(Graphics g)
Paints the image of the ball onto a Graphics object using the current paint strategy. |
void |
performUpdate()
|
void |
setColor(Color color)
Sets the color of this Ball to a given color. |
void |
setLocation(Point2DDouble location)
Sets the center of the ball to a new location. |
void |
setMass(double mass)
Sets the ball's mass |
void |
setMoveStrategy(IBallMoveStrategy s)
|
void |
setPaintStrategy(IPaintStrategy pstrategy)
Sets the current paint strategy of this Ball to the given strategy |
void |
setRadius(int radius)
Sets the radius of this Ball to a new radius. |
void |
setStrategy(IUpdateStrategy strategy)
Sets the current update strategy of this Ball to the given strategy |
void |
setVelocity(Point2DDouble velocity)
Sets the velocity of this Ball to a new velocity. |
void |
update(Observable o,
Object cmd)
The update method called by the main ball Dispatcher to notify all the balls to perform the given command. |
void |
updateState(Graphics g)
Updates the state of the ball by calling the strategy's updateState(), moving the ball as per its velocity, bouncing off the walls if necessary, and notifying all other balls that it may have collided with them. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private IBallEnvironment _env
private Point2DDouble _location
private int _radius
private IBallMoveStrategy _moveStrategy
private Color _color
private double _mass
private IUpdateStrategy _strategy
private IPaintStrategy _paintStrategy
private BallCmdSet _updateCmdSet
Constructor Detail |
---|
public Ball(IBallEnvironment env, IUpdateStrategy strategy, IPaintStrategy pstrategy)
env
- The ball's environmentstrategy
- The update strategy used by the ball.Method Detail |
---|
public IBallMoveStrategy getMoveStrategy()
public void setMoveStrategy(IBallMoveStrategy s)
public void update(Observable o, Object cmd)
update
in interface Observer
o
- The Dispatcher that set the update request.cmd
- The IBallCmd that will be run.public void addUpdateCmd(IBallCmd cmd)
public void updateState(Graphics g)
g
- The Graphics object to paint on.public void performUpdate()
private void move()
public void setLocation(Point2DDouble location)
location
- the new center.public Point2DDouble getLocation()
public void setRadius(int radius)
radius
- public int getRadius()
public void setVelocity(Point2DDouble velocity)
velocity
- the new velocity for this Ball.public Point2DDouble getVelocity()
public void setColor(Color color)
color
- the new color for this Ball.public Color getColor()
public IUpdateStrategy getStrategy()
public void setPaintStrategy(IPaintStrategy pstrategy)
pstrategy
- The new IPaintStrategy to use.public IPaintStrategy getPaintStrategy()
public void setStrategy(IUpdateStrategy strategy)
strategy
- The new IUpdateStrategy to use.public void paint(Graphics g)
g
- a Graphics object.public void kill()
public void doKill()
public IBallEnvironment getEnv()
public double getMass()
public void setMass(double mass)
mass
- The mass value. Must be a positive, non-zero number.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |