added health to characters

This commit is contained in:
Sem van der Hoeven
2020-06-02 23:40:25 +02:00
parent 087c3a7193
commit be0703ba61
3 changed files with 35 additions and 0 deletions

View File

@@ -99,6 +99,7 @@ public class MainGame extends ApplicationAdapter {
mapRenderer.getGameTiles()[1][1].visit(testCharacter);
mapRenderer.getGameTiles()[1][2].visit(character2);
this.team = new Team();
this.team.addMember(this.testCharacter, character2);
}
@@ -192,4 +193,8 @@ public class MainGame extends ApplicationAdapter {
public boolean hasCharacterSelected() {
return selectedCharacter != null;
}
public Team getTeam() {
return team;
}
}

View File

@@ -30,6 +30,12 @@ public class Team {
this.members = members;
}
public void addMember(GameCharacter... characters) {
for (GameCharacter gameCharacter : characters) {
this.members.insert(gameCharacter);
}
}
public GameCharacter get(GameCharacter character) {
for (GameCharacter cur : this.members) {
if (cur.equals(character)) {

View File

@@ -17,6 +17,7 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
protected HashSet<Ability> abilities;
protected boolean override;
protected TextureRegion textureRegion;
protected int health;
public GameCharacter(String name, Faction faction, TextureRegion textureRegion, Ability... abilities) {
super();
@@ -25,6 +26,7 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
this.abilities = new HashSet<>(Arrays.asList(abilities));
this.override = false;
this.textureRegion = textureRegion;
this.health = 100;
}
public String getName() {
@@ -39,6 +41,28 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
this.abilities.remove(ability);
}
public int getHealth() {
return health;
}
public void setHealth(int health) {
this.health = health;
}
public void heal(int amount) {
this.health += amount;
if (this.health > 100) this.health = 100;
}
public void damage(int amount) {
this.health -= amount;
if (this.health < 0) this. health = 0;
}
public boolean isDead() {
return this.health <= 0;
}
public void changeControl() {
this.override = !this.override;
}