From 9dca8d0f3610e2cd1079f9705f1da31ff19aba93 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 19 Nov 2018 09:12:42 +0100 Subject: Add Actor.SkillSet, remove useless members in various strucutres --- src/Actor.java | 95 ++++++++++++++++++++++----------------------------------- src/Battle.java | 4 +-- src/Map.java | 26 ++++++++-------- src/Weapon.java | 34 ++++++++------------- 4 files changed, 63 insertions(+), 96 deletions(-) diff --git a/src/Actor.java b/src/Actor.java index ef63217..b4d34aa 100644 --- a/src/Actor.java +++ b/src/Actor.java @@ -1,18 +1,20 @@ public class Actor { - // TODO: make final - private String name; - // TODO: could be replaced with `bool isAlive() { return this.hp > 0; }` - private boolean alive; + private final String name; + // TODO: enemy should not be binary (ex clans / groups / factions) - private boolean enemy; + private boolean isEnemy; private int hp; - // TODO: pack abilities / bonus / powers in structures - private int agility; - private int strenght; - private int defense; private int x; private int y; + + public class SkillSet { + public int agility; + // public int strenght; + // public int defense; + } + + public SkillSet skills; private Weapon weapon; private int actionsLeft; @@ -20,26 +22,39 @@ public class Actor { private int actions = 2; // TODO: make bonus / power-ups structure - public Actor(String name, int hp, boolean enemy, int agility) { + public Actor(String name, int hp, boolean isEnemy, int agility) { this.name = name; this.hp = hp; - this.enemy = enemy; - this.agility = agility; + this.isEnemy = isEnemy; + + this.skills = new SkillSet(); + this.skills.agility = agility; + // TODO: puch should have infinite durability this.weapon = new Weapon("fist", 1, 1, 10000000); - this.alive = true; this.resetActions(); } + public String getName() { return this.name; } + + public int getX() { return this.x; } + public int getY() { return this.y; } + + public Weapon getWeapon() { return this.weapon; } + public void equipWeapon(Weapon weapon) { this.weapon = weapon; } + + public void setHP(int hp) { this.hp = hp; } + public int getHP() { return this.hp; } + + public final SkillSet getSkills() { return this.skills; } + + public int getActionsLeft() { return this.actionsLeft; } + public void resetActions() { this.actionsLeft = this.actions; } - public int getActionsLeft() { - return this.actionsLeft; - } - public boolean hit(Actor actor, Map map) { if (this.actionsLeft > 0) { if (this.weapon.damage(this, actor, map)) { @@ -50,55 +65,17 @@ public class Actor { return false; } - public Weapon getWeapon() { - return this.weapon; - } - - public void equipWeapon(Weapon weapon) { - this.weapon = weapon; - } - - // TODO: could be `return this.hp > 0` and remove member public boolean isAlive() { - return this.alive; + return this.hp > 0; } - public void setHP(int hp) { - this.hp = hp; - if (this.hp <= 0) { - this.alive = false; - } + + public boolean isEnemy() { + return this.isEnemy; } public void damage(int dmg) { this.hp -= dmg; - if (this.hp <= 0) { - this.alive = false; - } - } - - public int getAgility() { - return this.agility; - } - - public String getName() { - return this.name; - } - - public int getHP() { - return this.hp; - } - - public int getX() { - return this.x; - } - - public int getY() { - return this.y; - } - - public boolean isEnemy() { - return this.enemy; } public void move(int x, int y) { diff --git a/src/Battle.java b/src/Battle.java index 6f614eb..cde2734 100644 --- a/src/Battle.java +++ b/src/Battle.java @@ -133,7 +133,7 @@ public class Battle extends MapScene { g.fillRect(20*this.guiSize, 22*this.guiSize, 70*this.guiSize*this.lastActor.getHP()/10, 10*this.guiSize); g.setColor(Palette.BLACK); - g.drawString("Agility: " + Integer.toString(this.lastActor.getAgility()), + g.drawString("Agility: " + Integer.toString(this.lastActor.getSkills().agility), 5*this.guiSize, 45*this.guiSize); } else if (this.actorClicked) { g.setColor(Palette.WHITE_T); @@ -269,7 +269,7 @@ public class Battle extends MapScene { this.map.clearSelected(); ArrayList path = this.map.getPath(this.selectedActor, x, y); Collections.reverse(path); - for (int i=0; i getActors() { diff --git a/src/Weapon.java b/src/Weapon.java index de6eb26..f20e0ca 100644 --- a/src/Weapon.java +++ b/src/Weapon.java @@ -1,54 +1,44 @@ // TODO: there are object such as "puch" that need infinite durability public class Weapon { - private boolean broken; // TODO: if possible make final private int damage; private int durability; private int range; private String name; + // TODO: add bonus / power-ups structure + // public class PowerUps {} public Weapon(String name, int damage, int range, int durability) { this.name = name; this.damage = damage; this.range = range; this.durability = durability; - - this.broken = false; } - public String getName() { - return this.name; - } + /* accessors */ + public String getName() { return this.name; } + public int getDamage() { return this.damage; } + public int getRange() { return this.range; } + public int getDurability() { return this.durability; } - public int getDamage() { - return this.damage; + + public boolean isBroken() { + return this.durability <= 0; } public boolean damage(Actor attacker, Actor attacked, Map map) { - if (this.broken) { + if (isBroken()) { return false; } - // TODO: bugfix durability-- iff damage has been done - this.durability--; - if (this.durability <= 0) { - this.broken = true; - } - if (map.getTile(attacked.getX(), attacked.getY()).isSelected()) { attacked.damage(this.damage); + this.durability--; return true; } else { return false; } } - public int getRange() { - return this.range; - } - - public int getDurability() { - return this.durability; - } } -- cgit v1.2.1