Move methods to increase health and shield points to LivingEntity, cap them ad their maximum value.

This commit is contained in:
Jan Philipp Timme 2014-11-28 21:22:41 +01:00
parent 970ddb348f
commit 7a9766788a
4 changed files with 25 additions and 24 deletions

View File

@ -134,6 +134,17 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable
public void setHealthPoints(int hp) { public void setHealthPoints(int hp) {
this.healthPoints = 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. * Get the current health points.
@ -156,6 +167,17 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable
public void setShieldPoints(int sp) { public void setShieldPoints(int sp) {
this.shieldPoints = 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. * Get the current shield points.

View File

@ -17,7 +17,7 @@ import de.teamteamteam.spacescooter.sound.SoundSystem;
public class Player extends ShootingEntity implements KeyboardListener { public class Player extends ShootingEntity implements KeyboardListener {
/** /**
* the Player's Keyboard * the Players Keyboard
*/ */
private Keyboard keyboard = null; private Keyboard keyboard = null;
@ -164,27 +164,6 @@ public class Player extends ShootingEntity implements KeyboardListener {
*/ */
public void keyTyped(KeyEvent e) {} 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. * Get the current rocket amount.

View File

@ -11,6 +11,6 @@ public class ItemHeal extends Item {
@Override @Override
public void itemCollected(Player player) { public void itemCollected(Player player) {
player.increaseHealthPoints(15); player.addHealthPoints(15);
} }
} }

View File

@ -11,6 +11,6 @@ public class ItemShield extends Item {
@Override @Override
public void itemCollected(Player player) { public void itemCollected(Player player) {
player.increaseShieldPoints(5); player.addShieldPoints(5);
} }
} }