public final class AreaGame extends Game
All these functions are stubs that you need to implement.
Feel free to add any private helper functions that would be useful.
See TargetGame for an example of how multiplayer games are handled.
| Constructor and Description |
|---|
AreaGame(java.lang.String email,
com.google.android.gms.maps.GoogleMap map,
com.neovisionaries.ws.client.WebSocket webSocket,
com.google.gson.JsonObject fullState,
android.content.Context context)
Creates a game in area mode.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getTeamScore(int teamId)
Gets a team's score in this area mode game.
|
boolean |
handleMessage(com.google.gson.JsonObject message,
java.lang.String type)
Processes an update from the server.
|
void |
locationUpdated(com.google.android.gms.maps.model.LatLng location)
Called when the user's location changes.
|
getContext, getEmail, getMap, getMyTeam, sendMessage, sendMessagepublic AreaGame(java.lang.String email,
com.google.android.gms.maps.GoogleMap map,
com.neovisionaries.ws.client.WebSocket webSocket,
com.google.gson.JsonObject fullState,
android.content.Context context)
Loads the current game state from JSON into instance variables and populates the map to show existing cell captures.
email - the user's emailmap - the Google Maps control to render towebSocket - the websocket to send updates tofullState - the "full" update from the servercontext - the Android UI contextpublic int getTeamScore(int teamId)
getTeamScore in class GameteamId - the team IDpublic boolean handleMessage(com.google.gson.JsonObject message,
java.lang.String type)
Since playerCellCapture events are specific to area mode games, this function handles those by placing a polygon of the capturing player's team color on the newly captured cell and recording the cell's new owning team. All other message types are delegated to the superclass.
handleMessage in class Gamemessage - JSON from the servertype - the update typepublic void locationUpdated(com.google.android.gms.maps.model.LatLng location)
Area mode games detect whether the player is in an uncaptured cell. Capture is possible if the player has no captures yet or if the cell shares a side with the previous cell captured by the player. If capture occurs, a polygon with the team color is added to the cell on the map and a cellCapture update is sent to the server.
locationUpdated in class Gamelocation - a location FusedLocationProviderClient is reasonably confident about