コード例 #1
0
ファイル: Achievement.java プロジェクト: rajdanala/pandam
 public static final void evaluate(final PlayerContext pc) {
   if (pc == null) {
     return;
   }
   final Profile profile = pc.profile;
   final Set<Integer> achieved = profile.achievements;
   final int size = ALL.length;
   boolean any = false;
   for (int i = 0; i < size; i++) {
     final Integer key = Integer.valueOf(i);
     if (achieved.contains(key)) {
       continue;
     }
     final Achievement ach = ALL[i];
     if (ach.isMet(pc)) {
       achieved.add(key);
       final int award = ach.award;
       FurGuardiansGame.notify(
           pc, ach.getName() + ", " + award + " Gem bonus", new Gem(FurGuardiansGame.gemAchieve));
       pc.addGems(award);
       any = true;
     }
   }
   if (any) {
     profile.save();
   }
 }
コード例 #2
0
    @Override
    protected Void doInBackground(String... params) {
      try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(
            new BasicNameValuePair("access_token", "059db4f010c5f40bf4a73a28222dd3e3"));
        nameValuePairs.add(new BasicNameValuePair("badge_name", "donorfriend"));
        nameValuePairs.add(new BasicNameValuePair("user_id", auth.getFacebookId()));
        nameValuePairs.add(new BasicNameValuePair("user_token", auth.getAccessToken()));
        JSONObject jsonObject =
            new JSONObject(
                WebUtil.postData(
                    "http://www.itsbeta.com/s/healthcare/donor/achieves/posttofbonce.json",
                    nameValuePairs,
                    "UTF-8"));
        if (!jsonObject.has("error")) {
          Achievement achievement = new Achievement();
          achievement.setDisplayName(jsonObject.getString("display_name"));
          achievement.setPictureLink(jsonObject.getString("pic"));
          achievement.setDescription(jsonObject.getString("desc"));
          startNewAchievementActivity(achievement);
        } else {
          finishBackgroundProcess();
        }
      } catch (Exception e) {

      }
      return null;
    }
コード例 #3
0
 public void getAchievements(String playerId) throws IOException {
   try {
     JSONObject json = new JSONObject();
     json.put("access_token", "8e6b3a7b47c3346cb7e4db42c88519bc");
     json.put("player_id", playerId);
     json.put("project_id", "50d78a38d870307e9b000002");
     JSONArray jsonArray =
         new JSONArray(
             WebUtil.postData("http://www.itsbeta.com/s/info/achievements.json", json, "UTF-8"));
     if (jsonArray.length() != 1) {
       return;
     }
     JSONArray projects = jsonArray.getJSONObject(0).getJSONArray("projects");
     for (int i = 0; i < projects.length(); i++) {
       JSONObject currentProject = projects.getJSONObject(i);
       Log.d("donor", currentProject.getString("api_name"));
       JSONArray achievements = currentProject.getJSONArray("achievements");
       for (int j = 0; j < achievements.length(); j++) {
         JSONObject currentAchievement = achievements.getJSONObject(i);
         Log.d("donor", currentAchievement.getString("badge_name"));
         Achievement achievement = new Achievement();
         achievement.setDisplayName(currentAchievement.getString("display_name"));
         achievement.setPictureLink(currentAchievement.getString("pic"));
         achievement.setDescription(currentAchievement.getString("desc"));
         achievementsList.add(achievement);
       }
     }
   } catch (Exception e) {
     throw new RuntimeException(e.getMessage());
   }
 }
コード例 #4
0
 public void startNewAchievementActivity(Achievement achievement) {
   try {
     Intent intent = new Intent();
     intent.putExtra("display_name", achievement.getDisplayName());
     intent.putExtra("pic", achievement.getPictureLink());
     intent.putExtra("desc", achievement.getDescription());
     intent.setClass(activity, NewAchievementActivity.class);
     activity.startActivity(intent);
     finishBackgroundProcess();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }