示例#1
0
  private JSONObject specialMove(int gameCount) {
    Random randomNum = new Random();
    GameInfo gameInfo;
    JSONObject jObj = new JSONObject();
    JSONObject action = new JSONObject();
    int game;
    int addPoints;
    int special;
    // Gets random number to denote which game to use action on
    game = getRandomGame(gameCount);
    gameInfo = gameRecord.get(game);
    // Checks if all specials are used
    if (gameInfo.checkSpecial()) {
      return moveUser(gameCount);
    }
    // Gets random number to denote which special move to use
    special = randomNum.nextInt(4);
    while (gameInfo.checkSpecialMove(special)) {
      special = randomNum.nextInt(4);
    }
    gameInfo.useSpecialMove(special);

    addPoints = randomNum.nextInt(41) - 20;
    gameInfo.addPoints(addPoints);
    gameInfo.incrementCount();

    try {
      jObj.put("game", game);

      action.put("actionType", "specialMove");
      action.put("actionNumber", gameInfo.getCount());
      action.put("pointsAdded", addPoints);
      if (special == SHUFFLE) {
        action.put("move", "Shuffle");
      } else if (special == CLEAR) {
        action.put("move", "Clear");
      } else if (special == INVERT) {
        action.put("move", "Invert");
      } else {
        action.put("move", "Rotate");
      }
      action.put("points", gameInfo.getPoints());

      jObj.put("action", action);
      jObj.put("user", gameInfo.getUser());
    } catch (JSONException e) {
      System.out.println("could not put");
    }
    return jObj;
  }