Пример #1
0
 def test_play_game_move(self, mock_stdout, mock_input, mock_game_event):
     character.set_coordinates(20, 20)
     try:
         play_game()
     except SystemExit:
         pass
     self.assertEqual((20, 19), character.get_coordinates())
Пример #2
0
 def test_play_game_game_event(self, mock_stdout, mock_input, mock_random):
     character.set_hp(9)
     character.set_coordinates(20, 20)
     try:
         play_game()
     except SystemExit:
         pass
     self.assertEqual(10, character.get_hp())
    def test_save_game(self):
        character.set_hp(6)
        character.set_coordinates(21, 21)
        save.save_game()

        with open('character.json') as file_object:
            current_character = json.load(file_object)

        self.assertEqual({"hp": 6, "column": 21, "row": 21}, current_character)
Пример #4
0
def load_game():
    """
    Load character data from character.json.

    POST-CONDITION character data is loaded and character is updated
    """

    try:
        with open('character.json') as file_object:
            char = json.load(file_object)
            character.set_hp(char['hp'])
            character.set_coordinates(char['column'], char['row'])

    except FileNotFoundError:
        char = {"hp": 10, "column": 29, "row": 16}
        character.set_hp(char['hp'])
        character.set_coordinates(char['column'], char['row'])
 def test_move_out_of_bound_return(self):
     character.set_coordinates(1, 4)
     self.assertEqual(False, character.move("west"))
 def test_move_out_of_bound(self, mock_stdout):
     character.set_coordinates(1, 4)
     character.move("west")
     self.assertTrue("OUT OF BOUND" in mock_stdout.getvalue())
 def test_move_valid_return(self):
     character.set_coordinates(10, 10)
     self.assertEqual(True, character.move("north"))
 def test_move_east_valid(self):
     character.set_coordinates(10, 10)
     character.move("east")
     self.assertEqual((11, 10), character.coordinates)
 def test_move_south_valid(self):
     character.set_coordinates(10, 10)
     character.move("south")
     self.assertEqual((10, 11), character.coordinates)
 def test_set_coordinates(self):
     character.set_coordinates(20, 20)
     self.assertEqual((20, 20), character.coordinates)