com.tootsville.game
Class SoccerField

java.lang.Object
  extended by org.starhope.appius.game.GameEvent
      extended by com.tootsville.game.SoccerField
All Implemented Interfaces:
Comparable<Object>, RoomListener, AcceptsMetronomeTicks, HasName

public class SoccerField
extends GameEvent

Author:
brpocock@star-hope.org, ewinkelman

Nested Class Summary
private static class SoccerField.RefPhrases
          Just for convenience
 
Field Summary
private  SoccerBall ball
          Pointer to the user that represents the soccer ball
private  org.starhope.appius.geometry.Coord2D centerField
          Center of the field
private  org.starhope.appius.geometry.Coord2D entryPoint
          Exit points when the soccer ball goes out of bounds
private  org.starhope.appius.geometry.Polygon field
          The polygon that contains the dimensions of the field
private  org.starhope.appius.geometry.Polygon goalLeft
          the left-side goal region
private  org.starhope.appius.geometry.Polygon goalRight
          the right-side goal region
private  boolean inGoal
          Is the ball in the left goal?
private  long lastGoalTime
          Last time a goal was made
private  long lastTimeMoving
          The last time the soccer ball moved
private  int leftScore
          Score for the left side team
private  boolean outOfBounds
          Boolean to freeze the ball from colliding
private  AbstractNonPlayerCharacter referee
          Referee character
private  int rightScore
          Score for the right side team
private static long serialVersionUID
          Serialization ID
private  Room soccerField
          Soccer field room object
 
Fields inherited from class org.starhope.appius.game.GameEvent
freezeTag, gameCode, gameState, players, rooms, scores, scoreWatchRooms
 
Constructor Summary
SoccerField(Zone z)
           
 
Method Summary
 void acceptGameAction(AbstractUser u, org.json.JSONObject action)
          Broadcast message of a game action taking place
 void acceptOutOfBandMessage(AbstractUser sender, Room room, org.json.JSONObject body)
          Accept an out-of-band communications packet that was broadcast to a room in which this Listener is listening.
 void acceptPublicMessage(AbstractUser from, String message)
          Accept a public chat message.
 void acceptUserAction(Room r, AbstractUser u)
          User actions (go/do actions) propagate through this channel.
 void destroySelf()
          Cleanup routine to make sure we get garbage collected properly
 String getGameEventPrefix()
          Get the prefix to be applied to event types for this game
 String getName()
          Return a user-visible, unique name for this class.
private  void speakRefSpeak(SoccerField.RefPhrases phrase)
          Mostly because I wanted to make sure Stu isn't spamming speech when no one is around to hear it
 void tick(long currentTime, long deltaTime)
          This method is called periodically from the metronome thread.
 
Methods inherited from class org.starhope.appius.game.GameEvent
acceptCommand, acceptCommand, acceptGameStateChange, acceptObjectJoinRoom, acceptObjectPartRoom, acceptPublicMessage, acceptUserVariableUpdate, changeGameState, compareTo, decrementScore, disconnect, equals, equals, getCountdownDuration, getEveryone, getGameCode, getGameDuration, getGameShortName, getLeaderBonus, getPlayers, getRoom, getRooms, getScoreWatchRooms, getSpectators, getTimer, getZone, hashCode, incrementScore, propagateGameStateChange, resetPlayers, sendEndEvents, sendStartEvents, toString, updateRoomVars, updateScore, updateScores
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Serialization ID

See Also:
Constant Field Values

ball

private transient SoccerBall ball
Pointer to the user that represents the soccer ball


centerField

private final transient org.starhope.appius.geometry.Coord2D centerField
Center of the field


entryPoint

private transient org.starhope.appius.geometry.Coord2D entryPoint
Exit points when the soccer ball goes out of bounds


field

private final transient org.starhope.appius.geometry.Polygon field
The polygon that contains the dimensions of the field


outOfBounds

private boolean outOfBounds
Boolean to freeze the ball from colliding


goalLeft

private final transient org.starhope.appius.geometry.Polygon goalLeft
the left-side goal region


goalRight

private final transient org.starhope.appius.geometry.Polygon goalRight
the right-side goal region


