export function fight(firstFighter, secondFighter) {
// Обьявление переменных
let promise = new Promise(function(resolve, reject){
let intervalId = setInterval(winner = function(){
let timeout1 = setTimeout(function () {
damage = getDamage(firstFighter, secondFighter);
if (damage > 0) {
console.log(secondFighterHealth + "-" + damage);
secondFighterHealth -= damage;
} else {
console.log('Второй блокировал удар первого!');
}
if (secondFighterHealth <= 0) {
window.winner = firstFighter;
clearInterval(intervalId);
resolve(winner);
clearTimeout(timeout2);
}
console.log('Second Health: ' + secondFighterHealth);
console.log('PAUSE!');
}, 250);
let timeout2 = setTimeout(function(){
damage = getDamage(secondFighter, firstFighter);
if (damage > 0) {
console.log(firstFighterHealth + "-" + damage);
firstFighterHealth -= damage;
} else {
console.log('Первый блокировал удар второго!');
}
if (firstFighterHealth <= 0) {
window.winner = secondFighter;
clearInterval(intervalId);
resolve(winner);
clearTimeout(timeout1);
}
console.log('First Health: ' + firstFighterHealth);
console.log('PAUSE!');
}, 500);
}, 750);
});
promise.then(function(){
console.log(window.winner.name);
});
}
Вызов fight?
const winner = fight(...selectedFighters.values());
showWinnerModal(winner);
Как достать значение winner?