ballwar.model
Interface IBallEnvironment

All Known Implementing Classes:
BallModel

public interface IBallEnvironment

An interface that represents the environment in which the ball is operating.


Field Summary
static IBallEnvironment NullEnv
          Represents a null environment that does nothing.
 
Method Summary
 void addDisplayCmd(ILambda cmd)
          Adds a command that will be run to whenever the view requests a display string to be displayed.
 void addKeyCmd(String keyName, ILambda cmd)
          Associates a key with a behavior (command).
 Component getCanvas()
          Gets the Component that the Balls will be painted on.
 Dispatcher getDispatcher()
          Get the ball dispatcher used by the system.
 int getHeight()
          Get the height of the ball's environment.
 IPlayer getSelectedPlayer()
          Get the currently selected player.
 int getWidth()
          Get the width of the ball's environment.
 void registerMovementKeys(IMovementKeys keys, IMoveable m)
          Takes an IMovementKeys object which defines a set of movement keys and associates the pressing of each key with its respective behavior in the given IMoveable object.
 

Field Detail

NullEnv

static final IBallEnvironment NullEnv
Represents a null environment that does nothing.

Method Detail

getDispatcher

Dispatcher getDispatcher()
Get the ball dispatcher used by the system. Used when a ball wants to communicate to all the other balls, e.g. for collisions.

Returns:
The system ball dispatcher

addKeyCmd

void addKeyCmd(String keyName,
               ILambda cmd)
Associates a key with a behavior (command). When the user presses the given key, the ILambda command will be run. The parameter passed to the command will be the key name. The return value will be discarded.

Parameters:
keyName - The name of the key, as defined by the Java "virtual keys": VK_XXX (The "VK_" is omitted). See the Java documentation under "KeyEvent"
cmd - The ILambda command that will be run when the key is pressed.

addDisplayCmd

void addDisplayCmd(ILambda cmd)
Adds a command that will be run to whenever the view requests a display string to be displayed. The output of the ILambda.apply must be a String given a String input, where the input is the original string on the display. The output is concatenated with all other display commands in the system.

Parameters:
cmd - The command used to generate part of the total display string.

getCanvas

Component getCanvas()
Gets the Component that the Balls will be painted on. Note that a Component class is also implements the ImageObserver interface.

Returns:
The Component object upon which the Balls will be painted.

getWidth

int getWidth()
Get the width of the ball's environment. This is not the same as the width of the entire BallWar frame, but rather simply the width of the graphics area in which the balls are moving.

Returns:
The width of the environment in pixels.

getHeight

int getHeight()
Get the height of the ball's environment. This is not the same as the height of the entire BallWar frame, but rather simply the height of the graphics area in which the balls are moving.

Returns:
The height of the environment in pixels.

getSelectedPlayer

IPlayer getSelectedPlayer()
Get the currently selected player. Note that in general, for a ball or strategy to maintain a connection to a particular player, they must save their own reference and not rely on the currently selected player. Usually this method is only called during an initialization phase.

Returns:
The currently selected player.

registerMovementKeys

void registerMovementKeys(IMovementKeys keys,
                          IMoveable m)
Takes an IMovementKeys object which defines a set of movement keys and associates the pressing of each key with its respective behavior in the given IMoveable object.

Parameters:
keys - The IMovementKeys object that defines a set of movement keys.
m - The IMoveable object that is to be associated with the key set.