| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectballwar.model.BallModel
public class BallModel
Represents the main "model" of the system that coordinates the non-GUI processing.
| Field Summary | |
|---|---|
| private  Dispatcher | _dispatcherThe dispatcher used to communicate with all the balls. | 
| private  ILambda | _displayCmdThe current command used to generate the display string. | 
| private  ILambda | _displayCmdOrigThe initial, default command used to generate the initial display string. | 
| private  Graphics | _graphicsVariable used to hold the current Graphics object upon which the balls will next paint. | 
| private  SwitcherStrategy | _switcherThe SwitcherStrategy object to use in switcher balls. | 
| private  Timer | _timerA timer object that is the main clock that drives the simulation. | 
| private  int | _timeSliceThe time in milliseconds between updates to the balls. | 
| private  IBallCmd | _updateStateCmdThe command used when the balls are told to update their states and paint. | 
| private  IViewCtrlAdapter | _vCtrlAThe adapter to the view. | 
| Fields inherited from interface ballwar.model.IBallEnvironment | 
|---|
| NullEnv | 
| Constructor Summary | |
|---|---|
| BallModel(IViewCtrlAdapter vCtrlA)Constructor for the BallControl class Instantiates the BallGUI frame with the required ILambdas for making a ball, clearing the balls from the screen and for painting the balls onto the Container Starts the timer up. | |
| Method Summary | |
|---|---|
|  void | addDisplayCmd(ILambda cmd)Adds a display command (ILambda) used to display messages onto the view. | 
|  void | addKeyCmd(String keyName,
          ILambda cmd)Associates a key with a behavior (command). | 
|  void | clearBalls()Clears all the balls from the dispatcher and resets the display string to its original state. | 
|  Component | getCanvas()Gets the Component that the Balls will be painted on. | 
|  Dispatcher | getDispatcher()Get the dispatcher used to notify all the balls to execute a supplied command. | 
|  String | getDisplayStr(String origStr)Called by the view to get the current display string. | 
|  int | getHeight()Gets the height of the ball's environment | 
|  IPlayer | getSelectedPlayer()Get the currently selected player from the view. | 
|  int | getWidth()Get's the width of the ball's environment. | 
|  Ball | loadBall(IUpdateStrategy strategy,
         IPaintStrategy pstrategy) | 
|  Object | loadStrategy(String className,
             Object defaultObject)Uses dynamic class loading to load and instantiate a specified class, given its full class name. | 
|  void | loadSwitcherBall(IPaintStrategy pstrategy)Loads a ball with a switcher strategy into the system. | 
|  IPlayer | makePlayer(String name,
           IMovementKeys keys)Makes a play8er object given a name and a set of movement keys. | 
|  void | paint(Graphics g)Tells the model to have all the balls to update their states and paint themselves onto the supplied Graphics object. | 
|  void | registerMovementKeys(IMovementKeys keys,
                     IMoveable m)Registers a set of movement keys, as defined by an IMovementKeys object, with the view. | 
|  void | setSwitcherStrategy(IUpdateStrategy strategy)Sets the strategy used by any switcher balls. | 
|  void | start()Starts the model running by starting the internal timer. | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
|---|
private IViewCtrlAdapter _vCtrlA
private Dispatcher _dispatcher
private SwitcherStrategy _switcher
private IBallCmd _updateStateCmd
private Graphics _graphics
private int _timeSlice
private Timer _timer
private ILambda _displayCmdOrig
private ILambda _displayCmd
| Constructor Detail | 
|---|
public BallModel(IViewCtrlAdapter vCtrlA)
| Method Detail | 
|---|
public Dispatcher getDispatcher()
getDispatcher in interface IBallEnvironmentpublic Component getCanvas()
IBallEnvironment
getCanvas in interface IBallEnvironmentpublic int getWidth()
getWidth in interface IBallEnvironmentpublic int getHeight()
getHeight in interface IBallEnvironmentpublic void addDisplayCmd(ILambda cmd)
addDisplayCmd in interface IBallEnvironmentcmd - The ILambda used to generate the display string.public String getDisplayStr(String origStr)
origStr - The string handed to the display commands as their input parameter.
public void addKeyCmd(String keyName,
                      ILambda cmd)
IBallEnvironment
addKeyCmd in interface IBallEnvironmentkeyName - cmd - 
public Ball loadBall(IUpdateStrategy strategy,
                     IPaintStrategy pstrategy)
strategy - 
public Object loadStrategy(String className,
                           Object defaultObject)
classname - full classname of the strategydefaultObject - The default object instance to return if the given class cannot be instantiated.  Usually specified to be an instance of the class's null object value.
public void paint(Graphics g)
g - The Graphics object to paint on.public void clearBalls()
public void setSwitcherStrategy(IUpdateStrategy strategy)
strategy - The new strategy to use.public void loadSwitcherBall(IPaintStrategy pstrategy)
public void start()
public IPlayer makePlayer(String name,
                          IMovementKeys keys)
name - The name of the new playerkeys - The set of movement keys associated with this player.
public void registerMovementKeys(IMovementKeys keys,
                                 IMoveable m)
registerMovementKeys in interface IBallEnvironmentkeys - The set of movement keys to registerm - The IMoveable object to associate with those keys.public IPlayer getSelectedPlayer()
getSelectedPlayer in interface IBallEnvironment| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||