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


Python base.Location类代码示例

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


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

示例1: test_exits

 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,代码行数:30,代码来源:test_mudobjects.py

示例2: test_socialize

 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,代码行数:29,代码来源:test_player.py

示例3: setUp

 def setUp(self):
     mud_context.driver = TestDriver()
     mud_context.config = DemoStory()._get_config()
     self.hall = Location("Main hall", "A very large hall.")
     self.attic = Location("Attic", "A dark attic.")
     self.street = Location("Street", "An endless street.")
     e1 = Exit("up", self.attic, "A ladder leads up.")
     e2 = Exit(["door", "east"], self.street, "A heavy wooden door to the east blocks the noises from the street outside.")
     self.hall.add_exits([e1, e2])
     self.table = Item("table", "oak table", "a large dark table with a lot of cracks in its surface")
     self.key = Item("key", "rusty key", "an old rusty key without a label", short_description="Someone forgot a key.")
     self.magazine = Item("magazine", "university magazine")
     self.magazine2 = Item("magazine", "university magazine")
     self.rat = NPC("rat", "n", race="rodent")
     self.rat2 = NPC("rat", "n", race="rodent")
     self.fly = NPC("fly", "n", race="insect", short_description="A fly buzzes around your head.")
     self.julie = NPC("julie", "f", title="attractive Julie", description="She's quite the looker.")
     self.julie.aliases = {"chick"}
     self.player = Player("player", "m")
     self.pencil = Item("pencil", title="fountain pen")
     self.pencil.aliases = {"pen"}
     self.bag = Container("bag")
     self.notebook_in_bag = Item("notebook")
     self.bag.insert(self.notebook_in_bag, self.player)
     self.player.insert(self.pencil, self.player)
     self.player.insert(self.bag, self.player)
     self.hall.init_inventory([self.table, self.key, self.magazine, self.magazine2, self.rat, self.rat2, self.julie, self.player, self.fly])
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:27,代码来源:test_mudobjects.py

示例4: test_custom_verbs

    def test_custom_verbs(self):
        player = Player("julie", "f")
        player.verbs["xywobble"] = "p1"
        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"
        room.init_inventory([chair1, player, chair2])

        # check inventory NOT affecting player custom verbs, but DOES affect location verbs
        self.assertEqual({"xywobble": "p1"}, player.verbs)
        self.assertEqual({"frobnitz": "c2", "xywobble": "p1"}, room.verbs)
        player.insert(chair_in_inventory, player)
        self.assertEqual({"xywobble": "p1"}, player.verbs)
        self.assertEqual({"frobnitz": "c2", "xywobble": "p1", "kowabooga": "c3"}, room.verbs)
        player.remove(chair_in_inventory, player)
        self.assertEqual({"frobnitz": "c2", "xywobble": "p1"}, room.verbs)

        player.insert(chair_in_inventory, player)
        self.assertEqual({"frobnitz": "c2", "xywobble": "p1", "kowabooga": "c3" }, room.verbs)
        room2 = Location("room2")
        self.assertEqual({}, room2.verbs)
        chair1.move(room2, player)
        self.assertEqual({"xywobble": "p1", "kowabooga": "c3" }, room.verbs)
        self.assertEqual({"frobnitz": "c1"}, room2.verbs)
        chair2.move(room2, player)
        self.assertEqual({"xywobble": "p1", "kowabooga": "c3"}, room.verbs)
        self.assertEqual({"frobnitz": "c2"}, room2.verbs)
        player.move(room2)
        self.assertEqual({}, room.verbs)
        self.assertEqual({"frobnitz": "c2", "xywobble": "p1", "kowabooga": "c3"}, room2.verbs)
开发者ID:jordanaycamara,项目名称:Tale,代码行数:34,代码来源:test_mudobjects.py

示例5: test_move

 def test_move(self):
     hall = Location("hall")
     person = Living("person", "m", race="human")
     monster = NPC("dragon", "f", race="dragon")
     monster.aggressive = True
     key = Item("key")
     stone = Item("stone")
     hall.init_inventory([person, key])
     stone.move(hall, person)
     wiretap = Wiretap(hall)
     self.assertTrue(person in hall)
     self.assertTrue(key in hall)
     key.contained_in = person   # hack to force move to actually check the source container
     with self.assertRaises(KeyError):
         key.move(person, person)
     key.contained_in = hall   # put it back as it was
     key.move(person, person)
     self.assertFalse(key in hall)
     self.assertTrue(key in person)
     self.assertEqual([], wiretap.msgs, "item.move() should be silent")
     with self.assertRaises(ActionRefused) as x:
         key.move(monster, person)  # aggressive monster should fail
     self.assertTrue("not a good idea" in str(x.exception))
     monster.aggressive = False
     key.move(monster, person)   # non-aggressive should be ok
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:25,代码来源:test_mudobjects.py

