本文整理汇总了Python中tale.player.Player类的典型用法代码示例。如果您正苦于以下问题:Python Player类的具体用法?Python Player怎么用?Python Player使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Player类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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)
示例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())
示例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
示例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 ""
示例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())
示例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)
示例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)
示例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)
示例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())
示例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 ""
示例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)
示例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])
示例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")