首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Inform7:处理房间的属性

Inform7:处理房间的属性
EN

Stack Overflow用户
提问于 2014-12-31 18:08:17
回答 1查看 262关注 0票数 1

我对这门语言非常非常陌生,把我的注意力集中在“如何用东西做事”上,这证明是一项非常令人沮丧的努力。

我在这里的目标是创造一个技工,在那里某些房间是危险的,并变得更危险的球员停留在他们的时间。如果玩家在危险的房间里呆得太久,就会触发死亡场景。

我有这样的代码:

代码语言:javascript
复制
[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.

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

代码语言:javascript
复制
`*** Run-time problem P31: Attempt to use a property of the 'nothing' non-object: property danger level`

..And试图将规则重新定义为类似于the danger level of the roomthe danger level of this room之类的内容,这会导致令人费解的编译消息,例如:

代码语言:javascript
复制
`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.`

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-03 04:56:02

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

工作规则如下:

代码语言:javascript
复制
Every turn while the player is in a dangerous room:
        Increase danger level of the location by 1.

诀窍是给出足够的信息来知道你指的是哪一件事情。原来的问题句是完全有效的英语,人类可以解析,但计算机需要更多的帮助,以确定我们指的是什么房间,当我们说“房间”。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27724727

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档