Example #1
0
  /**
   * This method will create the appropriate Command Object
   *
   * @param info - Passed to the function to create
   * @return - Returns the appropriate Command Object
   */
  public BuildSettlement makeBuildSettlement(JsonConstructionInfo info) {
    JsonParser myParse = new JsonParser();
    JsonElement myEle = myParse.parse(info.getJsonBody());
    JsonTreeReader myTree = new JsonTreeReader(myEle);
    int playerIndex = -1;
    int x = 0;
    int y = 0;
    String jsonDirection = "";
    boolean isFree = false;
    VertexDirection direction = null;
    try {
      myTree.beginObject();
      System.out.println(info.getJsonBody());
      myTree.nextName(); // This is the first which is just the type
      myTree.nextString(); // This is the Type name
      myTree.nextName(); // This is the name == playerindex
      playerIndex = myTree.nextInt(); // This is the player index
      myTree.nextName(); // This is the Vertex Location name
      myTree.beginObject(); // Begining the vertex location object
      myTree.nextName(); // the first integer x name
      x = myTree.nextInt(); // the x-coordinate
      myTree.nextName(); // the y-coordinate name
      y = myTree.nextInt(); // the y-coordinate
      myTree.nextName(); // getting the name of the string vertex direction
      jsonDirection = myTree.nextString(); // the actual vertex direction
      myTree.endObject(); // ending the vertexLocation object
      myTree.nextName(); // the name of the free boolean
      isFree = myTree.nextBoolean(); // the "free" boolean

    } catch (IOException e) {
      e.printStackTrace();
    }
    switch (jsonDirection) {
      case "W":
        direction = VertexDirection.W;
        break;
      case "NW":
        direction = VertexDirection.NW;
        break;
      case "NE":
        direction = VertexDirection.NE;
        break;
      case "E":
        direction = VertexDirection.E;
        break;
      case "SE":
        direction = VertexDirection.SE;
        break;
      case "SW":
        direction = VertexDirection.SW;
        break;
    }
    return new BuildSettlement(playerIndex, x, y, direction, isFree);
  }
Example #2
0
  /**
   * This method will create the appropriate Command Object
   *
   * @param info - Passed to the function to create
   * @return - Returns the appropriate Command Object
   */
  public AcceptTrade makeAcceptTrade(JsonConstructionInfo info) {
    JsonParser myParse = new JsonParser();
    JsonElement myEle = myParse.parse(info.getJsonBody());
    JsonTreeReader myTree = new JsonTreeReader(myEle);
    int playerIndex = -1;
    boolean willAccept = false;
    try {
      myTree.beginObject();
      System.out.println(info.getJsonBody());
      myTree.nextName(); // This is the first which is just the type
      myTree.nextString(); // This is the Type name
      myTree.nextName(); // This is the name == playerindex
      playerIndex = myTree.nextInt(); // This is the player index
      myTree.nextName(); // This is the willAccept
      willAccept = myTree.nextBoolean(); // This is the boolean
    } catch (IOException e) {
      e.printStackTrace();
    }

    return new AcceptTrade(playerIndex, willAccept);
  }