use of com.states.ObjectBehind in project anki-battle-showcase by adessoAG.
the class Vehicle method convertFactsToMessage.
public String convertFactsToMessage() {
ObjectMapper objMapper = new ObjectMapper();
JSONObject json = new JSONObject();
JSONArray arr = new JSONArray();
try {
json.put("speed", this.speed);
for (GameState gameState : this.factsRoad) {
arr.put(gameState.getClass().getSimpleName());
}
json.put("nextRoadPiece", arr);
arr = new JSONArray();
for (GameState gameState : this.factsInventory) {
arr.put(gameState.getClass().getSimpleName());
}
json.put("inv", arr);
// 1 ebene tiefer die einzelnen attribute
JSONArray allObstacleFacts = new JSONArray();
for (GameState gameState : this.factsObstacles) {
JSONArray factArr = new JSONArray();
if (gameState instanceof ObjectBehind) {
factArr.put("Behind");
// obstacle type
factArr.put(((ObjectBehind) gameState).getType());
factArr.put(((ObjectBehind) gameState).getMetersBehind());
}
if (gameState instanceof ObjectInFront) {
factArr.put("Front");
// obstacle type
factArr.put(((ObjectInFront) gameState).getType());
factArr.put(((ObjectInFront) gameState).getMetersInFront());
}
allObstacleFacts.put(factArr);
}
json.put("obstacles", allObstacleFacts);
return json.toString();
} catch (JSONException e) {
log.error("Constructing Json error", e);
}
return "";
}
Aggregations