当前位置: 首页>>代码示例>>Python>>正文


Python Location.add_exits方法代码示例

本文整理汇总了Python中tale.base.Location.add_exits方法的典型用法代码示例。如果您正苦于以下问题:Python Location.add_exits方法的具体用法?Python Location.add_exits怎么用?Python Location.add_exits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tale.base.Location的用法示例。


在下文中一共展示了Location.add_exits方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_exits

# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import add_exits [as 别名]
 def test_exits(self):
     hall = Location("hall")
     attic = Location("attic")
     exit1 = Exit("ladder1", attic, "The first ladder leads to the attic.")
     exit2 = Exit("up", attic, "Second ladder to attic.")
     exit3 = Exit("ladder3", attic, "Third ladder to attic.")
     exit4 = Exit("window", attic, "A window.", "A window, maybe if you open it you can get out?")
     hall.add_exits([exit1, exit2, exit3, exit4])
     self.assertTrue(hall.exits["up"] is exit2)
     self.assertTrue(hall.exits["ladder3"] is exit3)
     self.assertTrue(hall.exits["window"] is exit4)
     self.assertEqual(['[hall]', 'The first ladder leads to the attic. Third ladder to attic. Second ladder to attic. A window.'], strip_text_styles(hall.look()))
     self.assertEqual("Third ladder to attic.", exit3.description)
     self.assertEqual("A window, maybe if you open it you can get out?", exit4.description)
     with self.assertRaises(ActionRefused):
         exit1.activate(None)
     with self.assertRaises(ActionRefused):
         exit1.deactivate(None)
     with self.assertRaises(ActionRefused):
         exit1.close(None, None)
     with self.assertRaises(ActionRefused):
         exit1.open(None, None)
     with self.assertRaises(ActionRefused):
         exit1.lock(None, None)
     with self.assertRaises(ActionRefused):
         exit1.unlock(None, None)
     with self.assertRaises(ActionRefused):
         exit1.manipulate("frobnitz", None)
     with self.assertRaises(ActionRefused):
         exit1.read(None)
开发者ID:jordanaycamara,项目名称:Tale,代码行数:32,代码来源:test_mudobjects.py

示例2: test_door_pair

# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import add_exits [as 别名]
    def test_door_pair(self):
        loc1 = Location("room1", "room one")
        loc2 = Location("room2", "room two")
        key = Key("key")
        door_one_two = Door("two", loc2, "door to room two", locked=True, opened=False)
        door_two_one = door_one_two.reverse_door("one", loc1, "door to room one", reverse_open_msg="door one open", reverse_close_msg="door one close",
                                                 this_open_msg="door two open", this_close_msg="door two close")
        loc1.add_exits([door_one_two])
        loc2.add_exits([door_two_one])
        door_one_two.key_code = 555
        key.key_for(door_one_two)
        pubsub1 = PubsubCollector()
        pubsub2 = PubsubCollector()
        loc1.get_wiretap().subscribe(pubsub1)
        loc2.get_wiretap().subscribe(pubsub2)
        self.assertTrue(door_two_one.locked)
        self.assertFalse(door_two_one.opened)
        lucy = Living("lucy", "f")

        door_two_one.unlock(lucy, item=key)
        self.assertFalse(door_one_two.locked)
        door_two_one.open(lucy)
        self.assertTrue(door_one_two.opened)
        pubsub.sync()
        self.assertEqual(["door one open"], pubsub1.messages)
        self.assertEqual([], pubsub2.messages)
        door_one_two.close(lucy)
        door_one_two.lock(lucy, item=key)
        self.assertTrue(door_two_one.locked)
        self.assertFalse(door_two_one.opened)
        pubsub1.clear()
        pubsub2.clear()
        pubsub.sync()
        self.assertEqual([], pubsub1.messages)
        self.assertEqual(["door two close"], pubsub2.messages)
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:37,代码来源:test_mudobjects.py

示例3: test_socialize

# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import add_exits [as 别名]
 def test_socialize(self):
     player = Player("fritz", "m")
     attic = Location("Attic", "A dark attic.")
     julie = NPC("julie", "f")
     julie.move(attic)
     player.move(attic)
     parsed = player.parse("wave all")
     self.assertEqual("wave", parsed.verb)
     self.assertEqual([julie], parsed.who_order)
     who, playermsg, roommsg, targetmsg = player.soul.process_verb_parsed(player, parsed)
     self.assertEqual({julie}, who)
     self.assertEqual("You wave happily at julie.", playermsg)
     with self.assertRaises(tale.soul.UnknownVerbException):
         player.parse("befrotzificate all and me")
     with self.assertRaises(NonSoulVerb) as x:
         player.parse("befrotzificate all and me", external_verbs={"befrotzificate"})
     parsed = x.exception.parsed
     self.assertEqual("befrotzificate", parsed.verb)
     self.assertEqual([julie, player], parsed.who_order)
     attic.add_exits([Exit("south", "target", "door")])
     try:
         player.parse("push south")
         self.fail("push south should throw a parse error because of the exit that is used")
     except ParseError:
         pass
     with self.assertRaises(NonSoulVerb):
         player.parse("fart south")
     parsed = player.parse("hug julie")
     player.validate_socialize_targets(parsed)
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:31,代码来源:test_player.py

示例4: test_aliases

# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import add_exits [as 别名]
 def test_aliases(self):
     loc = Location("hall", "empty hall")
     exit = Exit("up", "attic", "ladder to attic")
     door = Door("door", "street", "door to street")
     exit2 = Exit(["down", "hatch", "manhole"], "underground", "hatch to underground")
     door2 = Door(["east", "garden"], "garden", "door east to garden")
     self.assertEqual("up", exit.name)
     self.assertEqual("door", door.name)
     loc.add_exits([exit, door, exit2, door2])
     self.assertEqual({"up", "door", "down", "hatch", "manhole", "east", "garden"}, set(loc.exits.keys()))
     self.assertEqual(loc.exits["down"], loc.exits["hatch"])
开发者ID:jordanaycamara,项目名称:Tale,代码行数:13,代码来源:test_mudobjects.py

示例5: test_message_nearby_location

# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import add_exits [as 别名]
 def test_message_nearby_location(self):
     plaza = Location("plaza")
     road = Location("road")
     house = Location("house")
     attic = Location("attic")
     plaza.add_exits([Exit("north", road, "road leads north"), Exit("door", house, "door to a house")])
     road.add_exits([Exit("south", plaza, "plaza to the south")])
     house.add_exits([Exit("door", plaza, "door to the plaza"), Exit("ladder", attic, "dusty attic")])
     attic.add_exits([Exit("ladder", house, "the house")])
     wiretap_plaza = Wiretap(plaza)
     wiretap_road = Wiretap(road)
     wiretap_house = Wiretap(house)
     wiretap_attic = Wiretap(attic)
     util.message_nearby_locations(plaza, "boing")
     pubsub.sync()
     self.assertEqual([], wiretap_plaza.msgs, "the plaza doesnt receive tells")
     self.assertEqual([], wiretap_attic.msgs, "the attic is too far away to receive msgs")
     self.assertTrue(("road", "boing") in wiretap_road.msgs)
     self.assertTrue(
         ("road", "The sound is coming from the south.") in wiretap_road.msgs, "road should give sound direction"
     )
     self.assertTrue(("house", "boing") in wiretap_house.msgs)
     self.assertTrue(
         ("house", "You can't hear where the sound is coming from.") in wiretap_house.msgs,
         "in the house you can't locate the sound direction",
     )
开发者ID:sils1297,项目名称:Tale,代码行数:28,代码来源:test_util.py

示例6: test_destroy_loc

# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import add_exits [as 别名]
 def test_destroy_loc(self):
     ctx = Context()
     loc = Location("loc")
     i = Item("item")
     liv = Living("rat", "n", race="rodent")
     loc.add_exits([Exit("north", "somewhere", "exit to somewhere")])
     player = Player("julie", "f")
     player.privileges = {"wizard"}
     player.create_wiretap(loc)
     loc.init_inventory([i, liv, player])
     self.assertTrue(len(loc.exits) > 0)
     self.assertTrue(len(loc.items) > 0)
     self.assertTrue(len(loc.livings) > 0)
     self.assertEqual(loc, player.location)
     self.assertEqual(loc, liv.location)
     loc.destroy(ctx)
     self.assertTrue(len(loc.exits) == 0)
     self.assertTrue(len(loc.items) == 0)
     self.assertTrue(len(loc.livings) == 0)
     self.assertEqual(_Limbo, player.location)
     self.assertEqual(_Limbo, liv.location)
开发者ID:jordanaycamara,项目名称:Tale,代码行数:23,代码来源:test_mudobjects.py

示例7: test_nearby

# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import add_exits [as 别名]
 def test_nearby(self):
     plaza = Location("plaza")
     road = Location("road")
     house = Location("house")
     alley = Location("alley")  # no exits
     attic = Location("attic")
     plaza.add_exits([Exit("north", road, "road leads north"), Exit("door", house, "door to a house"),
                      Exit("west", alley, "small alleywith no way back")])
     road.add_exits([Exit("south", plaza, "plaza to the south")])
     house.add_exits([Exit("door", plaza, "door to the plaza"), Exit("ladder", attic, "dusty attic")])
     attic.add_exits([Exit("ladder", house, "the house")])
     adj = set(plaza.nearby())
     self.assertSetEqual({road, house}, adj)
     adj = set(plaza.nearby(no_traps=False))
     self.assertSetEqual({road, house, alley}, adj)
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:17,代码来源:test_mudobjects.py

示例8: test_custom_verbs

# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import add_exits [as 别名]
 def test_custom_verbs(self):
     player = Player("julie", "f")
     player.verbs["xywobble"] = "p1"
     monster = NPC("snake", "f")
     monster.verbs["snakeverb"] = "s1"
     room = Location("room")
     chair1 = Item("chair1")
     chair1.verbs["frobnitz"] = "c1"
     chair2 = Item("chair2")
     chair2.verbs["frobnitz"] = "c2"
     chair_in_inventory = Item("chair3")
     chair_in_inventory.verbs["kowabooga"] = "c3"
     box_in_inventory = Item("box")
     box_in_inventory.verbs["boxverb"] = "c4"
     player.init_inventory([box_in_inventory, chair_in_inventory])
     exit = Exit("e", "dummy", None, None)
     exit.verbs["exitverb"] = "c5"
     room.init_inventory([chair1, player, chair2, monster])
     room.add_exits([exit])
     custom_verbs = mud_context.driver.current_custom_verbs(player)
     all_verbs = mud_context.driver.current_verbs(player)
     self.assertEqual({"xywobble", "snakeverb", "frobnitz", "kowabooga", "boxverb", "exitverb"}, set(custom_verbs))
     self.assertEqual(set(), set(custom_verbs) - set(all_verbs))
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:25,代码来源:test_mudobjects.py

示例9: Door

# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import add_exits [as 别名]
                              "you prefer cooking your own meals -- unlike most of the other people you know in town. A window lets you look outside.")
kitchen.add_extradesc({"window", "outside"}, "Through the kitchen window you can see your small garden and behind that, the children's playground.")

#  Exits

front_door = Door(["door", "outside", "street"], "magnolia_st.street1", "Your front door leads outside, to the street.",
                  "There's a heavy front door here that leads to the streets outside.", opened=False)
house_door = front_door.reverse_door(["house", "north", "inside"], livingroom,
                                     "You can go back inside your house.", "It's your house, on the north side of the street.",
                                     reverse_open_msg="Someone outside opens the door.",
                                     reverse_close_msg="Someone outside closes the door.",
                                     this_open_msg="Someone in the house opens the door.",
                                     this_close_msg="Someone in the house closes the door.")
livingroom.add_exits([
    Exit("kitchen", kitchen, "Your kitchen is adjacent to this room.",
                             "You can see your kitchen. The previous house owners had a door there but you removed it."),
    front_door
])

