本文整理汇总了Python中tale.player.Player.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Player.insert方法的具体用法?Python Player.insert怎么用?Python Player.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tale.player.Player
的用法示例。
在下文中一共展示了Player.insert方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_custom_verbs
# 需要导入模块: from tale.player import Player [as 别名]
# 或者: from tale.player.Player import insert [as 别名]
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)
示例2: test_clone
# 需要导入模块: from tale.player import Player [as 别名]
# 或者: from tale.player.Player import insert [as 别名]
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)
示例3: test_destroy_player
# 需要导入模块: from tale.player import Player [as 别名]
# 或者: from tale.player.Player import insert [as 别名]
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)")
示例4: test_clone
# 需要导入模块: from tale.player import Player [as 别名]
# 或者: from tale.player.Player import insert [as 别名]
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)
示例5: test_print_location
# 需要导入模块: from tale.player import Player [as 别名]
# 或者: from tale.player.Player import insert [as 别名]
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()))
示例6: TestLocations
# 需要导入模块: from tale.player import Player [as 别名]
# 或者: from tale.player.Player import insert [as 别名]
class TestLocations(unittest.TestCase):
def setUp(self):
mud_context.driver = DummyDriver()
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.rat = 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.rat, self.julie, self.player, self.fly])
def test_names(self):
loc = Location("The Attic", "A dusty attic.")
self.assertEqual("The Attic", loc.name)
self.assertEqual("A dusty attic.", loc.description)
def test_contains(self):
self.assertTrue(self.julie in self.hall)
self.assertTrue(self.magazine in self.hall)
self.assertFalse(self.pencil in self.hall)
self.assertFalse(self.magazine in self.attic)
self.assertFalse(self.julie in self.attic)
def test_look(self):
expected = ["[Main hall]", "A very large hall.",
"A heavy wooden door to the east blocks the noises from the street outside. A ladder leads up.",
"Someone forgot a key. You see a university magazine and an oak table. Player, attractive Julie, and rat are here. A fly buzzes around your head."]
self.assertEqual(expected, strip_text_styles(self.hall.look()))
expected = ["[Main hall]", "A very large hall.",
"A heavy wooden door to the east blocks the noises from the street outside. A ladder leads up.",
"Someone forgot a key. You see a university magazine and an oak table. Attractive Julie and rat are here. A fly buzzes around your head."]
self.assertEqual(expected, strip_text_styles(self.hall.look(exclude_living=self.player)))
expected = ["[Attic]", "A dark attic."]
self.assertEqual(expected, strip_text_styles(self.attic.look()))
def test_look_short(self):
expected = ["[Attic]"]
self.assertEqual(expected, strip_text_styles(self.attic.look(short=True)))
expected = ["[Main hall]", "Exits: door, east, up", "You see: key, magazine, table", "Present: fly, julie, player, rat"]
self.assertEqual(expected, strip_text_styles(self.hall.look(short=True)))
expected = ["[Main hall]", "Exits: door, east, up", "You see: key, magazine, table", "Present: fly, julie, rat"]
self.assertEqual(expected, strip_text_styles(self.hall.look(exclude_living=self.player, short=True)))
def test_search_living(self):
self.assertEqual(None, self.hall.search_living("<notexisting>"))
self.assertEqual(None, self.attic.search_living("<notexisting>"))
self.assertEqual(self.rat, self.hall.search_living("rat"))
self.assertEqual(self.julie, self.hall.search_living("Julie"))
self.assertEqual(self.julie, self.hall.search_living("attractive julie"))
self.assertEqual(self.julie, self.hall.search_living("chick"))
self.assertEqual(None, self.hall.search_living("bloke"))
def test_search_item(self):
# almost identical to locate_item so only do a few basic tests
self.assertEqual(None, self.player.search_item("<notexisting>"))
self.assertEqual(self.pencil, self.player.search_item("pencil"))
def test_locate_item(self):
item, container = self.player.locate_item("<notexisting>")
self.assertEqual(None, item)
self.assertEqual(None, container)
item, container = self.player.locate_item("pencil")
self.assertEqual(self.pencil, item)
self.assertEqual(self.player, container)
item, container = self.player.locate_item("fountain pen")
self.assertEqual(self.pencil, item, "need to find the title")
item, container = self.player.locate_item("pen")
self.assertEqual(self.pencil, item, "need to find the alias")
item, container = self.player.locate_item("pencil", include_inventory=False)
self.assertEqual(None, item)
self.assertEqual(None, container)
item, container = self.player.locate_item("key")
self.assertEqual(self.key, item)
self.assertEqual(self.hall, container)
item, container = self.player.locate_item("key", include_location=False)
self.assertEqual(None, item)
self.assertEqual(None, container)
item, container = self.player.locate_item("KEY")
self.assertEqual(self.key, item, "should work case-insensitive")
self.assertEqual(self.hall, container, "should work case-insensitive")
item, container = self.player.locate_item("notebook")
self.assertEqual(self.notebook_in_bag, item)
self.assertEqual(self.bag, container, "should search in bags in inventory")
item, container = self.player.locate_item("notebook", include_containers_in_inventory=False)
self.assertEqual(None, item)
#.........这里部分代码省略.........
示例7: TestLocations
# 需要导入模块: from tale.player import Player [as 别名]
# 或者: from tale.player.Player import insert [as 别名]
class TestLocations(unittest.TestCase):
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])
def test_names(self):
loc = Location("The Attic", "A dusty attic.")
self.assertEqual("The Attic", loc.name)
self.assertEqual("A dusty attic.", loc.description)
def test_contains(self):
self.assertTrue(self.julie in self.hall)
self.assertTrue(self.magazine in self.hall)
self.assertFalse(self.pencil in self.hall)
self.assertFalse(self.magazine in self.attic)
self.assertFalse(self.julie in self.attic)
def test_look(self):
expected = ["[Main hall]", "A very large hall.",
"A heavy wooden door to the east blocks the noises from the street outside. A ladder leads up.",
"Someone forgot a key. You see two university magazines and an oak table. Player, attractive Julie, and two rats are here. A fly buzzes around your head."]
self.assertEqual(expected, strip_text_styles(self.hall.look()))
expected = ["[Main hall]", "A very large hall.",
"A heavy wooden door to the east blocks the noises from the street outside. A ladder leads up.",
"Someone forgot a key. You see two university magazines and an oak table. Attractive Julie and two rats are here. A fly buzzes around your head."]
self.assertEqual(expected, strip_text_styles(self.hall.look(exclude_living=self.player)))
expected = ["[Attic]", "A dark attic."]
self.assertEqual(expected, strip_text_styles(self.attic.look()))
def test_look_short(self):
expected = ["[Attic]"]
self.assertEqual(expected, strip_text_styles(self.attic.look(short=True)))
expected = ["[Main hall]", "Exits: door, east, up", "You see: key, two magazines, and table", "Present: fly, julie, player, and two rats"]
self.assertEqual(expected, strip_text_styles(self.hall.look(short=True)))
expected = ["[Main hall]", "Exits: door, east, up", "You see: key, two magazines, and table", "Present: fly, julie, and two rats"]
self.assertEqual(expected, strip_text_styles(self.hall.look(exclude_living=self.player, short=True)))
def test_search_living(self):
self.assertEqual(None, self.hall.search_living("<notexisting>"))
self.assertEqual(None, self.attic.search_living("<notexisting>"))
self.assertEqual(self.fly, self.hall.search_living("fly"))
self.assertEqual(self.julie, self.hall.search_living("Julie"))
self.assertEqual(self.julie, self.hall.search_living("attractive julie"))
self.assertEqual(self.julie, self.hall.search_living("chick"))
self.assertEqual(None, self.hall.search_living("bloke"))
def test_search_item(self):
# almost identical to locate_item so only do a few basic tests
self.assertEqual(None, self.player.search_item("<notexisting>"))
self.assertEqual(self.pencil, self.player.search_item("pencil"))
def test_locate_item(self):
item, container = self.player.locate_item("<notexisting>")
self.assertEqual(None, item)
self.assertEqual(None, container)
item, container = self.player.locate_item("pencil")
self.assertEqual(self.pencil, item)
self.assertEqual(self.player, container)
item, container = self.player.locate_item("fountain pen")
self.assertEqual(self.pencil, item, "need to find the title")
item, container = self.player.locate_item("pen")
self.assertEqual(self.pencil, item, "need to find the alias")
item, container = self.player.locate_item("pencil", include_inventory=False)
self.assertEqual(None, item)
self.assertEqual(None, container)
item, container = self.player.locate_item("key")
self.assertEqual(self.key, item)
self.assertEqual(self.hall, container)
item, container = self.player.locate_item("key", include_location=False)
self.assertEqual(None, item)
self.assertEqual(None, container)
item, container = self.player.locate_item("KEY")
self.assertEqual(self.key, item, "should work case-insensitive")
self.assertEqual(self.hall, container, "should work case-insensitive")
item, container = self.player.locate_item("notebook")
self.assertEqual(self.notebook_in_bag, item)
#.........这里部分代码省略.........