simulator.model.debug
Class SMfacade

java.lang.Object
  extended by simulator.model.debug.SMfacade
All Implemented Interfaces:
ISimulatorNet, ISimulatorView

public class SMfacade
extends java.lang.Object
implements ISimulatorNet

A trivial implementation of the required simulator model interfaces for debugging purposes. In most cases this simply logs the calls to a log file.

Version:
$Revision: 385 $ $Date: 2008-03-11 10:10:33 -0230 (Tue, 11 Mar 2008) $
Author:
dpeters

Field Summary
 
Fields inherited from interface simulator.model.ISimulatorView
BALL_RADIUS, FIELD_LENGTH, FIELD_WIDTH, GOAL_WIDTH, NUMBER_OF_PLAYERS, PLAYER_RADIUS
 
Constructor Summary
SMfacade()
           
 
Method Summary
 void accelerate(Side side, int p, double a)
          Sets the acceleration for the player
 void endGame()
          Indicates game should end due to a request from one or more teams.
 CartesianVect getBallPosition()
           
 PolarVect getBallVelocity()
           
 Student getFieldName()
          Which simulator is the host.
 ISimulatorNet getISimulatorNet()
          Get the object that implements the ISimulatorNet interface.
 CartesianVect getPlayerPosition(Side t, int p)
          The position of a particular player.
 PolarVect getPlayerVelocity(Side t, int p)
          The orientation of a particular player.
 java.lang.String getStatusMessage()
          The last status message.
 Student getTeamName(Side t)
          The name of each team.
 int getTeamScore(Side t)
          The number of goals scored by each team.
 int getTime()
          The number of milliseconds played.
 boolean isGameInProgress()
           
 boolean isPlayerInGame(Side t, int p)
          Is the player in play
 void kick(Side side, int p, double v, double alpha)
          Updates field data in response to a kick request
 void placeBall(CartesianVect l)
          placeBall places ball at given coordinates
 void placePlayer(Side side, int p, CartesianVect l)
          places player at given coordinates
 void setNet(INetSimulator n)
          Set the network layer.
 void setStatusMessage(java.lang.String msg)
           
 void setTeams(Student west, Student east)
          Indicates which team is on each side.
 void setTestMode(boolean m)
          Set the model into 'test mode' or not.
 void setTime(int t)
          setTime sets game time
 void spin(Side side, int p, double av)
          Sets angular velocity for the player
 void startGame()
          Indicates that game should start (time == 0).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SMfacade

public SMfacade()
Method Detail

setNet

public void setNet(INetSimulator n)
Description copied from interface: ISimulatorNet
Set the network layer. To be used to call goalScored(), gameReset() and gameOver() when these events occur.

Specified by:
setNet in interface ISimulatorNet

startGame

public void startGame()
Description copied from interface: ISimulatorNet
Indicates that game should start (time == 0).

Precondidtion: setTeams and setNet have been called and isGameInProgress() is false.
Postcondition: isGameInProgress()

Specified by:
startGame in interface ISimulatorNet

endGame

public void endGame()
Description copied from interface: ISimulatorNet
Indicates game should end due to a request from one or more teams. Note that the protocol says that this should only occur due to abnormal situations.

Precondition: true
Postcondition: !isGameInProgress()

Specified by:
endGame in interface ISimulatorNet

accelerate

public void accelerate(Side side,
                       int p,
                       double a)
Description copied from interface: ISimulatorNet
Sets the acceleration for the player

Precondition: isGameInProgress()

Specified by:
accelerate in interface ISimulatorNet
p - Player number, in {0, 1, 2, 3, 4}
a - rate of acceleration, -5 <= a <= 1

kick

public void kick(Side side,
                 int p,
                 double v,
                 double alpha)
Description copied from interface: ISimulatorNet
Updates field data in response to a kick request

Precondition: isGameInProgress()

Specified by:
kick in interface ISimulatorNet
Parameters:
side - the team side
p - Player number, in {0, 1, 2, 3, 4}
v - Change in the ball's velocity. 0 <= v <= 10
alpha - Offset in degrees from a line connecting the player's centre to the ball's centre. -45 <= alpha <= 45

placePlayer

public void placePlayer(Side side,
                        int p,
                        CartesianVect l)
Description copied from interface: ISimulatorNet
places player at given coordinates

Precondition: game is in test mode

Specified by:
placePlayer in interface ISimulatorNet
Parameters:
side - Player team
p - Player number. In {0, 1, 2, 3, 4}
l - new location for player

