Пример #1
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.entrance_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.exit_msg)

        self.assertIs(
            self.me.location,
            room1,
            f"Tried to travel out to {room1}, '{room1.name}', but player in "
            f"{self.me.location}",
        )
Пример #2
0
    def test_travel_southeast_northwest(self):
        room1 = Room(self.game, "A place", "Description of a place. ")
        room2 = Room(self.game, "A different place",
                     "Description of a different place. ")
        room1.southeast = room2
        room2.northwest = 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 southeast")

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

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

        self.game.turnMain("go northwest")

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

        self.assertIs(
            self.me.location,
            room1,
            f"Tried to travel northwest to {room1}, '{room1.name}', but player in "
            f"{self.me.location}",
        )
Пример #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_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,
        )
Пример #5
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
Пример #6
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"
         )
Пример #7
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)
Пример #8
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
        )
Пример #9
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)
Пример #10
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")
Пример #11
0
 def setUp(self):
     super().setUp()
     self.room2 = Room(self.game, "A hot room",
                       "This room is uncomfortably hot. ")
     self.door = DoorConnector(self.game, self.start_room, "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)
Пример #12
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))
Пример #13
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"
        )
Пример #14
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"
        )
Пример #15
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"
        )
Пример #16
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))
Пример #17
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")
Пример #18
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"
        )
Пример #19
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)
Пример #20
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):
Пример #21
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.in_false_msg)

        self.game.turnMain("out")
        self.assertIs(self.me.location, room1)
        self.assertEqual(self.app.print_stack.pop(), room1.out_false_msg)
Пример #22
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)