好的,所以我要创建一个基于文本的探索类游戏。我想知道如何循环if / else语句以及重置变量。我拥有它,因此您扮演的角色从他的卧室开始,并且您必须键入命令以让角色跟随,例如环顾四周。如果您还可以帮助我用Java识别所有形式的相同单词(在任何地方都可以使用CAPS)。

    if (begin === 'look around')
{
  confirm('To your right is the door.Left is the dresser with some pictures on it and a mirror on the wall. In front of you is the cabinets with a TV on top. Behind you is the bed')
}
else if (begin === 'look')
{
  confirm('To your right is the door.Left is the dresser with some pictures on it and a mirror on the wall. In front of you is the cabinets with a TV on top. Behind you is the bed')
}
else if (begin === 'examine room')
{
  confirm('To your right is the door.Left is the dresser with some pictures on it and a mirror on the wall. In front of you is the cabinets with a TV on top. Behind you is the bed')
}
else if (begin === 'examine the room')
{
  confirm('To your right is the door.Left is the dresser with some pictures on it and a mirror on the wall. In front of you is the cabinets with a TV on top. Behind you is the bed')
}
else if (begin === '?')
{
  confirm('If you have not already noticed, this game is completely Text-based. In order to progress through the game, you will need to type in commands that you think the character you are playing as should do.Example: look around.')
}

最佳答案

我建议在while(true)内进行切换,如果出现问题,请中断。

关于javascript - 如何循环if/else语句(JavaScript)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24924032/

10-10 23:41