alexander909090,
function Fighter(name, damage, strenght, agility, hp) {
this.name = name;
this.damage = damage;
this.strength = strenght;
this.agility = agility;
this.hp = hp;
this.getName=function() {
return this.name;
}
this.getDamage=function() {
return this.damage;
}
this.getStrenght=function() {
return this.strength;
}
this.getAgility=function() {
return this.agility;
}
this.getHealth=function() {
return this.hp;
}
}
const myFighter1 = new Fighter('Maximus',25,1,1,100);
let name1 = myFighter1.getName();
let damage1 = myFighter1.getDamage();
let strenght1 = myFighter1.getStrenght();
let agility1 = myFighter1.getAgility();
let health1 = myFighter1.getHealth();
const myFighter2 = new Fighter('Commod',25,25,25,90);
let name2 = myFighter2.getName();
let damage2 = myFighter2.getDamage();
let strenght2 = myFighter2.getStrenght();
let agility2 = myFighter2.getAgility();
let health2 = myFighter2.getHealth();
//console.log(name2)
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
function attack(fighter) {
let hp=fighter.getHealth();
let damage=fighter.getDamage();
let success = 100-(fighter.getAgility()+fighter.getStrenght());
let rand_number = getRandomInt(101);
if (rand_number < success) {
hp=hp-damage;
} else {
hp=hp-0;
};
fighter.hp = hp;
return hp
}
console.log(attack(myFighter2));
console.log(attack(myFighter2));
console.log(attack(myFighter2));