def test_move_character_north(self):
     test_character = Character('Chris', 10, [2, 2], 0)
     actual_return = move_character(test_character, 'N')
     expected_return = True
     expected_coordinates = [1, 2]
     actual_coordinates = test_character.get_coordinate()
     self.assertEqual(expected_return, actual_return)
     self.assertEqual(expected_coordinates, actual_coordinates)
 def test_move_character_upper_boundary(self):
     test_character = Character('Chris', 10, [1, 4], 0)
     actual_return = move_character(test_character, 'E')
     expected_return = False
     expected_coordinates = [1, 4]
     actual_coordinates = test_character.get_coordinate()
     self.assertEqual(expected_return, actual_return)
     self.assertEqual(expected_coordinates, actual_coordinates)
Example #3
0
def game_loop(char: character.Character):
    """The main loop of the game.

    For each non-combat turn, this loop draws the game map, display map description for the coordinates the player
    is on, display player HP and number of kills, and asks which direction the player wants to move to.
    PARAM: An instance belonging to the class 'Character'.
    PRECONDITION: The parameter must be an instance belonging to the class 'Character'.
    POSTCONDITION: A character can only move to a position that is not a physical boundary. If a player chooses to
    quit, they can choose to save the game or quit without saving.
    RETURN: N/A.
    """
    print(
        "-------------------------------------------------------------------------------\n"
    )
    print(
        "You find yourself in a dark house, the children are near...which way do you go?"
    )
    while True:
        map_and_movement.draw_map(char)
        # Draws game map and character position
        dialogue_and_scripts.map_description(char)
        # Prints map dialogue
        print(dialogue_and_scripts.display_stats(char))
        # Prints player HP and number of kills
        directions = ['N', 'S', 'E', 'W']
        move_input = input(
            "\nWhich direction would you like to go? (Enter 'Q' or 'Quit' to quit)\n"
        ).title().strip()
        print(
            "-------------------------------------------------------------------------------"
        )
        if move_input == 'Q' or move_input == 'Quit':
            save_and_load.choose_to_save(char)
            # Lets player decide if they want to save or not.
            sys.exit()
        elif move_input not in directions:
            print('\nThat is not a valid command.\n'
                  'Enter "N", "S", "E", or "W"')
        elif move_input in directions:
            character_move = map_and_movement.move_character(char, move_input)
            # Moves character to a new position on the map if True
            # Keeps character in the same position on the map if False
            if character_move is True:
                combat.chance_of_engagement(char)
                # Decides if an enemy will appear and engage the character
            if character_move is False:
                pass