mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
36 lines
866 B
JavaScript
36 lines
866 B
JavaScript
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;
|
|
this.turn = 1;
|
|
this.lastTurnTimeout = false;
|
|
this.endedDueToInactivity = 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.guard) this.user.changeGuard();
|
|
if (changeGuard && this.opponent.guard) this.opponent.changeGuard();
|
|
this.userTurn = !this.userTurn;
|
|
this.turn++;
|
|
return this.turn;
|
|
}
|
|
|
|
get winner() {
|
|
if (this.endedDueToInactivity) return 'time';
|
|
if (this.user.hp <= 0) return this.opponent;
|
|
if (this.opponent.hp <= 0) return this.user;
|
|
return null;
|
|
}
|
|
};
|