对于模糊的标题感到抱歉,我不确定如何构建这个标题的标题。
我正在为我的JS类项目构建一个游戏。我写的代码对我来说很有意义,但在实施时并没有正常工作,并且想知道我是否能够获得一些见解。
第一部分已经解决了,感谢团队!请进一步阅读以帮助第二部分!
function goStraight(){
if (transition == 0){
return;
}
if (transition == 1){
ctx.clearRect (0,0,500,500);
ctx.beginPath();
ctx.drawImage (blankPage,0,0);
continueGame = prompt("You have made it to the boss room, a powerful being with a lot of power: If you wish to continue type 'continue' if you wish to turn back and end your journey here type 'exit' !");
while (continueGame !== "continue" && continueGame !== "exit"){
continueGame = prompt("You have made it to the boss room, a powerful being with a lot of power: If you wish to continue type 'continue' if you wish to turn back and end your journey here type 'exit' !");
}
if (continueGame == "continue"){
ctx.clearRect (0,0,500,500);
ctx.beginPath();
ctx.drawImage (takeThis,0,0);
transition = 4;
return;
}
if (continueGame == "exit"){
startGame();
return;
}
}
我遇到问题的第二部分是"退出"部分。如果我执行"退出" if语句运行starGame()函数,即:
function startGame(){
ctx.clearRect (0,0,500,500);
ctx.beginPath();
ctx.drawImage (start,0,0);
transition = 0;
continueGame = 0;
document.getElementById("intro").onkeydown = function enterToStart(event){
if (event.keyCode === 13) {
centerRoom();
return;
}
}
}
但是当我尝试按"输入"再次启动游戏它会调出goStraight()的提示,我可以从中收集所有这些是由于某种原因,当我按下回车时仍然会调用该函数,因为输入应该使transition = 1并且提示应该只出现当过渡= 1时。
对于长篇大论的问题,再次抱歉。