所以,我和一些朋友正在用JavaScript制作视频游戏(文本冒险)。在这个游戏中,你去打怪怪物。它打开了,但是当你赢了,它随机地在URL的末尾加上'/ 1'。这很奇怪,因为window.location
永远不会出现在程序中。以下是问题发生时执行的代码:
function Places() {
location = 1
answer = prompt('Where do you go now? You have ' + totalGold + ' gold, and ' + hitPoints + ' health.', 'Town, Plains, Swamp, Menu').toUpperCase()
switch (answer) {
case 'TOWN':
if (aabeaDestroysTown === 0) {
alert('You walk into town, where there is a marketplace and an inn.')
InTown()
} else {
alert('As you near the outskirts of town, you notice the stream of people leaving town. Then you notice that the entire place is now just a gigantic blast crater. Somebody blew it up!!! You decide to investigate, and walk over to the stream of people.')
alert('When you reach the people, they all say this person named A\'Abea had just come to town and started fires all over, and then used some weird, magical powers to blow up Smatino.')
alert('You are sure this A\'Abea is the same as the one who you met in the swamp, and wish you had used some \'weird, magical powers\' to blow him up')
alert('You race back to the swamp, and see him from a distance. You can\'t, however, blow him up. There are too many vines in the way. So, you follow him. You see a large tower in the distance, and finally, after a few hours, reach it at night. You see A\'Abea enter, and then, as the gate is clanging down above him, you slide under it and manage to get in.')
inTower()
}
break;
等。您只能看到prompt()
框一瞬间,然后进行随机添加。
/*
Exception: out of memory
*/
更奇怪的是,它似乎只在Firefox中进行测试时才会这样做。
答案 0 :(得分:2)
这是因为您将window.location
设置为1
。除非您想更新页面网址,否则请不要这样做。
默认情况下,变量在全局window
对象上设置。如果您想在函数中设置名为location
的局部变量,请使用var location = 1
。