示例6: test_door_pair

    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,代码行数:35,代码来源:test_mudobjects.py

示例7: test_move

 def test_move(self):
     hall = Location("hall")
     attic = Location("attic")
     rat = Living("rat", "n", race="rodent")
     hall.init_inventory([rat])
     wiretap_hall = Wiretap(hall)
     wiretap_attic = Wiretap(attic)
     self.assertTrue(rat in hall.livings)
     self.assertFalse(rat in attic.livings)
     self.assertEqual(hall, rat.location)
     rat.move(attic)
     self.assertTrue(rat in attic.livings)
     self.assertFalse(rat in hall.livings)
     self.assertEqual(attic, rat.location)
     self.assertEqual([("hall", "Rat leaves.")], wiretap_hall.msgs)
     self.assertEqual([("attic", "Rat arrives.")], wiretap_attic.msgs)
     # now try silent
     wiretap_hall.clear()
     wiretap_attic.clear()
     rat.move(hall, silent=True)
     self.assertTrue(rat in hall.livings)
     self.assertFalse(rat in attic.livings)
     self.assertEqual(hall, rat.location)
     self.assertEqual([], wiretap_hall.msgs)
     self.assertEqual([], wiretap_attic.msgs)
开发者ID:jordanaycamara,项目名称:Tale,代码行数:25,代码来源:test_mudobjects.py

示例8: test_aliases

 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,代码行数:11,代码来源:test_mudobjects.py

示例9: test_destroy_deferreds

 def test_destroy_deferreds(self):
     ctx = Context(driver=mud_context.driver)
     thing = Item("thing")
     player = Player("julie", "f")
     wolf = Monster("wolf", "m")
     loc = Location("loc")
     mud_context.driver.defer(datetime.datetime.now(), thing, "method")
     mud_context.driver.defer(datetime.datetime.now(), player, "method")
     mud_context.driver.defer(datetime.datetime.now(), wolf, "method")
     mud_context.driver.defer(datetime.datetime.now(), loc, "method")
     self.assertEqual(4, len(mud_context.driver.deferreds))
     thing.destroy(ctx)
     player.destroy(ctx)
     wolf.destroy(ctx)
     loc.destroy(ctx)
     self.assertEqual(0, len(mud_context.driver.deferreds), "all deferreds must be removed")
开发者ID:jordanaycamara,项目名称:Tale,代码行数:16,代码来源:test_mudobjects.py

示例10: test_destroy_deferreds

 def test_destroy_deferreds(self):
     ctx = Context(driver=mud_context.driver, clock=None, config=None, player_connection=None)
     thing = Item("thing")
     player = Player("julie", "f")
     wolf = NPC("wolf", "m")
     loc = Location("loc")
     mud_context.driver.defer(datetime.datetime.now(), thing.move)
     mud_context.driver.defer(datetime.datetime.now(), player.move)
     mud_context.driver.defer(datetime.datetime.now(), wolf.move)
     mud_context.driver.defer(datetime.datetime.now(), loc.move)
     self.assertEqual(4, len(mud_context.driver.deferreds))
     thing.destroy(ctx)
     player.destroy(ctx)
     wolf.destroy(ctx)
     loc.destroy(ctx)
     self.assertEqual(0, len(mud_context.driver.deferreds), "all deferreds must be removed")
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:16,代码来源:test_mudobjects.py

示例11: test_destroy_player

 def test_destroy_player(self):
     ctx = Context()
     loc = Location("loc")
     player = Player("julie", "f")
     player.privileges = {"wizard"}
     player.create_wiretap(loc)
     player.insert(Item("key"), player)
     loc.init_inventory([player])
     self.assertEqual(loc, player.location)
     self.assertTrue(len(player.inventory) > 0)
     self.assertTrue(player in loc.livings)
     player.destroy(ctx)
     import gc
     gc.collect()
     self.assertTrue(len(player.inventory) == 0)
     self.assertFalse(player in loc.livings)
     self.assertIsNone(player.location, "destroyed player should end up nowhere (None)")
