示例#1
0
    def test_travel_east_west(self):
        room1 = Room(self.game, "A place", "Description of a place. ")
        room2 = Room(
            self.game, "A different place", "Description of a different place. "
        )
        room1.east = room2
        room2.west = room1
        self.me.location.removeThing(self.me)
        room1.addThing(self.me)
        self.assertIs(
            self.me.location, room1, "This test needs the user to start in room1"
        )

        self.game.turnMain("go e")

        self.assertEqual(self.app.print_stack[-3], room1.e_msg)

        self.assertIs(
            self.me.location,
            room2,
            f"Tried to travel east to {room2}, '{room2.name}', but player in "
            f"{self.me.location}",
        )

        self.game.turnMain("w")

        self.assertEqual(self.app.print_stack[-3], room1.w_msg)

        self.assertIs(
            self.me.location,
            room1,
            f"Tried to travel west to {room1}, '{room1.name}', but player in "
            f"{self.me.location}",
        )
示例#2
0
    def test_can_travel_StaircaseConnector(self):
        room1 = Room(self.game, "A place", "Description of a place. ")
        room2 = Room(self.game, "A different place",
                     "Description of a different place. ")
        c = StaircaseConnector(self.game, room1, room2)

        self._assert_can_travel(room1, room2, c)
示例#3
0
    def test_travel_up_down(self):
        room1 = Room(self.game, "A place", "Description of a place. ")
        room2 = Room(
            self.game, "A different place", "Description of a different place. "
        )
        room1.up = room2
        room2.down = room1
        self.me.location.removeThing(self.me)
        room1.addThing(self.me)
        self.assertIs(
            self.me.location, room1, "This test needs the user to start in room1"
        )

        self.game.turnMain("u")

        self.assertEqual(self.app.print_stack[-3], room1.u_msg)

        self.assertIs(
            self.me.location,
            room2,
            f"Tried to travel up to {room2}, '{room2.name}', but player in "
            f"{self.me.location}",
        )

        self.game.turnMain("go d")
        self.assertEqual(self.app.print_stack[-3], room1.d_msg)

        self.assertIs(
            self.me.location,
            room1,
            f"Tried to travel down to {room1}, '{room1.name}', but player in "
            f"{self.me.location}",
        )
示例#4
0
    def test_travel_north_south(self):
        room1 = Room(self.game, "A place", "Description of a place. ")
        room2 = Room(
            self.game, "A different place", "Description of a different place. "
        )
        room1.north = room2
        room2.south = room1
        self.me.location.removeThing(self.me)
        room1.addThing(self.me)
        self.assertIs(
            self.me.location, room1, "This test needs the user to start in room1"
        )

        self.game.turnMain("go n")
        self.assertEqual(self.app.print_stack[-3], room1.n_msg)

        self.assertIs(
            self.me.location,
            room2,
            f"Tried to travel north to {room2}, '{room2.name}', but player in "
            f"{self.me.location}",
        )

        self.game.turnMain("s")

        self.assertEqual(self.app.print_stack[-3], room1.s_msg)

        self.assertIs(
            self.me.location,
            room1,
            f"Tried to travel south to {room1}, '{room1.name}', but player in "
            f"{self.me.location}",
        )
示例#5
0
    def test_can_travel_DoorConnector(self):
        room1 = Room(self.game, "A place", "Description of a place. ")
        room2 = Room(self.game, "A different place",
                     "Description of a different place. ")
        c = DoorConnector(self.game, room1, "n", room2, "s")

        self._assert_can_travel(room1, room2, c)
示例#6
0
    def test_travel_in_out(self):
        room1 = Room(self.game, "A place", "Description of a place. ")
        room2 = Room(
            self.game, "A different place", "Description of a different place. "
        )
        room1.entrance = room2
        room2.exit = room1
        self.me.location.removeThing(self.me)
        room1.addThing(self.me)
        self.assertIs(
            self.me.location, room1, "This test needs the user to start in room1"
        )

        self.game.turnMain("enter")

        self.assertEqual(self.app.print_stack[-3], room1.in_msg)

        self.assertIs(
            self.me.location,
            room2,
            f"Tried to travel in to {room2}, '{room2.name}', but player in "
            f"{self.me.location}",
        )

        self.game.turnMain("exit")

        self.assertEqual(self.app.print_stack[-3], room1.out_msg)

        self.assertIs(
            self.me.location,
            room1,
            f"Tried to travel out to {room1}, '{room1.name}', but player in "
            f"{self.me.location}",
        )
