def test_game_over_reset(self):
     character.set_hp(0)
     try:
         game_over()
     except SystemExit:
         pass
     self.assertEqual(10, character.get_hp())
 def test_restart_game_reset(self, mock_input):
     character.set_hp(0)
     try:
         restart_game()
     except SystemExit:
         pass
     self.assertEqual(10, character.get_hp())
Example #3
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)
Example #5
0
 def test_quit_game_save_game(self):
     character.set_hp(5)
     try:
         quit_game()
     except SystemExit:
         pass
     character.set_hp(10)
     load_game()
     self.assertEqual(5, character.get_hp())
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'])
Example #7
0
 def test_set_hp(self):
     character.set_hp(3)
     self.assertEqual(3, character.hp)
 def test_combat_flee_dead(self, mock_combat_flee):
     character.set_hp(0)
     self.assertEqual(False, combat())
Example #9
0
 def test_game_event_no_heal(self, mock_random):
     character.set_hp(10)
     game_event()
     self.assertEqual(10, character.get_hp())
 def test_combat_lose_print(self, mock_stdout, mock_combat_flee, mock_roll,
                            mock_input):
     character.set_hp(10)
     combat()
     self.assertTrue("DEFEATED" in mock_stdout.getvalue())
 def test_combat_lose(self, mock_combat_flee, mock_roll, mock_input):
     character.set_hp(10)
     self.assertEqual(False, combat())
 def test_combat_win_print(self, mock_stdout, mock_combat_flee, mock_roll,
                           mock_input):
     character.set_hp(10)
     combat()
     self.assertTrue("ENEMY DESTROYED" in mock_stdout.getvalue())
 def test_combat_win(self, mock_combat_flee, mock_roll, mock_input):
     character.set_hp(10)
     self.assertEqual(True, combat())
 def test_combat_flee_alive(self, mock_combat_flee):
     character.set_hp(10)
     self.assertEqual(True, combat())