kitchen.add_exits([
    Exit(["living room", "livingroom", "back"], livingroom, "The living room is back the way you entered.")
])


# ----------------- Neighbours House, Bedroom, Garden  -------------------------

neighbors_house = Location("Neighbor's House", "The house of your neighbors across the street.")

bedroom = Location("Bedroom", "A rather untidy little bedroom. There's clothes lying all over the place. The window is open!")
bedroom.add_extradesc({"clothes"}, "A pile of clothes lies on the floor. The back pocket of some trousers draw your attention.")
bedroom.add_extradesc({"window"}, "The bedroom window is open and you see a ladder leading down to the garden.")
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:33,代码来源:houses.py

示例10: Location

# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import add_exits [as 别名]
library = Location(
    "Library",
    """
    You're in the library, where you usually spend your after-school time in detention.
    """,
)

hallway_door = Door(
    ["hallway", "hallway door", "south", "s", "out"],
    "hallways.north_hallway",
    short_description="An open door to the south leads back into the hallway.",
    locked=False,
    opened=True,
)

library.add_exits([hallway_door])

english.add_exits(
    [Exit(["w", "west"], "hallways.north_hallway", "The hallway to the west offers the possibility of escape.")]
)


class ForDummies(Note):
    def init(self):
        super(Note, self).init()
        self._text = """
        "Divide by 2" is scrawled in the margin of the book in your handwriting.
        """

    def read(self, actor):
        actor.tell(self.text)
开发者ID:elaewin,项目名称:IntroPython2015,代码行数:33,代码来源:classrooms.py

示例11: GameEnd

# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import add_exits [as 别名]
from __future__ import absolute_import, print_function, division, unicode_literals
from tale.base import Location, Exit, Door

# define the locations


class GameEnd(Location):
    def init(self):
        pass

    def notify_player_arrived(self, player, previous_location):
        # player has entered!
        player.story_completed()

livingroom = Location("Living room", "The living room in your home in the outskirts of the city.")
room1 = Location("Small room", "A small room.")
room2 = Location("Large room", "A large room.")
outside = GameEnd("Outside", "You escaped the house.")


# define the exits that connect the locations

livingroom.add_exits([
    Exit("small room", room1, "There's a small room in your house."),
    Exit("large room", room2, "There's a large room in your house."),
    Door(["door", "garden"], outside, "A door leads to the garden.", "There's a heavy door here that leads to the garden outside the house.", opened=False)
])
room1.add_exits([Exit("living room", livingroom, "You can see the living room.")])
room2.add_exits([Exit("living room", livingroom, "You can see the living room.")])
开发者ID:jordanaycamara,项目名称:Tale,代码行数:31,代码来源:house.py

示例12: Location

# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import add_exits [as 别名]
drone.aggressive = True

hall.init_inventory([table, key, drone])

attic = Location("Tower attic",
    """
    The dark and dusty attic of the wizard tower.
    There are piles of old scrolls and assorted stuff here of which you assume
    it once held great magical power. All of it is now covered with a thick
    layer of dust.
    """)
attic.add_extradesc({"dust", "stuff", "scrolls"}, "The scrolls look ancient. One looks like a spell!")
attic.add_extradesc({"spell"}, "The scroll looks like it contains a spell, but on closer inspection, it has become too faded to be understood anymore.")


kitchen = Location("Tower kitchen",
    """
    A cozy little kitchen for hungry wizards.
    Magically conjured food often tastes like cardboard, so even wizards need to
    prepare their meals the old-fashioned way. The kitchen looks small but tidy.
    """)

hall.add_exits([
    Exit(["up", "ladder"], attic, "A small ladder leads up through a hole in the ceiling."),
    Exit(["door", "east"], "town.lane", "A heavy wooden door to the east blocks the noises from the street outside."),
    Exit("north", kitchen, "A door to the north leads to the kitchen.")
])

kitchen.add_exits([Exit("south", hall, "A door to the south leads back to the hall.")])
attic.add_exits([Exit(["down", "ladder"], hall, "A small ladder leads back down to the hall.")])
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:32,代码来源:wizardtower.py

