From 7a9766788a1f71cf1aee3d77c0f3bd7534b90891 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 28 Nov 2014 21:22:41 +0100 Subject: [PATCH] Move methods to increase health and shield points to LivingEntity, cap them ad their maximum value. --- .../spacescooter/entity/LivingEntity.java | 22 ++++++++++++++++++ .../spacescooter/entity/Player.java | 23 +------------------ .../spacescooter/entity/item/ItemHeal.java | 2 +- .../spacescooter/entity/item/ItemShield.java | 2 +- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java index 77ae16e..5d9c7d2 100644 --- a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java @@ -134,6 +134,17 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable public void setHealthPoints(int hp) { this.healthPoints = hp; } + + /** + * Add the given number of points to the current health points. + * Capped at maximum health points. + */ + public void addHealthPoints(int hp) { + this.healthPoints += hp; + if(this.healthPoints > this.maximumHealthPoints) { + this.healthPoints = this.maximumHealthPoints; + } + } /** * Get the current health points. @@ -156,6 +167,17 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable public void setShieldPoints(int sp) { this.shieldPoints = sp; } + + /** + * Add the given number of points to the current shield points. + * Capped at maximum shield points. + */ + public void addShieldPoints(int sp) { + this.shieldPoints += sp; + if(this.shieldPoints > this.maximumShieldPoints) { + this.shieldPoints = this.maximumShieldPoints; + } + } /** * Get the current shield points. diff --git a/src/de/teamteamteam/spacescooter/entity/Player.java b/src/de/teamteamteam/spacescooter/entity/Player.java index 4a52b3b..8c48a57 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -17,7 +17,7 @@ import de.teamteamteam.spacescooter.sound.SoundSystem; public class Player extends ShootingEntity implements KeyboardListener { /** - * the Player's Keyboard + * the Players Keyboard */ private Keyboard keyboard = null; @@ -164,27 +164,6 @@ public class Player extends ShootingEntity implements KeyboardListener { */ public void keyTyped(KeyEvent e) {} - /** - * method for increasing the HealthPoints with the Heal-Item - */ - public void increaseHealthPoints(int inc) { - if (this.getHealthPoints() <= (PlayerSession.getShipHealthPoints() - 15)) { - this.setHealthPoints(getHealthPoints() + inc); - } else { - this.setHealthPoints(PlayerSession.getShipHealthPoints()); - } - } - - /** - * method for increasing the ShieldPoints with the Shield-Item - */ - public void increaseShieldPoints(int inc) { - if (this.getShieldPoints() <= (PlayerSession.getShipShieldPoints() - 5)) { - this.setShieldPoints(getShieldPoints() + inc); - } else { - this.setShieldPoints(PlayerSession.getShipShieldPoints()); - } - } /** * Get the current rocket amount. diff --git a/src/de/teamteamteam/spacescooter/entity/item/ItemHeal.java b/src/de/teamteamteam/spacescooter/entity/item/ItemHeal.java index 6dc11a9..e9fe589 100644 --- a/src/de/teamteamteam/spacescooter/entity/item/ItemHeal.java +++ b/src/de/teamteamteam/spacescooter/entity/item/ItemHeal.java @@ -11,6 +11,6 @@ public class ItemHeal extends Item { @Override public void itemCollected(Player player) { - player.increaseHealthPoints(15); + player.addHealthPoints(15); } } diff --git a/src/de/teamteamteam/spacescooter/entity/item/ItemShield.java b/src/de/teamteamteam/spacescooter/entity/item/ItemShield.java index 6a0386f..a3e3838 100644 --- a/src/de/teamteamteam/spacescooter/entity/item/ItemShield.java +++ b/src/de/teamteamteam/spacescooter/entity/item/ItemShield.java @@ -11,6 +11,6 @@ public class ItemShield extends Item { @Override public void itemCollected(Player player) { - player.increaseShieldPoints(5); + player.addShieldPoints(5); } }