lastTimeMoving

private long lastTimeMoving
The last time the soccer ball moved


referee

private transient AbstractNonPlayerCharacter referee
Referee character


soccerField

private final transient Room soccerField
Soccer field room object


inGoal

private boolean inGoal
Is the ball in the left goal?


leftScore

private int leftScore
Score for the left side team


rightScore

private int rightScore
Score for the right side team


lastGoalTime

private long lastGoalTime
Last time a goal was made

Constructor Detail

SoccerField

public SoccerField(Zone z)
            throws GameLogicException,
                   NotFoundException
Parameters:
z - zone
Throws:
GameLogicException - WRITEME
NotFoundException - WRITEME
Method Detail

acceptGameAction

public void acceptGameAction(AbstractUser u,
                             org.json.JSONObject action)
Description copied from interface: RoomListener
Broadcast message of a game action taking place

Parameters:
u - the sender
action - The game action. The verb is in action.getString("action").
See Also:
RoomListener.acceptGameAction(org.starhope.appius.user.AbstractUser, org.json.JSONObject)

acceptOutOfBandMessage

public void acceptOutOfBandMessage(AbstractUser sender,
                                   Room room,
                                   org.json.JSONObject body)
Description copied from interface: RoomListener
Accept an out-of-band communications packet that was broadcast to a room in which this Listener is listening.

Parameters:
sender - The sender of the OOB message
room - The room in which the OOB message is being broadcast
body - A JSON object containing the OOB message. The contents of this message are not constrained.
See Also:
RoomListener.acceptOutOfBandMessage(org.starhope.appius.user.AbstractUser, org.starhope.appius.game.Room, org.json.JSONObject)

acceptPublicMessage

public void acceptPublicMessage(AbstractUser from,
                                String message)
Description copied from interface: RoomListener
Accept a public chat message. This prototype does not specify the room, on the (potentially invalid) assumption that the room listener doesn't care from which room the speech was made.

Parameters:
from - The speaker
message - The spoken text or /emote
See Also:
RoomListener.acceptPublicMessage(org.starhope.appius.user.AbstractUser, java.lang.String)

acceptUserAction

public void acceptUserAction(Room r,
                             AbstractUser u)
Description copied from interface: RoomListener
User actions (go/do actions) propagate through this channel.

Parameters:
r - the room in which the user is taking an action
u - the user taking an action
See Also:
RoomListener.acceptUserAction(org.starhope.appius.game.Room, org.starhope.appius.user.AbstractUser)

destroySelf

public void destroySelf()
Cleanup routine to make sure we get garbage collected properly

Overrides:
destroySelf in class GameEvent

getGameEventPrefix

public String getGameEventPrefix()
Description copied from class: GameEvent
Get the prefix to be applied to event types for this game

Specified by:
getGameEventPrefix in class GameEvent
Returns:
the string prefix used to find event types for this game
See Also:
GameEvent.getGameEventPrefix()

getName

public String getName()
Description copied from interface: HasName
Return a user-visible, unique name for this class. This name may not necessarily be globally unique, but must be unique across all objects of this class. For example, having both a User and a Zone named “Lightning” is acceptable, but there may not be two users with the same name.

Returns:
a user-visible string name for this instance
See Also:
HasName.getName()

speakRefSpeak

private void speakRefSpeak(SoccerField.RefPhrases phrase)
Mostly because I wanted to make sure Stu isn't spamming speech when no one is around to hear it

Parameters:
phrase - phrase key

tick

public void tick(long currentTime,
                 long deltaTime)
          throws UserDeadException
Description copied from interface: AcceptsMetronomeTicks
This method is called periodically from the metronome thread. To save computation, it receives both the current time since epoch in milliseconds at the start of the global tick propagation, and the delta time since the previous metronome tick.

Specified by:
tick in interface AcceptsMetronomeTicks
Overrides:
tick in class GameEvent
Parameters:
currentTime - Time since epoch at the start of the global metronome propagation, as per System.currentTimeMillis()
deltaTime - Delta-time in milliseconds since the prior global metronome tick
Throws:
UserDeadException - if a user has died during this tick
See Also:
GameEvent.tick(long, long)