11package engine ;
22
33import entity .Achievement ;
4- import entity .Wallet ;
54
65import java .io .IOException ;
76import java .util .logging .Logger ;
@@ -20,36 +19,38 @@ public class AchievementManager {
2019 private final int MAX_PERFECT_STAGE = 7 ;
2120
2221 // Variables related to Accuracy Achievement
23- private double highAccuracy ; // List of accuracy achievements
22+ private int highMaxCombo ; // List of accuracy achievements
2423
2524 // Variables related to Flawless Failure Achievement
2625 private boolean checkFlawlessFailure ;
2726
28- // Variables related to Best Friends Achievement
29- private boolean checkBestFriends ;
30-
3127 // Coin rewards update
3228 private int coinReward = 0 ;
3329
34- private final int [] ACCURACY_COIN_REWARD = {500 , 1500 , 2000 , 2500 };
30+ private final int [] COMBO_COIN_REWARD = {500 , 1500 , 2000 , 2500 };
3531 private final int [] PERFECT_COIN_REWARD = {200 , 400 , 800 , 2000 , 3000 , 4000 , 5000 };
3632 private final int FLAWLESS_FAILURE_COIN = 1000 ;
37- private final int BEST_FRIENDS_COIN = 1000 ;
33+ private final int PLAY_TIME_COIN = 1000 ;
34+
35+ private boolean checkPlayTimeAch ;
36+
3837
3938 // Variables needed for each achievement are loaded through a file.
4039 public AchievementManager () throws IOException {
4140 achievement = FileManager .getInstance ().loadAchievement ();
4241 this .currentPerfectLevel = achievement .getPerfectStage ();
43- this .highAccuracy = achievement .getHighAccuracy ();
42+ this .highMaxCombo = achievement .getHighmaxCombo ();
4443 this .checkFlawlessFailure = achievement .getFlawlessFailure ();
45- this .checkBestFriends = achievement .getBestFriends ();
4644 }
4745
4846 public int getAchievementReward () {
4947 return coinReward ;
5048 }
5149
5250 public void updateTotalPlayTime (int playTime ) {
51+ if (achievement .getTotalPlayTime () < 600 && achievement .getTotalPlayTime () + playTime >= 600 ) {
52+ coinReward += PLAY_TIME_COIN ;
53+ }
5354 achievement .setTotalPlayTime (playTime );
5455 }
5556
@@ -60,38 +61,44 @@ public void updateTotalScore(int score) {
6061 /**
6162 * Function to update the accuracy achievement.
6263 */
63- public void updateAccuracy ( double accuracy ) {
64- if (highAccuracy >= accuracy ) {
64+ public void updateMaxCombo ( int maxCombo ) {
65+ if (highMaxCombo >= maxCombo ) {
6566 return ;
6667 }
67- int accuracyGoal = (int )(highAccuracy /10 )*10 +10 ;
68- highAccuracy = accuracy ;
69- if (accuracyGoal < 70 ) {
70- accuracyGoal = 70 ;
68+ int maxComboGoal = 10 ;
69+ if (highMaxCombo < 10 ) {
70+ maxComboGoal = 10 ;
71+ } else if (highMaxCombo < 15 ) {
72+ maxComboGoal = 15 ;
73+ } else if (highMaxCombo < 20 ) {
74+ maxComboGoal = 20 ;
75+ } else if (highMaxCombo < 25 ) {
76+ maxComboGoal = 25 ;
7177 }
72- if (highAccuracy < accuracyGoal ) {
73- achievement .setHighAccuracy (highAccuracy );
78+ int rewardIndex = highMaxCombo / 5 - 1 ;
79+ highMaxCombo = maxCombo ;
80+ if (highMaxCombo < maxComboGoal ) {
81+ achievement .setHighMaxcombo (highMaxCombo );
7482 return ;
7583 }
76- int rewardIndex = accuracyGoal /10 -7 ;
7784 // When an accuracy achievement is reached, all lower achievements are achieved together.
78- if (highAccuracy >= 100 ) {
85+ if (highMaxCombo >= 25 ) {
7986 for (int i = rewardIndex ; i < 4 ; i ++) {
80- coinReward += ACCURACY_COIN_REWARD [i ];
87+ coinReward += COMBO_COIN_REWARD [i ];
8188 }
82- } else if (highAccuracy >= 90 ) {
89+ } else if (highMaxCombo >= 20 ) {
8390 for (int i = rewardIndex ; i < 3 ; i ++) {
84- coinReward += ACCURACY_COIN_REWARD [i ];
91+ coinReward += COMBO_COIN_REWARD [i ];
8592 }
86- } else if (highAccuracy >= 80 ) {
93+ } else if (highMaxCombo >= 15 ) {
8794 for (int i = rewardIndex ; i < 2 ; i ++) {
88- coinReward += ACCURACY_COIN_REWARD [i ];
95+ coinReward += COMBO_COIN_REWARD [i ];
8996 }
90- } else if (highAccuracy >= 70 ) {
91- coinReward += ACCURACY_COIN_REWARD [0 ];
97+ } else if (highMaxCombo >= 10 ) {
98+ coinReward += COMBO_COIN_REWARD [0 ];
9299 }
93100 // Save the updated achievement.
94- achievement .setHighAccuracy ( highAccuracy );
101+ achievement .setHighMaxcombo ( highMaxCombo );
95102 }
96103 /**
97104 * Check if the perfect achievement has been reached.
@@ -113,27 +120,18 @@ public void updateFlawlessFailure(double accuracy) {
113120 }
114121 }
115122
116- public void updateBestFriends (boolean checkTwoPlayMode ) {
117- if (!checkBestFriends && checkTwoPlayMode ) {
118- checkBestFriends = true ;
119- coinReward += BEST_FRIENDS_COIN ;
120- achievement .setBestFriends (true );
121- }
122- }
123-
124123 public void updateAllAchievements () throws IOException {
125124 FileManager .getInstance ().saveAchievement (achievement );
126125 }
127126
128- public void updatePlaying (int playtime , int max_lives , int LivesRemaining , int level ) throws IOException {
127+ public void updatePlaying (int maxCombo , int playtime , int max_lives , int LivesRemaining , int level ) throws IOException {
129128 updateTotalPlayTime (playtime );
130129 updatePerfect (max_lives ,LivesRemaining ,level );
130+ updateMaxCombo (maxCombo );
131131 }
132132
133- public void updatePlayed (double accuracy , int score , boolean multiPlay ) throws IOException {
134- updateAccuracy (accuracy );
133+ public void updatePlayed (double accuracy , int score ) throws IOException {
135134 updateTotalScore (score );
136135 updateFlawlessFailure (accuracy );
137- updateBestFriends (multiPlay );
138136 }
139137}
0 commit comments