示例#7
0
    def test_can_travel_StaircaseConnector(self):
        room1 = Room(self.game, "A place", "Description of a place. ")
        room2 = Room(
            self.game, "A different place", "Description of a different place. "
        )
        c = StaircaseConnector(self.game, room1, room2)

        self._assert_can_travel(room1, room2, "u", "d")
        self.assertIn("You climb up the upward staircase. ", self.app.print_stack)
        self.assertIn("You climb down the downward staircase. ", self.app.print_stack)
        self.assertIn(room1.desc + "A staircase leads up. ", self.app.print_stack)
示例#8
0
 def setUp(self):
     super().setUp()
     self.room1 = Room(self.game, "A cold room", "This room is cold. ")
     self.room2 = Room(self.game, "A hot room",
                       "This room is uncomfortably hot. ")
     self.door = DoorConnector(self.game, self.room1, "se", self.room2,
                               "nw")
     self.key = Key(self.game, "key")
     self.me.addThing(self.key)
     self.lock = Lock(self.game, False, self.key)
     self.lock.is_locked = False
     self.door.setLock(self.lock)
示例#9
0
 def setUp(self):
     super().setUp()
     self.actor1 = Actor(self.game, "grocer")
     self.actor1.can_be_led = True
     self.start_room.addThing(self.actor1)
     self.room2 = Room(self.game, "Place", "Words")
     self.start_room.north = self.room2
示例#10
0
    def test_can_travel_DoorConnector(self):
        room1 = Room(self.game, "A place", "Description of a place. ")
        room2 = Room(
            self.game, "A different place", "Description of a different place. "
        )
        c = DoorConnector(self.game, room1, "n", room2, "s")
        c.entrance_a.makeClosed()

        self._assert_can_travel(room1, room2, "n", "s")
        self.assertIn("You open the north door. ", self.app.print_stack)
        self.assertIn("You go through the north door. ", self.app.print_stack)
        self.assertIn("You go through the south door. ", self.app.print_stack)
        self.assertIn(
            room1.desc + "There is a door to the north. It is open. ",
            self.app.print_stack,
        )
示例#11
0
    def test_cannot_travel_if_not_connection(self):
        room1 = Room(self.game, "A place", "Description of a place. ")
        self.assertTrue(
            (not room1.north and not room1.northeast and not room1.east
             and not room1.southeast and not room1.south
             and not room1.southwest and not room1.west and not room1.northwest
             and not room1.up and not room1.down and not room1.entrance
             and not room1.exit),
            "This test needs room1 to have no directional connections.",
        )
        self.me.location.removeThing(self.me)
        room1.addThing(self.me)

        self.game.turnMain("n")
        self.assertIs(self.me.location, room1)
        self.assertEqual(self.app.print_stack.pop(), room1.n_false_msg)

        self.game.turnMain("ne")
        self.assertIs(self.me.location, room1)
        self.assertEqual(self.app.print_stack.pop(), room1.ne_false_msg)

        self.game.turnMain("e")
        self.assertIs(self.me.location, room1)
        self.assertEqual(self.app.print_stack.pop(), room1.e_false_msg)

        self.game.turnMain("se")
        self.assertIs(self.me.location, room1)
        self.assertEqual(self.app.print_stack.pop(), room1.se_false_msg)

        self.game.turnMain("s")
        self.assertIs(self.me.location, room1)
        self.assertEqual(self.app.print_stack.pop(), room1.s_false_msg)

        self.game.turnMain("sw")
        self.assertIs(self.me.location, room1)
        self.assertEqual(self.app.print_stack.pop(), room1.sw_false_msg)

        self.game.turnMain("w")
        self.assertIs(self.me.location, room1)
        self.assertEqual(self.app.print_stack.pop(), room1.w_false_msg)

        self.game.turnMain("nw")
        self.assertIs(self.me.location, room1)
        self.assertEqual(self.app.print_stack.pop(), room1.nw_false_msg)

        self.game.turnMain("u")
        self.assertIs(self.me.location, room1)
        self.assertEqual(self.app.print_stack.pop(), room1.u_false_msg)

        self.game.turnMain("d")
        self.assertIs(self.me.location, room1)
        self.assertEqual(self.app.print_stack.pop(), room1.d_false_msg)

        self.game.turnMain("in")
        self.assertIs(self.me.location, room1)
        self.assertEqual(self.app.print_stack.pop(), room1.entrance_false_msg)

        self.game.turnMain("out")
        self.assertIs(self.me.location, room1)
        self.assertEqual(self.app.print_stack.pop(), room1.exit_false_msg)
示例#12
0
 def setUp(self):
     self.app = TestApp()
     self.game = IFPGame(self.app, main=__name__)
     self.me = Player(self.game)
     self.start_room = Room(self.game, "room", "desc")
     self.start_room.addThing(self.me)
     self.game.setPlayer(self.me)
     self.game.initGame()
