Improve battle command

This commit is contained in:
Daniel Odendahl Jr
2018-10-09 20:59:49 +00:00
parent 51e8bac784
commit bae943bff7
7 changed files with 110 additions and 67 deletions
+30
View File
@@ -0,0 +1,30 @@
const Battler = require('./Battler');
module.exports = class Battle {
constructor(user, opponent) {
this.user = new Battler(this, user);
this.opponent = new Battler(this, opponent);
this.userTurn = false;
}
get attacker() {
return this.userTurn ? this.user : this.opponent;
}
get defender() {
return this.userTurn ? this.opponent : this.user;
}
reset(changeGuard = true) {
if (changeGuard && this.user.guarding) this.user.changeGuard();
if (changeGuard && this.opponent.guarding) this.opponent.changeGuard();
this.userTurn = !this.userTurn;
return null;
}
get winner() {
if (this.user.hp <= 0) return this.opponent;
if (this.opponent.hp <= 0) return this.user;
return null;
}
};