Example #1
0
    def test_reload_game(self, mock_get_user_name):

        # Create a new game
        original_game = comp_1510_a1.start_game()

        # Modify that game manually
        original_game["hp"] = 7
        original_game["row_loc"] = 2
        original_game["col_loc"] = 1
        original_game["sud_map"][0][0]['appearance'] = "[ ]"
        original_game["sud_map"][2][1]['appearance'] = "[X]"

        # Save game over the game we just created
        comp_1510_a1.save(original_game)

        # Check if the json values changed
        with open('reload_test_dont_modify.json') as file_object:
            content = json.load(file_object)
            self.assertEqual(7, content["hp"])
            self.assertEqual(2, content['row_loc'])
            self.assertEqual(1, content['col_loc'])
            self.assertEqual('[X]', content['sud_map'][2][1]['appearance'])

        # Reload the game
        comp_1510_a1.reload_game(original_game)

        # Check if the json values are back to default
        with open('reload_test_dont_modify.json') as file_object:
            content = json.load(file_object)
            self.assertEqual(10, content["hp"])
            self.assertEqual(0, content['row_loc'])
            self.assertEqual(0, content['col_loc'])
            self.assertEqual('[ ]', content['sud_map'][2][1]['appearance'])
            self.assertEqual('[X]', content['sud_map'][0][0]['appearance'])
Example #2
0
def restart_or_quit():
    """Let the player choose between playing again or exiting the game.

    PARAM: N/A
    PRECONDITION: This function is only called when an user dies or quits the game.
    POSTCONDITION: Either the main() game function is called again to restart the game or the game exits.
    RETURN: N/A.
    """
    choice_to_play_again = input("\nWould you like to play again? (Y / N)\n").title()
    if choice_to_play_again == 'Y':
        comp_1510_a1.start_game()
        # Restarts game
    elif choice_to_play_again == 'N':
        sys.exit()
        # Exits game
    else:
        print('That is not a valid command.')
Example #3
0
 def test_start_game_start_new_game(self, mock_input, mock_character):
     test_character = Character('Kevin', 10, [1, 3], 0)
     save_game(test_character)
     actual_character = comp_1510_a1.start_game()
     self.assertEqual(test_character.get_name(),
                      actual_character.get_name())
     self.assertEqual(test_character.get_health(),
                      actual_character.get_health())
     self.assertEqual(test_character.get_coordinate(),
                      actual_character.get_coordinate())
     self.assertEqual(test_character.get_kill_count(),
                      actual_character.get_kill_count())
     do_not_save(test_character)
Example #4
0
 def test_start_game_start_load_game(self, mock_stdout, mock_input):
     test_character = Character('Kevin', 10, [1, 3], 0)
     save_game(test_character)
     actual_character = comp_1510_a1.start_game()
     expected_stdout = 'I see you could not resist your lust for blood.'
     self.assertIn(expected_stdout, mock_stdout.getvalue())
     self.assertEqual(test_character.get_name(),
                      actual_character.get_name())
     self.assertEqual(test_character.get_health(),
                      actual_character.get_health())
     self.assertEqual(test_character.get_coordinate(),
                      actual_character.get_coordinate())
     self.assertEqual(test_character.get_kill_count(),
                      actual_character.get_kill_count())
     do_not_save(test_character)
Example #5
0
 def test_start_game_invalid_command(self, mock_stdout, mock_input):
     with self.assertRaises(SystemExit):
         comp_1510_a1.start_game()
         expected_stdout = "That is not a valid command."
         self.assertIn(expected_stdout, mock_stdout.getvalue())
Example #6
0
 def test_start_game_under_18(self, mock_stdout, mock_input):
     with self.assertRaises(SystemExit):
         comp_1510_a1.start_game()
         expected_stdout = "DISCLAIMER: This game is rated 'M' for MATURE, are you over 18? (Y / N)"
         self.assertIn(expected_stdout, mock_stdout.getvalue())