setTeams

public void setTeams(Student west,
                     Student east)
Description copied from interface: ISimulatorNet
Indicates which team is on each side.

Specified by:
setTeams in interface ISimulatorNet
Parameters:
west - team on WEST side.
east - team on EAST side.

spin

public void spin(Side side,
                 int p,
                 double av)
Description copied from interface: ISimulatorNet
Sets angular velocity for the player

Precondition: isGameInProgress()

Specified by:
spin in interface ISimulatorNet
p - Player number in {0, 1, 2, 3, 4}
av - double Angular velocity in degrees per second. -90 <= av <= 90

getISimulatorNet

public ISimulatorNet getISimulatorNet()
Description copied from interface: ISimulatorView
Get the object that implements the ISimulatorNet interface. This isn't needed by the view so strictly it should be somewhere else. It is needed by simulator.MainUI to set up the game.

Specified by:
getISimulatorNet in interface ISimulatorView
Returns:
an object that is instanceof ISimulatorNet

setTestMode

public void setTestMode(boolean m)
Description copied from interface: ISimulatorView
Set the model into 'test mode' or not.

Specified by:
setTestMode in interface ISimulatorView
Parameters:
m - true to set the model in test mode, false for normal play mode

getFieldName

public Student getFieldName()
Description copied from interface: ISimulatorView
Which simulator is the host.

Specified by:
getFieldName in interface ISimulatorView

getStatusMessage

public java.lang.String getStatusMessage()
Description copied from interface: ISimulatorView
The last status message. This could be any string at all.

Specified by:
getStatusMessage in interface ISimulatorView

setStatusMessage

public void setStatusMessage(java.lang.String msg)

isGameInProgress

public boolean isGameInProgress()
Specified by:
isGameInProgress in interface ISimulatorView
Returns:
true if the game is in progress, false otherwise.

getTeamName

public Student getTeamName(Side t)
Description copied from interface: ISimulatorView
The name of each team.

Precondition: isGameInProgress()

Specified by:
getTeamName in interface ISimulatorView
Parameters:
t - The team, 0 or 1.

getTeamScore

public int getTeamScore(Side t)
Description copied from interface: ISimulatorView
The number of goals scored by each team.

Precondition: isGameInProgress()

Specified by:
getTeamScore in interface ISimulatorView
Parameters:
t - The team, 0 or 1.

getTime

public int getTime()
Description copied from interface: ISimulatorView
The number of milliseconds played.

Precondition: isGameInProgress()

Specified by:
getTime in interface ISimulatorView

getPlayerPosition

public CartesianVect getPlayerPosition(Side t,
                                       int p)
Description copied from interface: ISimulatorView
The position of a particular player.

Precondition: isGameInProgress()

Specified by:
getPlayerPosition in interface ISimulatorView
Parameters:
t - The team, 0 or 1.
p - The player: 0 less than or equal p, p less than number_of_players()

isPlayerInGame

public boolean isPlayerInGame(Side t,
                              int p)
Description copied from interface: ISimulatorView
Is the player in play

Specified by:
isPlayerInGame in interface ISimulatorView
Parameters:
t - team side
p - player. 0 less than or equal p, p less than number_of_players()
Returns:
true if the player is in play, false otherwise (i.e., red-carded).

getPlayerVelocity

public PolarVect getPlayerVelocity(Side t,
                                   int p)
Description copied from interface: ISimulatorView
The orientation of a particular player. The orientation is reported in degrees from the x-axis.

Precondition: isGameInProgress()

Specified by:
getPlayerVelocity in interface ISimulatorView
Parameters:
t - The team, 0 or 1.
p - The player: 0 less than or equal p, p less than NUMBER_OF_PLAYERS()

getBallPosition

public CartesianVect getBallPosition()
Specified by:
getBallPosition in interface ISimulatorView
Returns:
The position of the ball.

getBallVelocity

public PolarVect getBallVelocity()
Specified by:
getBallVelocity in interface ISimulatorView
Returns:
The velocity of the ball.

placeBall

public void placeBall(CartesianVect l)
Description copied from interface: ISimulatorNet
placeBall places ball at given coordinates

Precondition: game is in test mode

Specified by:
placeBall in interface ISimulatorNet
Parameters:
l - location to place the ball

setTime

public void setTime(int t)
Description copied from interface: ISimulatorNet
setTime sets game time

Precondition: game is in test mode

Specified by:
setTime in interface ISimulatorNet
Parameters:
t - int Game time is set to t (in miliseconds)