1

我对这门语言非常非常陌生,并且将我的头脑围绕“如何用东西做事”被证明是一项非常令人沮丧的努力。

我的目标是创建一个机制,其中某些房间是危险的,并且玩家在其中停留的时间越长变得越危险。如果玩家在危险的房间里停留的时间过长,就会触发死亡场景。

我的代码如下所示:

[The "danger rule"]
A room has a number called danger level. The danger level of a room is usually 0.

Definition: A room is dangerous if its danger level is 1 or more.
Definition: A room is deadly if its danger level is 9 or more.

Every turn (this is the increasing danger rule):
    If the player is in a dangerous room:
        Increase danger level by 1.

Every turn (this is the death by danger rule):
    If the room is deadly:
        do nothing.[Later...]

Every turn (this is the danger explanation rule):
    say danger level.

[further down]

The Feeding Chamber is south of the dungeon."You enter a large, dimly lit room with straw on the floor, surrounded by various cages embedded in the wall.[line break]Blood spatters are all over the floor, and it looks as if there's been a fight recently". After going to the feeding chamber for the first time:
    try looking;
    say "It smells like grues around here. I would be careful if I were you..";

The Feeding Chamber has danger level 5.

我似乎无法弄清楚如何正确处理“房间的危险程度”。我定义的解释规则在进入危险房间时会导致运行时错误:

`*** Run-time problem P31: Attempt to use a property of the 'nothing' non-object: property danger level`

..并尝试将规则改写为类似the danger level of the roomthe danger level of this room导致令人困惑的编译消息,例如:

`In the sentence 'say the danger level of the room'  , it looks as if you intend 'danger level of the room' to be a property, but 'a room' is not specific enough about who or what the owner is.`

以这种方式引用对象属性的“正确”方法是什么?

4

1 回答 1

2

这里的神奇词是“ of the location”。如果我们暂时假设这是另一种编程语言,那么我写这篇文章的方式就好像我指的是一个类“ the room”,而不是当前被引用的类的一个实例“ the location”。

工作规则如下:

Every turn while the player is in a dangerous room:
        Increase danger level of the location by 1.

诀窍是向 Inform 提供足够的信息以了解您所指的特定事物。原始问题中的有问题的句子是人类可以解析的完全有效的英语,但是当我们说“房间”时,计算机需要更多帮助来确定我们的意思是什么房间。

于 2015-01-03T04:56:02.687 回答