let health = 50
async function fight(){
addKeysEvents();
return new Promise((resolve) =>
})
}
function damage(){
health = health -10;
}
function addKeysEvents(){
document.addEventListener('keydown', function(event){
if (event.code == 'KeyQ'){
damage();
}
})
}
fight()
if (health <= 0){
console.log("финиш бл*");
}
function damage(){
health -= 10;
}
function addKeysEvents(){
document.addEventListener('keydown', function(event){
if (event.key == 'Q'){
damage();
}
})
}
let health = 50;
const bus = new EventEmitter();
function fight(){
addKeysEvents();
return new Promise((res, rej) => {
bus.subscribe(e => {
if (e.type === 'gameover') {
bus.unsubscribe();
res();
}
})
})
}
function damage(){
health = health -10;
if (health <= 0) {
bus.trigger('gameover');
}
}
function addKeysEvents(){
document.addEventListener('keydown', function(event){
if (event.code == 'KeyQ'){
damage();
}
})
}
await fight();
console.log('The game is over now!');
let health = 50;
function fight(){
// конструктор напиши если не будет работать метод stop
this.stop = function(){
console.log("финиш");
}
this.damage = function(){
health -= 10;
}
document.addEventListener('keydown', function(event){
if (event.code == 'KeyQ'){
fight.damage();
}
});
}
fight();
if(health == 50){
fight.stop();
}
let health = 50
async function fight(){
return new Promise((resolve) => {
document.addEventListener(health<=0, resolve());
}).then(console.log('finish'))
}
function damage(){
health = health -10;
}
function addKeysEvents(){
document.addEventListener('keydown', function(event){
if (event.code == 'KeyQ'){
damage();
}
})
}
Дуболом всегда выполняет просьбы
let health = 50;
function fight(){
// конструктор напиши если не будет работать метод stop
this.stop = function(){
console.log("финиш");
return false; // это для того, чтобы код функции застопорить
}
this.damage = function(){
health -= 10;
}
document.addEventListener('keydown', function(event){
if (event.code == 'KeyQ'){
fight.damage();
}
});
}
fight();
if(health <= 0){
fight.stop();
}
async function fight(){
addKeysEvents();
return new Promise((resolve) =>
health <= 0 && resolve('finish')
})
}
fight().then( v => { console.log(v) })
async function fight(){
addKeysEvents();
return new Promise((resolve) =>
})
}