• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python player.Player类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_move_notify

    def test_move_notify(self):
        class LocationNotify(Location):
            def notify_npc_left(self, npc, target_location):
                self.npc_left = npc
                self.npc_left_target = target_location

            def notify_npc_arrived(self, npc, previous_location):
                self.npc_arrived = npc
                self.npc_arrived_from = previous_location

            def notify_player_left(self, player, target_location):
                self.player_left = player
                self.player_left_target = target_location

            def notify_player_arrived(self, player, previous_location):
                self.player_arrived = player
                self.player_arrived_from = previous_location

        player = Player("julie", "f")
        room1 = LocationNotify("room1")
        room2 = LocationNotify("room2")
        room1.insert(player, player)
        player.move(room2)
        pubsub.sync()
        self.assertEqual(room2, player.location)
        self.assertEqual(player, room1.player_left)
        self.assertEqual(room2, room1.player_left_target)
        self.assertEqual(player, room2.player_arrived)
        self.assertEqual(room1, room2.player_arrived_from)
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:29,代码来源:test_player.py


示例2: test_with_key

 def test_with_key(self):
     player = Player("julie", "f")
     key = Key("key", "door key")
     key.key_for(code=12345)
     hall = Location("hall")
     door = Door("north", hall, "a locked door", locked=True, opened=False)
     door2 = Door("south", hall, "another locked door", locked=True, opened=False)
     with self.assertRaises(ActionRefused):
         door.unlock(player)
     with self.assertRaises(ActionRefused):
         door.unlock(player, key)
     door.key_code = 12345
     door2.key_code = 9999
     key.key_for(door)
     self.assertTrue(door.locked)
     door.unlock(player, key)
     self.assertFalse(door.locked)
     with self.assertRaises(ActionRefused):
         door2.unlock(key)
     door.locked = True
     with self.assertRaises(ActionRefused):
         door.unlock(player)
     key.move(player, player)
     door.unlock(player)
     self.assertFalse(door.locked)
     door.lock(player)
     self.assertTrue(door.locked)
     door.unlock(player)
     player.remove(key, player)
     with self.assertRaises(ActionRefused):
         door.lock(player)
     door.key_code = None
     with self.assertRaises(LocationIntegrityError):
         key.key_for(door)
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:34,代码来源:test_mudobjects.py


示例3: 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


示例4: test_write_output

 def test_write_output(self):
     player = Player("julie", "f")
     with WrappedConsoleIO(None) as io:
         pc = PlayerConnection(player, io)
         player.tell("hello 1", end=True)
         player.tell("hello 2", end=True)
         pc.write_output()
         self.assertEqual("  hello 2", pc.last_output_line)
         self.assertEqual("  hello 1\n  hello 2\n", sys.stdout.getvalue())
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:9,代码来源:test_player.py


示例5: test_input

 def test_input(self):
     player = Player("julie", "f")
     with WrappedConsoleIO(None) as io:
         pc = PlayerConnection(player, io)
         player.tell("first this text")
         player.store_input_line("      input text     \n")
         x = pc.input_direct("inputprompt")
         self.assertEqual("input text", x)
         self.assertEqual("  first this text\ninputprompt ", sys.stdout.getvalue())  # should have outputted the buffered text
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:9,代码来源:test_player.py


示例6: welcome

 def welcome(self, player: Player) -> str:
     """
     Welcome text when player enters a new game
     If you return a string, it is used as an input prompt before continuing (a pause).
     """
     player.tell("<bright>Hello, %s!</> Welcome to the land of `%s'.  May your visit here be... interesting."
                 % (player.title, self.config.name), end=True)
     player.tell("--", end=True)
     return ""
开发者ID:irmen,项目名称:Tale,代码行数:9,代码来源:story.py


示例7: test_tell_emptystring

 def test_tell_emptystring(self):
     player = Player("fritz", "m")
     player.tell("", end=False)
     self.assertEqual([], player.test_get_output_paragraphs())
     player.tell("", end=True)
     self.assertEqual(["\n"], player.test_get_output_paragraphs())
     player.tell("", end=True)
     player.tell("", end=True)
     self.assertEqual(["\n", "\n"], player.test_get_output_paragraphs())
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:9,代码来源:test_player.py


示例8: test_init

 def test_init(self):
     player = Player("fritz", "m")
     player.title = "Fritz the great"
     self.assertEqual("fritz", player.name)
     self.assertEqual("Fritz the great", player.title)
     self.assertEqual("", player.description)
     self.assertEqual("human", player.race)
     self.assertEqual("m", player.gender)
     self.assertEqual(set(), player.privileges)
     self.assertTrue(1 < player.stats["agi"] < 100)
开发者ID:jordanaycamara,项目名称:Tale,代码行数:10,代码来源:test_player.py


示例9: test_init

 def test_init(self):
     player = Player("fritz", "m")
     player.title = "Fritz the great"
     self.assertEqual("fritz", player.name)
     self.assertEqual("Fritz the great", player.title)
     self.assertEqual("", player.description)
     self.assertEqual("human", player.stats.race)
     self.assertEqual("m", player.gender)
     self.assertEqual(set(), player.privileges)
     self.assertTrue(1 < player.stats.agi < 100)
     self.assertGreater(player.output_line_delay, 1)
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:11,代码来源:test_player.py


