コード例 #1
0
ファイル: test_game.py プロジェクト: laurahutton/first-game
    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"])
コード例 #2
0
ファイル: test_game.py プロジェクト: laurahutton/first-game
    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)
コード例 #3
0
ファイル: test_game.py プロジェクト: laurahutton/first-game
    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"])
コード例 #4
0
ファイル: test_game.py プロジェクト: laurahutton/first-game
    def test_move_by_alias(self):
        hallway = HallwayRoom()
        outside = OutsideRoom()
        hallway.add_exit("north", outside)

        self.assertEqual(hallway.move("n"), outside)
コード例 #5
0
ファイル: test_game.py プロジェクト: laurahutton/first-game
    def test_move_non_exit(self):
        hallway = HallwayRoom()
        outside = OutsideRoom()
        hallway.add_exit("north", outside)

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