@Test public void testBattleAchievementShouldBeFulfilled() throws Exception { AchievementBuilder achievementBuilder = new AchievementBuilder(); achievementBuilder.setId("TWO_COWS"); achievementBuilder.setName("Two Cows"); BattleStatisticsQuery cowQuery = new BattleStatisticsQuery(); cowQuery.setId(new Id("COW")); achievementBuilder.addBattleStatisticsRequirement(new BattleStatisticsRequirement(cowQuery, 2)); Achievement achievement = achievementBuilder.createAchievement(); CreaturePreset cowPreset = new CreaturePreset(); cowPreset.setId(new Id("COW")); cowPreset.setType("BEAST"); cowPreset.setHealth(1); cowPreset.setVisibility(Percentage.fromString("80%")); CauseOfDeath unarmedCauseOfDeath = CauseOfDeath.getUnarmedCauseOfDeath(); Statistics statistics = new Statistics(); Assert.assertFalse(achievement.isFulfilled(statistics)); statistics .getBattleStatistics() .addBattle(new Creature(cowPreset), unarmedCauseOfDeath, PartOfDay.DAWN); Assert.assertFalse(achievement.isFulfilled(statistics)); statistics .getBattleStatistics() .addBattle(new Creature(cowPreset), unarmedCauseOfDeath, PartOfDay.DAWN); Assert.assertTrue(achievement.isFulfilled(statistics)); }
@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; }
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()); } }
public void storeAchievements(ArrayList<Achievement> achi) { SharedPreferences.Editor editor = settings.edit(); for (Achievement achievement : achi) { editor.putString(achievement.getID(), achievement.getCompletionStatus()); } editor.commit(); }
@Override public int parseJson(JSONObject json) { // TODO Auto-generated method stub try { id = json.getString("id"); JSONObject fromObject = json.getJSONObject("from"); from = new From(fromObject.getString("id"), fromObject.getString("name")); createdTime = json.getString("created_time"); JSONObject applicationObject = json.getJSONObject("application"); application = new From(applicationObject.getString("id"), applicationObject.getString("name")); achievement = new Achievement(); JSONObject achiveObject = json.getJSONObject("achivement"); achievement.setId(achiveObject.getString("id")); achievement.setUrl(achiveObject.getString("url")); achievement.setType(achiveObject.getString("type")); achievement.setTitle(achiveObject.getString("title")); likes = new Like(); JSONObject likeObject = json.getJSONObject("likes"); JSONArray likeArray = likeObject.getJSONArray("data"); ArrayList<From> likeList = new ArrayList<From>(likeObject.getInt("count")); for (int i = 0; i < likeObject.getInt("count"); i++) { likeList.add( new From( likeArray.getJSONObject(i).getString("id"), likeArray.getJSONObject(i).getString("name"))); } likes = new Like(likeList, likeObject.getInt("count")); comments = new ArrayList<Comment>(); JSONObject commentObject = json.getJSONObject("comments"); JSONArray commentArray = commentObject.getJSONArray("data"); for (int i = 0; i < commentObject.getInt("count"); i++) { Comment tmp = new Comment(); tmp.setId(commentArray.getJSONObject(i).getString("id")); tmp.setFrom( new From( commentArray.getJSONObject(i).getJSONObject("from").getString("id"), commentArray.getJSONObject(i).getJSONObject("from").getString("name"))); tmp.setMessage(commentArray.getJSONObject(i).getString("message")); tmp.setCreateTime(commentArray.getJSONObject(i).getString("created_time")); comments.add(tmp); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return 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(); } }
@Test public void testMaximumVisitsAchievementsShouldWorkAsExpected() throws Exception { AchievementBuilder achievementBuilder = new AchievementBuilder(); achievementBuilder.setId("VISIT_ANY_DESERT_TWICE"); achievementBuilder.setName("Visit Any Desert Twice"); CounterMap<Id> maximumVisits = new CounterMap<>(); maximumVisits.incrementCounter(new Id("DESERT"), 2); achievementBuilder.setMaximumNumberOfVisits(maximumVisits); Achievement achievement = achievementBuilder.createAchievement(); Statistics statistics = new Statistics(); Assert.assertFalse(achievement.isFulfilled(statistics)); statistics.getExplorationStatistics().addVisit(new Point(0, 0, 0), new Id("DESERT")); Assert.assertFalse(achievement.isFulfilled(statistics)); statistics.getExplorationStatistics().addVisit(new Point(1, 1, 1), new Id("DESERT")); Assert.assertFalse(achievement.isFulfilled(statistics)); statistics.getExplorationStatistics().addVisit(new Point(0, 0, 0), new Id("DESERT")); Assert.assertTrue(achievement.isFulfilled(statistics)); }
@Test public void testVisitedLocationsBasedAchievementsShouldWorkAsExpected() throws Exception { AchievementBuilder achievementBuilder = new AchievementBuilder(); achievementBuilder.setId("VISIT_TWO_DIFFERENT_DESERTS"); achievementBuilder.setName("Visit Two Different Deserts"); CounterMap<Id> visitedLocations = new CounterMap<>(); visitedLocations.incrementCounter(new Id("DESERT"), 2); achievementBuilder.setVisitedLocations(visitedLocations); Achievement achievement = achievementBuilder.createAchievement(); Statistics statistics = new Statistics(); Assert.assertFalse(achievement.isFulfilled(statistics)); statistics.getExplorationStatistics().addVisit(new Point(0, 0, 0), new Id("DESERT")); Assert.assertFalse(achievement.isFulfilled(statistics)); statistics.getExplorationStatistics().addVisit(new Point(0, 0, 0), new Id("DESERT")); Assert.assertFalse(achievement.isFulfilled(statistics)); statistics.getExplorationStatistics().addVisit(new Point(1, 1, 1), new Id("DESERT")); Assert.assertTrue(achievement.isFulfilled(statistics)); }
@Override public void rewardPlayer(Player player, PlayerAchievementState state) { super.rewardPlayer(player, state); state.avatarIncrement(); }