Skip to content

Commit

Permalink
Revamp health system
Browse files Browse the repository at this point in the history
  • Loading branch information
bendem committed Oct 18, 2014
1 parent 77cb397 commit 44ad489
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
30 changes: 13 additions & 17 deletions src/main/java/be/bendem/bot/entities/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@ public abstract class Entity {

protected List<Dice> dices;
protected final String name;
protected int health;
protected int maxHealth;
private int currentHealth;

protected Entity(List<Dice> dices, String name, int maxHealth) {
this(dices, name, maxHealth, maxHealth);
}

protected Entity(List<Dice> dices, String name, int health, int maxHealth) {
protected Entity(List<Dice> dices, String name, int currentHealth) {
this.dices = dices;
this.name = name;
this.health = health;
this.maxHealth = maxHealth;
this.currentHealth = currentHealth;
}

public abstract boolean takeTurn(CampaignPart campaignPart, Random random);
Expand All @@ -41,20 +35,22 @@ public String getName() {
return name;
}

public int getHealth() {
return health;
public abstract int getMaxHealth();

public int getCurrentHealth() {
return currentHealth;
}

public void setHealth(int health) {
this.health = health;
public void damage(int damage) {
currentHealth -= damage > currentHealth ? currentHealth : damage;
}

public int getMaxHealth() {
return maxHealth;
public void heal(int heal) {
currentHealth += heal;
}

public void setMaxHealth(int maxHealth) {
this.maxHealth = maxHealth;
public boolean isDead() {
return currentHealth == 0;
}

}
12 changes: 10 additions & 2 deletions src/main/java/be/bendem/bot/entities/Monster.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
*/
public class Monster extends Entity {

protected Monster(List<Dice> dices, String name, int maxHealth) {
super(dices, name, maxHealth);
private final int maxHealth;

protected Monster(List<Dice> dices, String name, int health) {
super(dices, name, health);
maxHealth = health;
}

@Override
Expand All @@ -29,4 +32,9 @@ public Collection<Item> loot(Random random) {
return Collections.emptySet();
}

@Override
public int getMaxHealth() {
return maxHealth;
}

}
9 changes: 9 additions & 0 deletions src/main/java/be/bendem/bot/entities/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*/
public class Player extends Entity {

private static final int BASE_HEALTH = 20;
private static final int HEALTH_PER_LEVEL = 10;

private final List<Item> inventory;
private int level;

Expand All @@ -28,12 +31,18 @@ public boolean takeTurn(CampaignPart campaignPart, Random random) {
return false;
}

@Override
public int getMaxHealth() {
return BASE_HEALTH + level * HEALTH_PER_LEVEL;
}

public int getLevel() {
return level;
}

public void incrementLevel() {
level++;
// TODO Increment stats, give custom stat point(s), etc.
}

}

0 comments on commit 44ad489

Please sign in to comment.