示例13: Location

# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import add_exits [as 别名]

livingroom = Location("Living room", "The living room in your home in the outskirts of the city.")
closet = Location("Closet", "A small room.")
outside = GameEnd("Outside", "It is beautiful weather outside.")


# define the exits that connect the locations

door = Door(
    ["garden", "door"], outside,
    "A door leads to the garden.", "There's a heavy door here that leads to the garden outside the house.",
    locked=True, opened=False)
door.door_code = 1
closet_exit = Exit("closet", closet, "There's a small closet in your house.")
livingroom.add_exits([door, closet_exit])
closet.add_exits([Exit("living room", livingroom, "You can see the living room.")])


# define items and NPCs

class Cat(NPC):
    def init(self):
        self.aliases={"cat"}
        mud_context.driver.defer(4, self, self.do_purr)

    def do_purr(self, driver):
        if random.random() > 0.5:
            self.location.tell("%s purrs happily." % capital(self.title))
        else:
            self.location.tell("%s yawns sleepily." % capital(self.title))
开发者ID:jordanaycamara,项目名称:Tale,代码行数:32,代码来源:house.py

示例14: init

# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import add_exits [as 别名]

def init(driver):
    # called when zone is first loaded
    pass


street1 = Location("Magnolia Street", "Your house is on Magnolia Street, one of the larger streets in town. "
                                      "The rest of the town lies eastwards.")
street2 = Location("Magnolia Street", "Another part of the street.")
street3 = Location("Magnolia Street (east)", "The eastern part of Magnolia Street.")


pharmacy = Location("Pharmacy", "A pharmacy.")
pharmacy.add_exits([
    Exit(["east", "outside", "street"], street1, "Magnolia street is outside towards the east.")
])

factory = Location("ArtiGrow factory", "This area is the ArtiGrow fertilizer factory.")
factory.add_exits([
    Exit(["west", "street"], street3, "You can leave the factory to the west, back to Magnolia Street.")
])


street1.add_exits([
    houses.house_door,
    Exit(["pharmacy", "west"], pharmacy, "The west end of the street leads to the pharmacy."),
    Exit(["town", "east"], street2, "The street extends eastwards, towards the rest of the town.")
])

playground_gate = Door(["north", "gate", "playground"], "rose_st.playground", "To the north there is a small gate that connects to the children's playground.", opened=False)
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:32,代码来源:magnolia_st.py

示例15: super

# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import add_exits [as 别名]
        # but for the game ending, we require an immediate response.
        # So instead we hook into the direct arrival of something in this location.
        super(GameEnd, self).insert(obj, actor)
        try:
            obj.story_completed()   # player arrived! Great Success!
        except AttributeError:
            pass


north_street = Location("Rose Street", "The northern part of Rose Street.")
south_street = Location("Rose Street", "The southern part of Rose Street.")

crossing = Location("Crossing", "Town Crossing.")
crossing.add_exits([
    Exit("west", "magnolia_st.street2", "Westwards lies Magnolia Street."),
    Exit("east", "magnolia_st.street3", "Magnolia Street extends to the east, eventually leading towards the factory."),
    Exit("north", north_street, "A part of Rose Street lies to the north."),
    Exit("south", south_street, "Rose Street continues to the south.")
])

playground = Location("Playground", "Children's playground. You see a rusty merry-go-round, and a little swing. "
                                    "To the west, a house is visible.")
playground.add_extradesc({"west", "house"}, "You can see your house from here!")
playground.add_exits([
    Door("fence", _limbo, "On the north end of the playground is a sturdy looking padlocked fence.", locked=True, opened=False),  # this door is never meant to be opened
    Exit(["east", "street"], north_street, "Rose Street is back east."),
    zones.magnolia_st.street_gate
])

carpark = Location("Car Parking", "There are a few cars still parked over here. Their owners are nowhere to be seen. "
                                  "One yellow car grabs your attention.")
carpark.add_extradesc({"cars"}, "They look abandoned, but their doors are all locked.")
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:34,代码来源:rose_st.py


注:本文中的tale.base.Location.add_exits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。