示例10: test_idle

 def test_idle(self):
     p = Player("dummy", "f")
     c = PlayerConnection(p, WrappedConsoleIO(None))
     self.assertLess(p.idle_time, 0.1)
     self.assertLess(c.idle_time, 0.1)
     time.sleep(0.2)
     self.assertGreater(p.idle_time, 0.1)
     self.assertGreater(c.idle_time, 0.1)
     p.store_input_line("input")
     self.assertLess(p.idle_time, 0.1)
     self.assertLess(c.idle_time, 0.1)
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:11,代码来源:test_player.py


示例11: test_peek_output

 def test_peek_output(self):
     player = Player("fritz", "m")
     pc = PlayerConnection(player, ConsoleIo(None))
     player.set_screen_sizes(0, 100)
     player.tell("line1")
     player.tell("line2", 42)
     self.assertEqual(["line1\nline2 42\n"], player.test_peek_output_paragraphs())
     self.assertEqual("line1 line2 42\n", pc.get_output())
     self.assertEqual([], player.test_peek_output_paragraphs())
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:9,代码来源:test_player.py


示例12: welcome

 def welcome(self, player: Player) -> str:
     player.tell("<bright>Welcome to `%s'.</>" % self.config.name, end=True)
     player.tell("This is a tiny embedded story to check out a running Tale environment.")
     player.tell("Try to communicate with your pet, and exit the house to win the game.")
     player.tell("\n")
     player.tell("\n")
     return ""
开发者ID:irmen,项目名称:Tale,代码行数:7,代码来源:story.py


示例13: test_clone

 def test_clone(self):
     item = Item("thing", "description")
     item.aliases = ["a1", "a2"]
     item2 = util.clone(item)
     self.assertNotEqual(item, item2)
     item2.aliases.append("a3")
     self.assertNotEqual(item.aliases, item2.aliases)
     player = Player("julie", "f")
     player.insert(item, player)
     player2 = util.clone(player)
     player2.insert(item2, player2)
     self.assertNotEqual(player.inventory_size, player2.inventory_size)
     self.assertNotEqual(player.inventory, player2.inventory)
     self.assertTrue(item in player)
     self.assertFalse(item in player2)
开发者ID:jordanaycamara,项目名称:Tale,代码行数:15,代码来源:test_util.py


示例14: 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


示例15: 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


示例16: 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


示例17: test_tell_sep

 def test_tell_sep(self):
     player = Player("fritz", "m")
     pc = PlayerConnection(player, ConsoleIo(None))
     player.set_screen_sizes(0, 10)
     player.tell("apple", "bee", "zinc", "rose")
     self.assertEqual(["apple bee zinc rose\n"], player.test_get_output_paragraphs())
     pc.get_output()
     player.tell("apple", "bee", "zinc", "rose", format=False)
     self.assertEqual("apple\nbee\nzinc\nrose\n", pc.get_output())
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:9,代码来源:test_player.py


示例18: welcome_savegame

 def welcome_savegame(self, player: Player) -> str:
     """
     Welcome text when player enters the game after loading a saved game
     If you return a string, it is used as an input prompt before continuing (a pause).
     """
     player.tell("<bright>Welcome back to `%s'.</>" % self.config.name, end=True)
     player.tell("\n")
     player.tell_text_file(self.driver.resources["messages/welcome.txt"])
     player.tell("\n")
     return "<bright>Press enter to continue where you were before.</>"
开发者ID:irmen,项目名称:Tale,代码行数:10,代码来源:story.py


示例19: test_clone

 def test_clone(self):
     item = Item("thing", "description")
     item.aliases = ["a1", "a2"]
     item2 = clone(item)
     self.assertNotEqual(item, item2)
     item2.aliases.append("a3")
     self.assertNotEqual(item.aliases, item2.aliases)
     player = Player("julie", "f")
     player.insert(item, player)
     with self.assertRaises(ValueError):
         clone(player)   # can't clone something with stuff in it
     player.remove(item, player)
     player2 = clone(player)
     player2.insert(item2, player2)
     self.assertNotEqual(player.inventory_size, player2.inventory_size)
     self.assertNotEqual(player.inventory, player2.inventory)
     self.assertFalse(item in player)
     self.assertFalse(item in player2)
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:18,代码来源:test_mudobjects.py


示例20: test_others

 def test_others(self):
     attic = Location("Attic", "A dark attic.")
     player = Player("merlin", "m")
     player.title = "wizard Merlin"
     julie = MsgTraceNPC("julie", "f", "human")
     fritz = MsgTraceNPC("fritz", "m", "human")
     julie.move(attic, silent=True)
     fritz.move(attic, silent=True)
     player.move(attic, silent=True)
     player.tell_others("one", "two", "three")
     self.assertEqual([], player.test_get_output_paragraphs())
     self.assertEqual(["one", "two", "three"], fritz.messages)
     self.assertEqual(["one", "two", "three"], julie.messages)
     fritz.clearmessages()
     julie.clearmessages()
     player.tell_others("{title} and {Title}")
     self.assertEqual(["wizard Merlin and Wizard Merlin"], fritz.messages)
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:17,代码来源:test_player.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python result_form.ResultForm类代码示例发布时间:2022-05-27
下一篇:
Python base.Location类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap