Итак, у меня есть функция, которая проверяет, нажали ли вы «n» или «y», когда вы нажимаете «n», фигура атакует вас, после того как она должна удалить слушателя события, а затем дает вам шанс чтобы выиграть бой, но перед этим есть экран, который говорит, нажмите любую клавишу, чтобы продолжить, но этот экран не отображается. Помощь
Я работал над этим некоторое время, и он просто не работает, он не удаляет прослушиватель событий.
Это код начального экрана, после именования вашего персонажа и прочего
document.body.innerHTML = "<h4>As you are walking to the bar at a pub, a dark, hooded figure, pulls you aside to a corner: 'Listen, I have a job for you...'</h4><h2>Press 'Y' to accept, and 'N' to turn back to the bar</h2><img id='hoodedFigure' src='https://render.fineartamerica.com/images/rendered/default/print/6.125/8.000/break/images-medium/the-hooded-figure-kayleigh-semeniuk.jpg'>";
// Затем добавляется прослушиватель событий:
var event1 = window.addEventListener("keydown", checkKeyPressed, false);
// Это функция, которую она вызывает:
{if (evt.keyCode == "89") {
changeContentOnPressY(1);
} if (evt.keyCode == "78") {
changeContentOnPressN(1);
}}}```
//Then it calls this function to change the screen:
```function changeContentOnPressN(num) {
if (num == 1) {
window.removeEventListener("keydown", checkKeyPressed, false);
document.body.innerHTML = "The strange figure draws his weapons and agresses on you. You draw your small blade, and attempt to slash his stomach.<h3 style='text-align:center;'>Press any key to continue...</h3>";
window.addEventListener("keydown", chance(1), false);
} if(num == 2) {
window.addEventListener("keydown", checkKeyPressed2, false);
document.body.innerHTML = ""; // for 2nd n path}}```
//This is the part that is not working:
```window.removeEventListener("keydown", checkKeyPressed, false);```
This is the chance() function:
```function chance(num) {
if (num == 1) {
var chance = Math.random(0.1, 1);
if (chance >= 0.80) {
document.body.innerHTML = "Suddenly a swaggering figure walks towards you he says intrduces himself as Jean-Jacques le Tourment des Ombres, Grand Connoisseur of the Ombres House, he says 'You made the right choice, he was not to be trusted. I too dont like the Sabbath Family. Together we can get revenge'. Press Y to accept and N top refuse";
} else {
document.body.innerHTML = "He quickly slits your right wrist, and collects the blood spilled in a barrel. Soon nobles will enjoy this aged red. <br> <h1 style='text-align:center;'>GAME OVER<h1><br><h3 style='text-align:center;'>Press any key to continue...</h3>";
window.addEventListener("keydown", startGame1, false);}}}}```