My latest project involves developing a game using Vue.js with characters like tank, DPS, and healer.
data: {
tankHealth: 100,
healerHealth: 100,
dpsHealth: 100,
monsterHealth: 200,
gameRunning: false,
turns: [],
},
I've implemented a button that triggers a setInterval function where every second the tank and DPS characters attack the monster, while the healer heals one of the players. However, when it's the monster's turn to attack, I want it to randomly target one of the players as follows:
var monsterDamage = self.calculateDamage(10,20); // returns a random number between 10 and 20
var number = self.randomNumberFn(1,3);
// get a random number here so i can randomly pick a player to attack
switch(number) {
case 1:
self.dpsHealth -= monsterDamage;
if(self.dpsHealth <= 0) {
self.dpsHealth = 0;
break;
}
break;
case 2:
self.tankHealth -= monsterDamage;
if(self.tankHealth <= 0) {
self.tankHealth = 0;
break;
}
break;
case 3:
self.healerHealth -= monsterDamage;
if(self.healerHealth <= 0) {
self.healerHealth = 0;
break;
}
break;
}
A challenge arises when one of the players dies. In this scenario, I want the monster to attack only the remaining living players. However, in my current model, even if one player is deceased, the monster continues to target them.