开发者ID:jordanaycamara,项目名称:Tale,代码行数:17,代码来源:test_mudobjects.py

示例12: test_wiretap

 def test_wiretap(self):
     attic = Location("Attic", "A dark attic.")
     player = Player("fritz", "m")
     io = ConsoleIo(None)
     io.supports_smartquotes = False
     pc = PlayerConnection(player, io)
     player.set_screen_sizes(0, 100)
     julie = NPC("julie", "f")
     julie.move(attic)
     player.move(attic)
     julie.tell("message for julie")
     attic.tell("message for room")
     self.assertEqual(["message for room\n"], player.test_get_output_paragraphs())
     with self.assertRaises(ActionRefused):
         player.create_wiretap(julie)
     player.privileges = {"wizard"}
     player.create_wiretap(julie)
     player.create_wiretap(attic)
     julie.tell("message for julie")
     attic.tell("message for room")
     pubsub.sync()
     output = pc.get_output()
     self.assertTrue("[wiretapped from 'Attic': message for room]" in output)
     self.assertTrue("[wiretapped from 'julie': message for julie]" in output)
     self.assertTrue("[wiretapped from 'julie': message for room]" in output)
     self.assertTrue("message for room " in output)
     # test removing the wiretaps
     player.clear_wiretaps()
     import gc
     gc.collect()
     julie.tell("message for julie")
     attic.tell("message for room")
     self.assertEqual(["message for room\n"], player.test_get_output_paragraphs())
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:33,代码来源:test_player.py

示例13: make_location

def make_location(vnum):
    """
    Get a Tale location object for the given circle room vnum.
    This performs an on-demand conversion of the circle room data to Tale.
    """
    try:
        return converted_rooms[vnum]   # get cached version if available
    except KeyError:
        c_room = rooms[vnum]
        loc = Location(c_room.name, c_room.desc)
        loc.vnum = vnum  # keep the circle vnum
        for ed in c_room.extradesc:
            loc.add_extradesc(ed["keywords"], ed["text"])
        converted_rooms[vnum] = loc
        for circle_exit in c_room.exits.values():
            if circle_exit.roomlink >= 0:
                xt = make_exit(circle_exit)
                while True:
                    try:
                        xt.bind(loc)
                        break
                    except LocationIntegrityError as x:
                        if x.direction in xt.aliases:
                            # circlemud exit keywords can be duplicated over various exits
                            # if we have a conflict, just remove the alias from the exit and try again
                            xt.aliases = xt.aliases - {x.direction}
                            continue
                        else:
                            if loc.exits[x.direction] is xt:
                                # this can occur, the exit is already bound
                                break
                            else:
                                # in this case a true integrity error occurred
                                raise
            else:
                # add the description of the inaccessible exit to the room's own description.
                loc.description += " " + circle_exit.desc
        return loc
开发者ID:digideskio,项目名称:Tale,代码行数:38,代码来源:__init__.py

示例14: test_custom_verbs

 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,代码行数:23,代码来源:test_mudobjects.py

示例15: test_print_location

 def test_print_location(self):
     p = Player("julie", "f")
     key = Item("key")
     bag = Container("bag")
     room = Location("room")
     bag.insert(key, p)
     p.insert(bag, p)
     room.insert(p, p)
     with self.assertRaises(Exception):
         p.tell_object_location(None, None)
     p.tell_object_location(key, None)
     self.assertEqual(["(It's not clear where key is).\n"], p.test_get_output_paragraphs())
     p.tell_object_location(key, None, print_parentheses=False)
     self.assertEqual(["It's not clear where key is.\n"], p.test_get_output_paragraphs())
     p.tell_object_location(key, bag)
     result = "".join(p.test_get_output_paragraphs())
     self.assertTrue("in bag" in result and "in your inventory" in result)
     p.tell_object_location(key, room)
     self.assertTrue("in your current location" in "".join(p.test_get_output_paragraphs()))
     p.tell_object_location(bag, p)
     self.assertTrue("in your inventory" in "".join(p.test_get_output_paragraphs()))
     p.tell_object_location(p, room)
     self.assertTrue("in your current location" in "".join(p.test_get_output_paragraphs()))
开发者ID:irmen,项目名称:Tale,代码行数:23,代码来源:test_util.py


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