我对这种语言非常非常陌生,并且围绕"如何用东西做事"被证明是一项非常令人沮丧的努力。
我的目标是创建一个机制,其中某些房间是危险的,并且玩家在其中停留的时间越长,就越危险。如果玩家在危险的房间里呆得太久,就会触发死亡场景。
我有如下所示的代码:
[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 room
或 the 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.`
以这种方式引用对象属性的"正确"方法是什么?
这里的魔术词是" 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.
诀窍是给通知足够的信息,以了解您指的是哪个特定事物。原始问题中有问题的句子是人类可以解析的完全有效的英语,但是计算机需要更多的帮助来确定我们说"房间"时指的是什么房间。