示例#13
0
 def test_add_remove_item_with_lock_from_Room(self):
     parent = Room(self.game, "parent", "This is a room. ")
     parent.revealed = True
     child = Container(self.game, "child")
     child.has_lid = True
     lock = Lock(self.game, "lock", None)
     child.setLock(lock)
     self._assert_can_add_remove(parent, child)
示例#14
0
 def test_cannot_set_non_lock_as_door_lock(self):
     room2 = Room(
         self.game, "A different place", "Description of a different place. "
     )
     c = DoorConnector(self.game, self.start_room, "n", room2, "s")
     lock = Surface(self.game, "lock?")
     with self.assertRaises(IFPError):
         c.setLock(lock)
示例#15
0
    def test_can_travel_TravelConnector(self):
        self.me.position = "sitting"
        room1 = Room(self.game, "A place", "Description of a place. ")
        room2 = Room(
            self.game, "A different place", "Description of a different place. "
        )
        c = TravelConnector(self.game, room1, "n", room2, "s")
        c.entrance_a_msg = "You creep north. "

        self._assert_can_travel(room1, room2, "n", "s")
        self.assertIn("You stand up. ", self.app.print_stack)
        self.assertEqual(self.me.position, "standing")
        self.assertIn(c.entrance_a_msg, self.app.print_stack)
        self.assertIn("You go through the south doorway. ", self.app.print_stack)
        self.assertIn(
            room1.desc + "There is a doorway to the north. ", self.app.print_stack
        )
示例#16
0
 def test_create_TravelConnector_with_invalid_direction(self):
     room2 = Room(
         self.game, "A different place", "Description of a different place. "
     )
     with self.assertRaises(IFPError):
         c = TravelConnector(
             self.game, self.start_room, "lllllllrrrrrkkkk", room2, "s"
         )
示例#17
0
 def test_lock_already_attached_to_something_cannot_be_applied_to_a_door(self):
     room2 = Room(
         self.game, "A different place", "Description of a different place. "
     )
     c = DoorConnector(self.game, self.start_room, "n", room2, "s")
     lock = Lock(self.game, is_locked=True, key_obj=None)
     c.setLock(lock)
     c2 = DoorConnector(self.game, self.start_room, "e", room2, "w")
     with self.assertRaises(IFPError):
         c2.setLock(lock)
示例#18
0
    def test_move_to_removes_item_from_old_location_and_adds_to_new_location(self):
        old = Room(self.game, "old", "It is old")
        child = Thing(self.game, "child")
        old.addThing(child)

        new = Container(self.game, "new")
        child.moveTo(new)

        self.assertItemIn(child, new.contains, "Item not added to new location")
        self.assertItemNotIn(child, old.contains, "Item not removed from old location")
        self.assertIs(child.location, new, "Item not added to new location")
示例#19
0
    def test_look(self):
        room = Room(self.game, "Strange Room", "It's strange in here. ")
        item = Thing(self.game, "hullabaloo")
        item.describeThing("All around is a hullabaloo. ")
        room.addThing(item)

        self.me.location.removeThing(self.me)
        room.addThing(self.me)

        self.game.turnMain("look")
        look_desc = self.app.print_stack.pop()
        look_title = self.app.print_stack.pop()

        self.assertIn(room.name, look_title, f"Room title printed incorrectly")
        self.assertIn(room.desc, look_desc, "Room description not printed by look")
        self.assertIn(item.desc, look_desc, "Item description not printed by look")
示例#20
0
    def test_implicit_exit_container(self):
        meta_thing = Container(self.game, "metabox")
        thing = Container(self.game, "box")
        thing.moveTo(meta_thing)
        meta_thing.moveTo(self.start_room)
        self.game.me.moveTo(thing)

        room2 = Room(self.game, "new place", "You are in a new place.")
        self.start_room.east = room2

        self.assertTrue(self.start_room.subLevelContainsItem(self.game.me))

        self.game.turnMain("e")

        self.assertFalse(thing.containsItem(self.game.me),
                         "Player should have left the Container")
        self.assertFalse(self.start_room.subLevelContainsItem(self.game.me))
示例#21
0
    def test_cannot_travel_if_barrier_function_blocks(self):
        room2 = Room(
            self.game, "A different place", "Description of a different place. "
        )
        c = TravelConnector(self.game, self.start_room, "n", room2, "s")
        c.barrierFunc = lambda g: True

        self.assertItemIn(
            self.me, self.start_room.contains, "test needs player to start here"
        )
        self.assertIs(self.start_room.north, c)

        self.game.turnMain("n")

        self.assertIs(self.me.location, self.start_room)
        self.assertItemIn(
            self.me, self.start_room.contains, "player should not have moved"
        )
