public abstract class Game
extends java.lang.Object
This is used starting in Checkpoint 4. It does not need to be modified until Checkpoint 5.
Constructor and Description |
---|
Game(java.lang.String setEmail,
com.google.android.gms.maps.GoogleMap setMap,
com.neovisionaries.ws.client.WebSocket setWebSocket,
com.google.gson.JsonObject initialState,
android.content.Context setContext)
Sets up this Game.
|
Modifier and Type | Method and Description |
---|---|
protected android.content.Context |
getContext()
Gets the UI context.
|
protected java.lang.String |
getEmail()
Gets the user's email address.
|
protected com.google.android.gms.maps.GoogleMap |
getMap()
Gets the Google Maps view used by this Game.
|
int |
getMyTeam()
Gets the user's team ID in this game.
|
abstract int |
getTeamScore(int teamId)
Gets a team's score.
|
boolean |
handleMessage(com.google.gson.JsonObject message,
java.lang.String type)
Processes an update from the server.
|
abstract void |
locationUpdated(com.google.android.gms.maps.model.LatLng location)
Processes a location change, makes appropriate changes to the game state,
and sends appropriate notifications to the server.
|
protected void |
sendMessage(com.google.gson.JsonObject message)
Sends a message to the server.
|
protected void |
sendMessage(java.lang.String text)
Sends a message to the server.
|
public Game(java.lang.String setEmail, com.google.android.gms.maps.GoogleMap setMap, com.neovisionaries.ws.client.WebSocket setWebSocket, com.google.gson.JsonObject initialState, android.content.Context setContext)
setEmail
- the user's email (from Firebase)setMap
- the Google Maps view to render tosetWebSocket
- the websocket to send events toinitialState
- the "full" update from the serversetContext
- the Android UI contextprotected final android.content.Context getContext()
This method is here to expose the private context variable to subclasses.
protected final java.lang.String getEmail()
This method is here to expose the private email variable to subclasses.
protected final com.google.android.gms.maps.GoogleMap getMap()
This method is here to expose the private map variable to subclasses.
public final int getMyTeam()
public abstract int getTeamScore(int teamId)
Subclasses should implement this in a way specific to their game mode's type of objective.
teamId
- the team IDpublic boolean handleMessage(com.google.gson.JsonObject message, java.lang.String type)
This implementation handles playerLocation and playerExit events, updating the player circles appropriately. Subclass implementations should handle events specific to their game mode, delegating others to this implementation with a super call.
message
- JSON from the servertype
- the update typepublic abstract void locationUpdated(com.google.android.gms.maps.model.LatLng location)
Subclasses should implement this in a way specific to the mode of game they represent.
location
- a location FusedLocationProviderClient is reasonably confident aboutprotected final void sendMessage(com.google.gson.JsonObject message)
Subclasses can use this to send updates via the websocket.
message
- JSON object to sendprotected final void sendMessage(java.lang.String text)
text
- serialized JSON to send