예제 #1
0
 def test_hallway_guard(self):
     hallway = HallwayRoom()
     guard = Guard("Guard 1")
     before = len(hallway.items)
     self.assertNotIn(guard, hallway.items)
     hallway.add_item(guard)
     self.assertEqual(len(hallway.items), before + 1)
     self.assertIn(guard, hallway.items)
예제 #2
0
    def test_describe(self):
        hallway = HallwayRoom()
        self.assertIn(hallway.about, hallway.describe())

        # after the first visit, the description is omitted
        self.assertNotIn(hallway.about, hallway.describe())

        # full description can be shown again if requested
        self.assertIn(hallway.about, hallway.describe(verbose=True))
예제 #3
0
    def test_add_exit_by_alias(self):
        hallway = HallwayRoom()
        outside = OutsideRoom()

        before = len(hallway.exits)
        self.assertNotIn("northwest", hallway.exits)

        hallway.add_exit("nw", outside)

        self.assertEqual(len(hallway.exits), before + 1)
        self.assertIn("northwest", hallway.exits)
        self.assertEqual(hallway.exits["northwest"], outside)
예제 #4
0
    def test_possible_exits(self):
        """test that possible_exits returns a list of directions"""
        room = HallwayRoom()

        # initially, there are no exits
        self.assertEqual(room.possible_exits(), [])

        room.add_exit("north", room)
        self.assertEqual(room.possible_exits(), ["north"])

        room.add_exit("south", room)
        self.assertEqual(room.possible_exits(), ["north", "south"])
예제 #5
0
    def test_room_traversal(self):
        start_room = OutsideRoom()
        end_room = HallwayRoom()

        start_room.add_exit("north", end_room)

        end_room.add_item(Item("feather"))

        self.assertIn(start_room.about, start_room.describe())
        self.assertTrue(start_room.describe().startswith(start_room.name))

        possible_exits = start_room.possible_exits()
        new_room = start_room.move(possible_exits[0])
        self.assertIsInstance(new_room, Room)
        self.assertEqual(new_room.about, end_room.about)
        self.assertIn(end_room.about, new_room.describe())
        self.assertIn("feather", new_room.describe())

        possible_exits = new_room.possible_exits()
        self.assertEqual(possible_exits, [])
예제 #6
0
    def setUp(self):
        super(TestScript, self).setUp()
        self.player = Player(gender="male", age="10", hair_color="blue")

        # capture stdout from game loop
        self.stdout = StringIO.StringIO()
        self._orig_stdout = sys.stdout
        sys.stdout = self.stdout

        # initialize rooms
        outside = OutsideRoom()

        hallway = HallwayRoom()
        guard = Guard("Guard 1")
        hallway.add_item(guard)

        # connect rooms
        outside.add_exit("in", hallway)
        hallway.add_exit("out", outside)

        # initialize game and play
        player = Player(gender="female", age="74", hair_color="red")

        self.game = Game(player, rooms=[outside, hallway], script=["quit"])
예제 #7
0
    def test_move_by_alias(self):
        hallway = HallwayRoom()
        outside = OutsideRoom()
        hallway.add_exit("north", outside)

        self.assertEqual(hallway.move("n"), outside)
예제 #8
0
    def test_move_non_exit(self):
        hallway = HallwayRoom()
        outside = OutsideRoom()
        hallway.add_exit("north", outside)

        self.assertIsNone(hallway.move("south"))