示例#22
0
    def test_move_to_removes_item_from_old_superlocation_subcontains(self):
        room = Room(self.game, "old", "It is old")
        old = Container(self.game, "box")
        room.addThing(old)
        child = Thing(self.game, "child")
        old.addThing(child)

        new = Container(self.game, "new")

        self.assertItemIn(
            child, room.sub_contains, "Item not removed from old location"
        )

        child.moveTo(new)

        self.assertItemNotIn(
            child, room.sub_contains, "Item not removed from old location"
        )
        self.assertIs(child.location, new, "Item not added to new location")
示例#23
0
    def test_cannot_travel_blocked_connector(self):
        room2 = Room(
            self.game, "A different place", "Description of a different place. "
        )
        c = TravelConnector(self.game, self.start_room, "n", room2, "s")
        c.can_pass = False

        self.assertItemIn(
            self.me, self.start_room.contains, "test needs player to start here"
        )
        self.assertIs(self.start_room.north, c)

        self.game.turnMain("n")

        self.assertIn(c.cannot_pass_msg, self.app.print_stack)

        self.assertIs(self.me.location, self.start_room)
        self.assertItemIn(
            self.me, self.start_room.contains, "player should not have moved"
        )
示例#24
0
    def test_cannot_travel_in_darkness(self):
        room2 = Room(
            self.game, "A different place", "Description of a different place. "
        )
        c = TravelConnector(self.game, self.start_room, "n", room2, "s")
        self.start_room.dark = True

        self.assertItemIn(
            self.me, self.start_room.contains, "test needs player to start here"
        )
        self.assertIs(self.start_room.north, c)

        self.game.turnMain("n")

        self.assertIn("It's too dark to find your way. ", self.app.print_stack)

        self.assertIs(self.me.location, self.start_room)
        self.assertItemIn(
            self.me, self.start_room.contains, "player should not have moved"
        )
示例#25
0
    def test_move_nested_item_between_locations(self):
        room2 = Room(self.game, "room", "here")
        container = Container(self.game, "cup")
        item = Thing(self.game, "bead")

        item.moveTo(container)
        container.moveTo(self.start_room)

        self.assertIs(container.location, self.start_room)
        self.assertIs(item.location, container)
        self.assertTrue(container.topLevelContainsItem(item))

        container.moveTo(room2)

        self.assertIs(container.location, room2)
        self.assertIs(
            item.location,
            container,
            "Nested item location was updated when container was moved",
        )
        self.assertTrue(container.topLevelContainsItem(item))
示例#26
0
    def test_cannot_travel_closed_and_locked_door(self):
        room2 = Room(
            self.game, "A different place", "Description of a different place. "
        )
        c = DoorConnector(self.game, self.start_room, "n", room2, "s")
        lock = Lock(self.game, is_locked=True, key_obj=None)
        c.setLock(lock)

        self.assertItemIn(
            self.me, self.start_room.contains, "test needs player to start here"
        )
        self.assertIs(self.start_room.north, c)

        self.game.turnMain("n")

        self.assertIn(
            f"{c.entrance_a.capNameArticle(True)} is locked. ", self.app.print_stack
        )

        self.assertIs(self.me.location, self.start_room)
        self.assertItemIn(
            self.me, self.start_room.contains, "player should not have moved"
        )
示例#27
0
 def test_add_remove_from_Room(self):
     parent = Room(self.game, "parent", "This is a room. ")
     child = Thing(self.game, "child")
     self._assert_can_add_remove(parent, child)
示例#28
0
silverkey = Key(game)
silverkey.setAdjectives(["silver"])

rustykey = Key(game)
rustykey.setAdjectives(["rusty"])

opal = Thing(game, "opal")
opal.makeUnique()
opal.size = 25

# ROOMS

# Start Room (Shack Interior)
startroom = Room(
    game,
    "Shack interior",
    "You are standing in a one room shack. Light filters in through a cracked, dirty window. ",
)

me.moveTo(startroom)

# ABSTRACT CONCEPTS
# Use "Abstract" items to create topics of discussion (for ask/tell Topics) that do not
# correlate to a physical item. Alternately, use them to track player knowledge
storm_concept = Abstract(game, "storm")
shack_concept = Abstract(game, "shack")
shack_concept.setAdjectives(["one", "room"])
shack_concept.makeKnown(me)


def takeOpalFunc(game):
示例#29
0
 def test_add_remove_composite_item_from_Room(self):
     parent = Room(self.game, "parent", "This is a room. ")
     child = Thing(self.game, "child")
     sub = Thing(self.game, "sub")
     child.addComposite(sub)
     self._assert_can_add_remove(parent, child)