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
Serializer
sCredentials
in interface Serializer
username
- The user's usernamepassword
- The user's passwordorg.json.JSONException
public java.lang.String sCreateGameReq(boolean randomTiles, boolean randomNumbers, boolean randomPorts, java.lang.String name) throws org.json.JSONException
Serializer
sCreateGameReq
in interface Serializer
randomTiles
- 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.JSONException
public java.lang.String sJoinGameReq(int id, CatanColor color) throws org.json.JSONException
Serializer
sJoinGameReq
in interface Serializer
id
- ID of the user who wishes to join the gamecolor
- The color the user requestsorg.json.JSONException
public java.lang.String sAddAIReq(AIType aitype) throws org.json.JSONException
Serializer
sAddAIReq
in interface Serializer
org.json.JSONException
public java.lang.String sSendChatReq(int playerIndex, java.lang.String content) throws org.json.JSONException
Serializer
sSendChatReq
in interface Serializer
playerIndex
- The index of the player sending the chatcontent
- The chat contentorg.json.JSONException
public java.lang.String sRollNumberReq(int playerIndex, int number) throws org.json.JSONException
Serializer
sRollNumberReq
in interface Serializer
playerIndex
- The index of the player who rollsnumber
- The number rolledorg.json.JSONException
public java.lang.String sRobPlayerReq(int playerIndex, int victimIndex, HexLocation location) throws org.json.JSONException
Serializer
sRobPlayerReq
in interface Serializer
playerIndex
- The index of the player doing the robbingvictimIndex
- The index of the victimlocation
- The new location of the robberorg.json.JSONException
private org.json.JSONObject oHexLocation(HexLocation location) throws org.json.JSONException
org.json.JSONException
public java.lang.String sFinishTurnReq(int playerIndex) throws org.json.JSONException
Serializer
sFinishTurnReq
in interface Serializer
playerIndex
- The index of the player who is finishing their turnorg.json.JSONException
public java.lang.String sBuyDevCardReq(int playerIndex) throws org.json.JSONException
Serializer
sBuyDevCardReq
in interface Serializer
playerIndex
- The index of the player who is buying the development cardorg.json.JSONException
public java.lang.String sYearOfPlentyCardReq(int playerIndex, ResourceType resource1, ResourceType resource2) throws org.json.JSONException
Serializer
sYearOfPlentyCardReq
in interface Serializer
playerIndex
- 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.JSONException
public java.lang.String sRoadBuildingCardReq(int playerIndex, EdgeLocation edgeLoc1, EdgeLocation edgeLoc2) throws org.json.JSONException
Serializer
sRoadBuildingCardReq
in interface Serializer
playerIndex
- The index of the player who wishes to play the cardedgeLoc1
- The location of the first roadedgeLoc2
- The location of the second roadorg.json.JSONException
private org.json.JSONObject oEdgeLocation(EdgeLocation edgeLocation) throws org.json.JSONException
org.json.JSONException
public java.lang.String sSoldierCardReq(int playerIndex, int victimIndex, HexLocation location) throws org.json.JSONException
Serializer
sSoldierCardReq
in interface Serializer
playerIndex
- The index of the player who wishes to play the cardvictimIndex
- The index of the victimlocation
- The new hex location of the soldierorg.json.JSONException
public java.lang.String sMonopolyCardReq(int playerIndex, ResourceType resource) throws org.json.JSONException
Serializer
sMonopolyCardReq
in interface Serializer
playerIndex
- The index of the player who wishes to play the cardresource
- The resource to have a monopoly onorg.json.JSONException
public java.lang.String sMonumentCardReq(int playerIndex) throws org.json.JSONException
Serializer
sMonumentCardReq
in interface Serializer
playerIndex
- The index of the player who wishes to play the cardorg.json.JSONException
public java.lang.String sBuildRoadReq(int playerIndex, EdgeLocation roadLocation, boolean free) throws org.json.JSONException
Serializer
sBuildRoadReq
in interface Serializer
playerIndex
- 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.JSONException
public java.lang.String sBuildSettlementReq(int playerIndex, VertexLocation vertexLocation, boolean free) throws org.json.JSONException
Serializer
sBuildSettlementReq
in interface Serializer
playerIndex
- 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.JSONException
private org.json.JSONObject oVertexLocation(VertexLocation vertexLocation) throws org.json.JSONException
org.json.JSONException
public java.lang.String sBuildCityReq(int playerIndex, VertexLocation vertexLocation) throws org.json.JSONException
Serializer
sBuildCityReq
in interface Serializer
playerIndex
- The index of the player who wishes to build the cityvertexLocation
- Where to build the cityorg.json.JSONException
public java.lang.String sOfferTradeReq(int playerIndex, java.util.List<java.lang.Integer> resourceList, int receiver) throws org.json.JSONException
Serializer
sOfferTradeReq
in interface Serializer
playerIndex
- The index of the player offering the traderesourceList
- The list of resources being traded and asked forreceiver
- The index of the receiverorg.json.JSONException
private org.json.JSONObject oResourceList(java.util.List<java.lang.Integer> resourceList) throws org.json.JSONException
resourceList
- org.json.JSONException
public java.lang.String sAcceptTradeReq(int playerIndex, boolean willAccept) throws org.json.JSONException
Serializer
sAcceptTradeReq
in interface Serializer
playerIndex
- The index of the player who is accepting or rejecting the tradewillAccept
- Whether the trade is acceptedorg.json.JSONException
public java.lang.String sMaritimeTradeReq(int playerIndex, int ratio, ResourceType inputResource, ResourceType outputResource) throws org.json.JSONException
Serializer
sMaritimeTradeReq
in interface Serializer
playerIndex
- 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.JSONException
public java.lang.String sDiscardCardsReq(int playerIndex, java.util.List<java.lang.Integer> resourceList) throws org.json.JSONException
Serializer
sDiscardCardsReq
in interface Serializer
playerIndex
- The index of the player discarding cardsresourceList
- A resource list with the cards being discardedorg.json.JSONException