From e928543e3fb6773eaab2a10ca993de2e8393764f Mon Sep 17 00:00:00 2001 From: JJTCM Date: Tue, 11 Nov 2014 13:19:41 +0100 Subject: [PATCH] More Error Handling for Score --- .../spacescooter/datastructure/Score.java | 15 +++++++++++---- .../spacescooter/entity/LivingEntity.java | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/de/teamteamteam/spacescooter/datastructure/Score.java b/src/de/teamteamteam/spacescooter/datastructure/Score.java index 408f888..f6e9346 100644 --- a/src/de/teamteamteam/spacescooter/datastructure/Score.java +++ b/src/de/teamteamteam/spacescooter/datastructure/Score.java @@ -3,6 +3,7 @@ package de.teamteamteam.spacescooter.datastructure; public class Score { private static int score = 0; + private static int maxScore = 99999999; public static int getScore() { return score; @@ -13,13 +14,19 @@ public class Score { } public static void addScore(int score) { - if (Score.score != 99999999) - Score.score += score; + if (Score.score + score >= Score.maxScore) { + Score.setScore(Score.maxScore); + } else if (Score.score != Score.maxScore) { + Score.score += score; + } } public static void removeScore(int score) { - if (Score.score != 0) - Score.score -= score; + if (Score.score - score <= 0) { + Score.setScore(0); + } else if (Score.score != 0) { + Score.score -= score; + } } } diff --git a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java index b760257..de38a41 100644 --- a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java @@ -115,7 +115,7 @@ public abstract class LivingEntity extends Entity implements Collidable, Hittabl this.healthPoints = 0; this.shieldPoints = 0; Score.addScore(ScorePoints); - if(this instanceof Enemy){ // Add 1 credit for the shop + if(this instanceof Enemy){ // Add 1 credit for the shop Credits.setCredits(Credits.getCredits() + 1); } if(GameConfig.DEBUG) System.out.println(this + " ist gestorben. RIP");