summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-11-19 09:12:42 +0100
committerNao Pross <naopross@thearcway.org>2018-11-19 09:12:42 +0100
commit9dca8d0f3610e2cd1079f9705f1da31ff19aba93 (patch)
treef3e421cf2e8e676bbeec2fb111cd5930b4cb3031
parentUpdate makefile (diff)
downloadSubconscious-java-9dca8d0f3610e2cd1079f9705f1da31ff19aba93.tar.gz
Subconscious-java-9dca8d0f3610e2cd1079f9705f1da31ff19aba93.zip
Add Actor.SkillSet, remove useless members in various strucutres
Diffstat (limited to '')
-rw-r--r--src/Actor.java95
-rw-r--r--src/Battle.java4
-rw-r--r--src/Map.java26
-rw-r--r--src/Weapon.java34
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<Tile> path = this.map.getPath(this.selectedActor, x, y);
Collections.reverse(path);
- for (int i=0; i<this.selectedActor.getAgility(); i++) {
+ for (int i=0; i<this.selectedActor.getSkills().agility; i++) {
path.get(i).setSelected(true);
if (i == path.size()-1) {
break;
diff --git a/src/Map.java b/src/Map.java
index a870604..0e0d1e3 100644
--- a/src/Map.java
+++ b/src/Map.java
@@ -15,11 +15,11 @@ public class Map {
public Map(Dimension size) {
this.size = size;
- // TODO: replace with Dimension.height and Dimension.width which are integer public members
- this.grid = new Tile[(int) this.size.getWidth() * (int) this.size.getHeight()];
- for (int x = 0; x < this.size.getWidth(); x++) {
- for (int y = 0; y < this.size.getHeight(); y++) {
- this.grid[x * (int) this.size.getWidth() + y] = new Tile(Tile.Type.GRASS, x, y);
+ // Populate grid with GRASS tiles
+ this.grid = new Tile[this.size.width * this.size.height];
+ for (int x = 0; x < this.size.width; x++) {
+ for (int y = 0; y < this.size.height; y++) {
+ this.grid[x * this.size.width + y] = new Tile(Tile.Type.GRASS, x, y);
}
}
}
@@ -56,7 +56,7 @@ public class Map {
Tile workingTile = this.getTile(x, y);
double bestDistance = 1000000000;
Tile bestTile = workingTile;
-
+
while (true) {
for (Tile i : workingTile.getAdjacent(this)) {
if (i.getDistance() < bestDistance) {
@@ -79,15 +79,15 @@ public class Map {
// TODO: if this is needed for something, implement copy constructors for Actor and Tile
// and delete this code
for (Actor actor : actorsList) {
- Actor newActor = new Actor(actor.getName(), actor.getHP(), actor.isEnemy(), actor.getAgility());
+ Actor newActor = new Actor(actor.getName(), actor.getHP(), actor.isEnemy(), actor.getSkills().agility);
newActor.place(actor.getX(), actor.getY());
this.actors.add(newActor);
}
- for (int x = 0; x < this.size.getWidth(); x++) {
- for (int y = 0; y < this.size.getHeight(); y++) {
- Tile.Type oldTileType = tileGrid[x * (int) this.size.getWidth() + y].getType();
- this.grid[x * (int) this.size.getWidth() + y] = new Tile(oldTileType, x, y);
+ for (int x = 0; x < this.size.width; x++) {
+ for (int y = 0; y < this.size.height; y++) {
+ Tile.Type oldTileType = tileGrid[x * this.size.width + y].getType();
+ this.grid[x * this.size.width + y] = new Tile(oldTileType, x, y);
}
}
}
@@ -139,11 +139,11 @@ public class Map {
}
public Tile getTile(int x, int y) {
- return this.grid[x * (int) this.size.getWidth() + y];
+ return this.grid[x * this.size.width + y];
}
public int getSize() {
- return (int) this.size.getWidth();
+ return this.size.width;
}
public ArrayList<Actor> 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;
- }
}