public class JSONSerializer extends java.lang.Object implements Serializer
| Constructor and Description |
|---|
JSONSerializer() |
| Modifier and Type | Method and Description |
|---|---|
private org.json.JSONObject |
oEdgeLocation(EdgeLocation edgeLocation) |
private org.json.JSONObject |
oHexLocation(HexLocation location) |
private org.json.JSONObject |
oResourceList(java.util.List<java.lang.Integer> resourceList)
Turns the passed resource list into a JSONObject which is returned
|
private org.json.JSONObject |
oVertexLocation(VertexLocation vertexLocation) |
java.lang.String |
sAcceptTradeReq(int playerIndex,
boolean willAccept)
Serializes a request to accept (or reject) a trade
|
java.lang.String |
sAddAIReq(AIType aitype)
Serializes a request to add AI to a game
|
java.lang.String |
sBuildCityReq(int playerIndex,
VertexLocation vertexLocation)
Serializes a request to build a city
|
java.lang.String |
sBuildRoadReq(int playerIndex,
EdgeLocation roadLocation,
boolean free)
Serializes a request to build a road
|
java.lang.String |
sBuildSettlementReq(int playerIndex,
VertexLocation vertexLocation,
boolean free)
Serializes a request to build a settlement
|
java.lang.String |
sBuyDevCardReq(int playerIndex)
Serializes a request to buy a development card
|
java.lang.String |
sCreateGameReq(boolean randomTiles,
boolean randomNumbers,
boolean randomPorts,
java.lang.String name)
Serializes data for requests to create a game
|
java.lang.String |
sCredentials(java.lang.String username,
java.lang.String password)
Serializes the information for any requests that require user credentials
|
java.lang.String |
sDiscardCardsReq(int playerIndex,
java.util.List<java.lang.Integer> resourceList)
Serializes a request to discard cards
|
java.lang.String |
sFinishTurnReq(int playerIndex)
Serializes a request to finish a turn
|
java.lang.String |
sJoinGameReq(int id,
CatanColor color)
Serializes a request from a user to join a game
|
java.lang.String |
sMaritimeTradeReq(int playerIndex,
int ratio,
ResourceType inputResource,
ResourceType outputResource)
Serializes a request to perform a maritime trade
|
java.lang.String |
sMonopolyCardReq(int playerIndex,
ResourceType resource)
Serializes a request to play a monopoly card
|
java.lang.String |
sMonumentCardReq(int playerIndex)
Serializes a request to play a monument card
|
java.lang.String |
sOfferTradeReq(int playerIndex,
java.util.List<java.lang.Integer> resourceList,
int receiver)
Serializes a request to offer a trade
|
java.lang.String |
sRoadBuildingCardReq(int playerIndex,
EdgeLocation edgeLoc1,
EdgeLocation edgeLoc2)
Serializes a request to play a road building card
|
java.lang.String |
sRobPlayerReq(int playerIndex,
int victimIndex,
HexLocation location)
Serializes a request to rob a player
|
java.lang.String |
sRollNumberReq(int playerIndex,
int number)
Serializes a request to roll a dice, where the result is already known
|
java.lang.String |
sSendChatReq(int playerIndex,
java.lang.String content)
Serializes a request to send a chat message
|
java.lang.String |
sSoldierCardReq(int playerIndex,
int victimIndex,
HexLocation location)
Serializes a request to play a soldier card
|
java.lang.String |
sYearOfPlentyCardReq(int playerIndex,
ResourceType resource1,
ResourceType resource2)
Serializes a request to play a Year of Plenty card
|
public java.lang.String sCredentials(java.lang.String username,
java.lang.String password)
throws org.json.JSONException
SerializersCredentials in interface Serializerusername - The user's usernamepassword - The user's passwordorg.json.JSONExceptionpublic java.lang.String sCreateGameReq(boolean randomTiles,
boolean randomNumbers,
boolean randomPorts,
java.lang.String name)
throws org.json.JSONException
SerializersCreateGameReq in interface SerializerrandomTiles - Whether to create a game with random tilesrandomNumbers - Whether to create a game with random chit placementrandomPorts - Whether to create a game with random portsname - The name of the game to createorg.json.JSONExceptionpublic java.lang.String sJoinGameReq(int id,
CatanColor color)
throws org.json.JSONException
SerializersJoinGameReq in interface Serializerid - ID of the user who wishes to join the gamecolor - The color the user requestsorg.json.JSONExceptionpublic java.lang.String sAddAIReq(AIType aitype) throws org.json.JSONException
SerializersAddAIReq in interface Serializerorg.json.JSONExceptionpublic java.lang.String sSendChatReq(int playerIndex,
java.lang.String content)
throws org.json.JSONException
SerializersSendChatReq in interface SerializerplayerIndex - The index of the player sending the chatcontent - The chat contentorg.json.JSONExceptionpublic java.lang.String sRollNumberReq(int playerIndex,
int number)
throws org.json.JSONException
SerializersRollNumberReq in interface SerializerplayerIndex - The index of the player who rollsnumber - The number rolledorg.json.JSONExceptionpublic java.lang.String sRobPlayerReq(int playerIndex,
int victimIndex,
HexLocation location)
throws org.json.JSONException
SerializersRobPlayerReq in interface SerializerplayerIndex - The index of the player doing the robbingvictimIndex - The index of the victimlocation - The new location of the robberorg.json.JSONExceptionprivate org.json.JSONObject oHexLocation(HexLocation location) throws org.json.JSONException
org.json.JSONExceptionpublic java.lang.String sFinishTurnReq(int playerIndex)
throws org.json.JSONException
SerializersFinishTurnReq in interface SerializerplayerIndex - The index of the player who is finishing their turnorg.json.JSONExceptionpublic java.lang.String sBuyDevCardReq(int playerIndex)
throws org.json.JSONException
SerializersBuyDevCardReq in interface SerializerplayerIndex - The index of the player who is buying the development cardorg.json.JSONExceptionpublic java.lang.String sYearOfPlentyCardReq(int playerIndex,
ResourceType resource1,
ResourceType resource2)
throws org.json.JSONException
SerializersYearOfPlentyCardReq in interface SerializerplayerIndex - The index of the player who wishes to play the cardresource1 - The first resource to take from the bankresource2 - The second resource to take from the bankorg.json.JSONExceptionpublic java.lang.String sRoadBuildingCardReq(int playerIndex,
EdgeLocation edgeLoc1,
EdgeLocation edgeLoc2)
throws org.json.JSONException
SerializersRoadBuildingCardReq in interface SerializerplayerIndex - The index of the player who wishes to play the cardedgeLoc1 - The location of the first roadedgeLoc2 - The location of the second roadorg.json.JSONExceptionprivate org.json.JSONObject oEdgeLocation(EdgeLocation edgeLocation) throws org.json.JSONException
org.json.JSONExceptionpublic java.lang.String sSoldierCardReq(int playerIndex,
int victimIndex,
HexLocation location)
throws org.json.JSONException
SerializersSoldierCardReq in interface SerializerplayerIndex - The index of the player who wishes to play the cardvictimIndex - The index of the victimlocation - The new hex location of the soldierorg.json.JSONExceptionpublic java.lang.String sMonopolyCardReq(int playerIndex,
ResourceType resource)
throws org.json.JSONException
SerializersMonopolyCardReq in interface SerializerplayerIndex - The index of the player who wishes to play the cardresource - The resource to have a monopoly onorg.json.JSONExceptionpublic java.lang.String sMonumentCardReq(int playerIndex)
throws org.json.JSONException
SerializersMonumentCardReq in interface SerializerplayerIndex - The index of the player who wishes to play the cardorg.json.JSONExceptionpublic java.lang.String sBuildRoadReq(int playerIndex,
EdgeLocation roadLocation,
boolean free)
throws org.json.JSONException
SerializersBuildRoadReq in interface SerializerplayerIndex - The index of the player who wishes to build the roadroadLocation - The location of the roadfree - Whether this road is free (doesn't cost resources) or notorg.json.JSONExceptionpublic java.lang.String sBuildSettlementReq(int playerIndex,
VertexLocation vertexLocation,
boolean free)
throws org.json.JSONException
SerializersBuildSettlementReq in interface SerializerplayerIndex - The index of the player who wishes to build the settlementvertexLocation - Where to build the settlementfree - Whether this settlement is free (doesn't cost resources) or notorg.json.JSONExceptionprivate org.json.JSONObject oVertexLocation(VertexLocation vertexLocation) throws org.json.JSONException
org.json.JSONExceptionpublic java.lang.String sBuildCityReq(int playerIndex,
VertexLocation vertexLocation)
throws org.json.JSONException
SerializersBuildCityReq in interface SerializerplayerIndex - The index of the player who wishes to build the cityvertexLocation - Where to build the cityorg.json.JSONExceptionpublic java.lang.String sOfferTradeReq(int playerIndex,
java.util.List<java.lang.Integer> resourceList,
int receiver)
throws org.json.JSONException
SerializersOfferTradeReq in interface SerializerplayerIndex - The index of the player offering the traderesourceList - The list of resources being traded and asked forreceiver - The index of the receiverorg.json.JSONExceptionprivate org.json.JSONObject oResourceList(java.util.List<java.lang.Integer> resourceList)
throws org.json.JSONException
resourceList - org.json.JSONExceptionpublic java.lang.String sAcceptTradeReq(int playerIndex,
boolean willAccept)
throws org.json.JSONException
SerializersAcceptTradeReq in interface SerializerplayerIndex - The index of the player who is accepting or rejecting the tradewillAccept - Whether the trade is acceptedorg.json.JSONExceptionpublic java.lang.String sMaritimeTradeReq(int playerIndex,
int ratio,
ResourceType inputResource,
ResourceType outputResource)
throws org.json.JSONException
SerializersMaritimeTradeReq in interface SerializerplayerIndex - The index of the player who is performing the traderatio - The trade ratio of the portinputResource - The resource being tradedoutputResource - The resource being traded fororg.json.JSONExceptionpublic java.lang.String sDiscardCardsReq(int playerIndex,
java.util.List<java.lang.Integer> resourceList)
throws org.json.JSONException
SerializersDiscardCardsReq in interface SerializerplayerIndex - The index of the player discarding cardsresourceList - A resource list with the cards being discardedorg.json.JSONException