我对这门语言非常非常陌生,并且将我的头脑围绕“如何用东西做事”被证明是一项非常令人沮丧的努力。
我的目标是创建一个机制,其中某些房间是危险的,并且玩家在其中停留的时间越长变得越危险。如果玩家在危险的房间里停留的时间过长,就会触发死亡场景。
我的代码如下所示:
[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.`
以这种方式引用对象属性的“正确”方法是什么?