1

我想在我的 Inform7 游戏中创建一个功能:

当玩家决定向北穿过人行横道时,解说员会在第一时间向玩家提示玩家有可能会死亡,如果玩家再次向北输入,则该事件将发生并且以 2 分之一的随机概率成功,玩家将能够前往花园。像这样:

        Instead of going north in the road for the second time when a random chance of 1 in 2 succeeds:
        say "Yay! You made it!";
        now the player is in the Garden.

        otherwise:
        say "The car crashed you instantly - without any hope, you lost your whole strength in your body…";
        end the game in death.

是的,这段代码不起作用..有人能帮我弄清楚如何使它工作吗?

4

1 回答 1

5

这段代码有两个问题:

  1. Inform 不允许whenfor the second time. (您可以反过来写,如“当 2 中 1 的随机机会第二次成功时”,但这意味着不同:它会在随机机会第二次成功时触发规则,也就是说,玩家第二次在过马路时幸存下来。)

  2. otherwise必须是if陈述的一部分;它不能与when子句一起使用。

要修复代码,您只需将“随机机会”条件移动到if语句中,然后更改标点符号,以便两个备选方案都属于同一规则:

[I added these lines to make a complete example...]
Road is a room.

Garden is a room, north of Road.

Instead of going north in the road for the first time:
    say "The road looks dangerous. You hesitate a moment, unsure if you really want to take the risk."

[And here's the fixed rule:]
Instead of going north in the road for the second time:
    if a random chance of 1 in 2 succeeds:
        say "Yay! You made it!";
        now the player is in the Garden;
    otherwise:
        say "The car crashed you instantly - without any hope, you lost your whole strength in your body…";
        end the game in death.
于 2013-05-10T18:31:37.620 回答