锁定Inform7中的门可以在一个案例中工作但不能在另一个案例中工作

时间:2017-04-06 10:16:09

标签: inform7

希望此标记上有人活跃,我会在此处发出有关Inform7的问题。我们目前在大学使用这种语言来接触组中拼接项目和任务的结构。

当前任务是在按下按钮时解锁门并在转动一圈后将其关闭。我使用的代码如下:

import random
from collections import OrderedDict

######################
# Class: NamedObject #
######################

class NamedObject(object):
    def __init__(self, name):
        self.name = name

    def get_name(self):
        return self.name

#######################
# Class: MobileObject #
#######################

class MobileObject(NamedObject):
    def __init__(self, name, place):
        super().__init__(name)
        self.place = place

    def get_place(self):
        return self.place

################
# Class: Thing #
################

class Thing(MobileObject):
    def __init__(self, name):
        super().__init__(name, None)
        self.owner = None

    def set_owner(self, owner):
        self.owner = owner

    def get_owner(self):
        return self.owner

    def is_owned(self):
        return self.owner is not None

#################
# Class: Person #
#################

class Person(LivingThing):
    def __init__(self, name, health, threshold):
        self.inventory = []
        super().__init__(name, health, threshold)

    def take(self, thing):
        # Can only take things in current location and not owned by others
        if isinstance(thing, Thing) and thing in self.place.objects and not thing.is_owned():
            thing.set_owner(self)
            self.inventory.append(thing)
            self.place.del_object(thing)
            GAME_LOGGER.add_event("TOOK", self, thing)
        else:
            GAME_LOGGER.warning("{} cannot take {}.".format(self.get_name(), thing.get_name()))

    def remove_item(self, thing):
        #Can only remove things in inventory
        if isinstance(thing, Thing) and thing in self.get_inventory() and thing.get_owner()==self:
            thing.set_owner(None)
            self.inventory.remove(thing)
        else:
            GAME_LOGGER.warning("{} does not own {}.".format(self.get_name(), thing.get_name()))

    def go(self, direction):
        new_place = self.place.get_neighbor_at(direction.upper())
        if new_place is not None:
            self.move_to(new_place)
        else:
            GAME_LOGGER.warning("{} cannot go {} from {}".format(self.get_name(), direction, self.get_place().get_name()))

    def get_inventory(self):
        return list(self.inventory)

    def objects_around(self):
        return list(filter(lambda t: t is not self, self.get_place().get_objects()))

    def get_exits(self):
        return self.get_place().get_exits()`



class Weapon(Thing):

    def __init__(self, name, min_dmg, max_dmg):
        self.name=name
        self.min_dmg=min_dmg
        self.max_dmg=max_dmg

    def min_damage(self):
        return self.min_dmg

    def max_damage(self):
        return self.max_dmg

    def damage(self):
        return random.randint(self.min_dmg,self.max_dmg)

class RangedWeapon(Weapon):

    def __init__(self, name, min_dmg, max_dmg):
        super().__init__(name, min_dmg, max_dmg)
        self.shots=0

    def shots_left(self):
        return self.shots

    def load(self, ammo):
        if ammo.weapon_type()==self.name:
            self.shots+=ammo.get_quantity()
            ammo.remove_all()

    def damage(self):
        if self.shots==0:
            return 0
        else:
            self.shots-=1
            return super().damage()

我使用doorOpen作为属性来检查门是否打开。现在的问题是,我可以按下按钮,进入打开的房间,它说门正在关闭,但我可以走出房间没有任何问题,它似乎从现在开始解锁。

另一方面,我有其他代码:

TuerSiT是一扇门。它位于R024以南和Flur005R以北。它被锁定了。

Sicherheitsausweis解锁了TuerSiT。

doorOpen is a number which varies. doorOpen is 0. [ = false]

TuerK is a door. It is south of Flur006R and north of R028a. It is locked.
Tbutton_flur is in Flur006R. Tbutton_flur can be pushed.
Instead of pushing Tbutton_flur:
    now TuerK is unlocked;
    say "Die Tür öffnet sich";
    now doorOpen is 2;

Every turn when doorOpen is 1:
    now doorOpen is 0;
    now TuerK is locked;
    say "Door closes!".

Every turn when doorOpen is 2:
    decrement doorOpen.

Tbutton_raum is in R028a. Tbutton_raum can be pushed.
Instead of pushing Tbutton_raum:
    now TuerK is unlocked;
    say "Door opens!";
    now doorOpen is 2;

Before going to R024: if player is holding Sicherheitsausweis: now TuerSiT is unlocked; say "Der Sicherheitsausweis hat die Tür entsperrt"; otherwise: now TuerSiT is locked. 完全正常的地方。

我做错了什么吗?我还试图创建隐藏的钥匙以解锁,因为这是我认为问题所在,但似乎我无法锁定门。

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:2)

所以看来首先必须关上门,这是我没有在另一扇门上测试的东西。所以

now the door is closed;
now the door is locked.

一切正常。