-
-
Notifications
You must be signed in to change notification settings - Fork 163
Persists achievements when we start the game/get a new one #342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7270a02
b031ed9
52a432f
8f8d940
de127f2
ee87307
68a73a4
2a86198
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,14 +1,27 @@ | ||||||||||||||
| package com.dinosaur.dinosaurexploder.achievements; | ||||||||||||||
|
|
||||||||||||||
| public abstract class Achievement { | ||||||||||||||
| import com.almasb.fxgl.dsl.FXGL; | ||||||||||||||
|
|
||||||||||||||
| protected boolean completed = false; | ||||||||||||||
| import java.io.Serializable; | ||||||||||||||
|
|
||||||||||||||
| public boolean isCompleted() { | ||||||||||||||
| return completed; | ||||||||||||||
| } | ||||||||||||||
| public abstract class Achievement implements Serializable { | ||||||||||||||
|
|
||||||||||||||
| public abstract void update(double tpf); | ||||||||||||||
| protected boolean completed = false; | ||||||||||||||
| protected int rewardCoins; | ||||||||||||||
|
Comment on lines
+9
to
+10
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| public abstract void onDinosaurKilled(); | ||||||||||||||
| public boolean isCompleted() { | ||||||||||||||
| return completed; | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+12
to
+14
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| public void onComplete(String description) { | ||||||||||||||
| FXGL.getNotificationService().pushNotification("Achievement unlocked: " + description); | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+16
to
+18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| public int getRewardCoins() { | ||||||||||||||
| return rewardCoins; | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+20
to
+22
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| public abstract void update(double tpf); | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| public abstract Boolean onDinosaurKilled(); | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||
| } | ||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,50 +1,82 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| package com.dinosaur.dinosaurexploder.achievements; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| import com.dinosaur.dinosaurexploder.constants.GameConstants; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.*; | ||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.ArrayList; | ||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| public class AchievementManager { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| private final List<Achievement> allAchievements = new ArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| private final List<Achievement> activeAchievements = new ArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| public AchievementManager() { | ||||||||||||||||||||||||||||||||||||||||||||||
| // Register all available achievements here | ||||||||||||||||||||||||||||||||||||||||||||||
| allAchievements.add(new KillCountAchievement(10, 50)); | ||||||||||||||||||||||||||||||||||||||||||||||
| allAchievements.add(new KillCountAchievement(20, 100)); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Called once when the game starts | ||||||||||||||||||||||||||||||||||||||||||||||
| public void init() { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (allAchievements.isEmpty()) return; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| activeAchievements.addAll(allAchievements); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Called every frame | ||||||||||||||||||||||||||||||||||||||||||||||
| public void update(double tpf) { | ||||||||||||||||||||||||||||||||||||||||||||||
| for (Achievement achievement : activeAchievements) { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!achievement.isCompleted()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| achievement.update(tpf); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Called when a dinosaur is killed | ||||||||||||||||||||||||||||||||||||||||||||||
| public void notifyDinosaurKilled() { | ||||||||||||||||||||||||||||||||||||||||||||||
| for (Achievement achievement : activeAchievements) { | ||||||||||||||||||||||||||||||||||||||||||||||
| achievement.onDinosaurKilled(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| public List<Achievement> getActiveAchievements() { | ||||||||||||||||||||||||||||||||||||||||||||||
| return activeAchievements; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| public Achievement getActiveAchievement() { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (activeAchievements.isEmpty()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| return activeAchievements.get(0); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| private final List<Achievement> allAchievements = new ArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| private final List<Achievement> activeAchievements = new ArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+11
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| public AchievementManager() { | ||||||||||||||||||||||||||||||||||||||||||||||
| // Register all available achievements here | ||||||||||||||||||||||||||||||||||||||||||||||
| allAchievements.add(new KillCountAchievement(1, 50)); | ||||||||||||||||||||||||||||||||||||||||||||||
| allAchievements.add(new KillCountAchievement(2, 50)); | ||||||||||||||||||||||||||||||||||||||||||||||
| allAchievements.add(new KillCountAchievement(10, 50)); | ||||||||||||||||||||||||||||||||||||||||||||||
| allAchievements.add(new KillCountAchievement(20, 100)); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Called once when the game starts | ||||||||||||||||||||||||||||||||||||||||||||||
| public void init() { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (allAchievements.isEmpty()) return; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| activeAchievements.addAll(loadAchievement()); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (activeAchievements.isEmpty()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| saveAchievement(allAchievements); | ||||||||||||||||||||||||||||||||||||||||||||||
| activeAchievements.addAll(allAchievements); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+26
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Called every frame | ||||||||||||||||||||||||||||||||||||||||||||||
| public void update(double tpf) { | ||||||||||||||||||||||||||||||||||||||||||||||
| for (Achievement achievement : activeAchievements) { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!achievement.isCompleted()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| achievement.update(tpf); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+33
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Called when a dinosaur is killed | ||||||||||||||||||||||||||||||||||||||||||||||
| public void notifyDinosaurKilled() { | ||||||||||||||||||||||||||||||||||||||||||||||
| for (Achievement achievement : activeAchievements) { | ||||||||||||||||||||||||||||||||||||||||||||||
| Boolean complete = achievement.onDinosaurKilled(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| saveAchievement(activeAchievements); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+42
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| public List<Achievement> getActiveAchievements() { | ||||||||||||||||||||||||||||||||||||||||||||||
| return activeAchievements; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+50
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| public Achievement getActiveAchievement() { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (activeAchievements.isEmpty()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| return activeAchievements.getFirst(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+54
to
+59
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /// Get the list of achievement save in the achievement.ser file | ||||||||||||||||||||||||||||||||||||||||||||||
| public List<Achievement> loadAchievement() { | ||||||||||||||||||||||||||||||||||||||||||||||
| List<Achievement> achievementFromFile = new ArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| try (ObjectInputStream in = | ||||||||||||||||||||||||||||||||||||||||||||||
| new ObjectInputStream(new FileInputStream(GameConstants.ACHIEVEMENTS_FILE))) { | ||||||||||||||||||||||||||||||||||||||||||||||
| achievementFromFile = (List<Achievement>) in.readObject(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } catch (IOException | ClassNotFoundException e) { | ||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("Failed to load achievements from file"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| return achievementFromFile; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+61
to
+71
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /// Save activeAchievement in the achievement.ser file | ||||||||||||||||||||||||||||||||||||||||||||||
| public void saveAchievement(List<Achievement> listToSave) { | ||||||||||||||||||||||||||||||||||||||||||||||
| try (ObjectOutputStream out = | ||||||||||||||||||||||||||||||||||||||||||||||
| new ObjectOutputStream(new FileOutputStream(GameConstants.ACHIEVEMENTS_FILE))) { | ||||||||||||||||||||||||||||||||||||||||||||||
| out.writeObject(listToSave); | ||||||||||||||||||||||||||||||||||||||||||||||
| } catch (IOException e) { | ||||||||||||||||||||||||||||||||||||||||||||||
| System.err.println("Error saving achievement : " + e.getMessage()); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+73
to
+81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,49 +1,37 @@ | ||||||||||||||||||||||||||||||||||||||||
| package com.dinosaur.dinosaurexploder.achievements; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| import com.almasb.fxgl.dsl.FXGL; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| public class KillCountAchievement extends Achievement { | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| private final int targetKills; | ||||||||||||||||||||||||||||||||||||||||
| private final int rewardCoins; | ||||||||||||||||||||||||||||||||||||||||
| private final int targetKills; | ||||||||||||||||||||||||||||||||||||||||
| private int currentKills = 0; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| private int currentKills = 0; | ||||||||||||||||||||||||||||||||||||||||
| private boolean completed = false; | ||||||||||||||||||||||||||||||||||||||||
| public KillCountAchievement(int targetKills, int rewardCoins) { | ||||||||||||||||||||||||||||||||||||||||
| this.targetKills = targetKills; | ||||||||||||||||||||||||||||||||||||||||
| this.rewardCoins = rewardCoins; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| public KillCountAchievement(int targetKills, int rewardCoins) { | ||||||||||||||||||||||||||||||||||||||||
| this.targetKills = targetKills; | ||||||||||||||||||||||||||||||||||||||||
| this.rewardCoins = rewardCoins; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| public String getDescription() { | ||||||||||||||||||||||||||||||||||||||||
| return "Kill " + targetKills + " dinosaurs"; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+6
to
+16
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| public String getDescription() { | ||||||||||||||||||||||||||||||||||||||||
| return "Kill " + targetKills + " dinosaurs"; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| public Boolean onDinosaurKilled() { | ||||||||||||||||||||||||||||||||||||||||
| if (completed) return (true); | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+19
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| public boolean isCompleted() { | ||||||||||||||||||||||||||||||||||||||||
| return completed; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| currentKills++; | ||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| public void onDinosaurKilled() { | ||||||||||||||||||||||||||||||||||||||||
| if (completed) return; | ||||||||||||||||||||||||||||||||||||||||
| if (currentKills >= targetKills) { | ||||||||||||||||||||||||||||||||||||||||
| completed = true; | ||||||||||||||||||||||||||||||||||||||||
| onComplete(getDescription()); | ||||||||||||||||||||||||||||||||||||||||
| return (true); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| return (false); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+23
to
+29
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| currentKills++; | ||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||
| public void update(double tpf) { | ||||||||||||||||||||||||||||||||||||||||
| // Not needed for count-based achievement | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+31
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if (currentKills >= targetKills) { | ||||||||||||||||||||||||||||||||||||||||
| completed = true; | ||||||||||||||||||||||||||||||||||||||||
| onComplete(); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||
| public void update(double tpf) { | ||||||||||||||||||||||||||||||||||||||||
| // Not needed for count-based achievement | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| public void onComplete() { | ||||||||||||||||||||||||||||||||||||||||
| FXGL.getNotificationService().pushNotification("Achievement unlocked: " + getDescription()); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| public int getRewardCoins() { | ||||||||||||||||||||||||||||||||||||||||
| return rewardCoins; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,44 @@ | ||||||||||||||||||||
| package com.dinosaur.dinosaurexploder.achievements; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import com.dinosaur.dinosaurexploder.utils.LevelManager; | ||||||||||||||||||||
| import org.junit.jupiter.api.AfterEach; | ||||||||||||||||||||
| import org.junit.jupiter.api.BeforeEach; | ||||||||||||||||||||
| import org.junit.jupiter.api.Test; | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
Comment on lines
+4
to
+7
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||
| import java.awt.*; | ||||||||||||||||||||
| import java.util.ArrayList; | ||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| public class AchievementTest { | ||||||||||||||||||||
|
|
||||||||||||||||||||
| private LevelManager levelManager; | ||||||||||||||||||||
| private List<Achievement> currentAchievement = new ArrayList<>(); | ||||||||||||||||||||
| AchievementManager achievementManager = new AchievementManager(); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @BeforeEach | ||||||||||||||||||||
| void setUp() { | ||||||||||||||||||||
|
Comment on lines
+15
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| List<Achievement> emptyList = new ArrayList<>(); | ||||||||||||||||||||
| currentAchievement = achievementManager.loadAchievement(); | ||||||||||||||||||||
| achievementManager.saveAchievement(emptyList); | ||||||||||||||||||||
| achievementManager.init(); | ||||||||||||||||||||
|
Comment on lines
+22
to
+25
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| } | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💄Spotless - Format] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| @Test | ||||||||||||||||||||
| void achievementSaveInFile() { | ||||||||||||||||||||
| List<Achievement> listToCheck; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| achievementManager.getActiveAchievement().completed = true; | ||||||||||||||||||||
| achievementManager.saveAchievement(achievementManager.getActiveAchievements()); | ||||||||||||||||||||
| listToCheck = achievementManager.loadAchievement(); | ||||||||||||||||||||
| assert listToCheck.getFirst().isCompleted(); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @AfterEach | ||||||||||||||||||||
| void setAchievementBack() { | ||||||||||||||||||||
|
|
||||||||||||||||||||
| achievementManager.saveAchievement(currentAchievement); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[💄Spotless - Format] reported by reviewdog 🐶