function onContextMenu(e) {
e.preventDefault();
let deleteBtn = document.querySelector('.delete-btn');
deleteBtn.addEventListener('click', function() {
console.log(e.target.tagName);
});
showMenu(e.clientX, e.clientY);
document.addEventListener('click', onMouseClick, false);
}
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!');