示例#1
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
 def test_map_description_position_1_1(self, mock_stdout):
     test_character = Character('Jihyo', 10, [1, 1], 0)
     dialogue_and_scripts.map_description(test_character)
     expected_stdout = "You are at the northwest corner of the house. You feel weird facing a corner."
     self.assertIn(expected_stdout, mock_stdout.getvalue())
 def test_map_description_position_3_3(self, mock_stdout):
     test_character = Character('Jihyo', 10, [3, 3], 0)
     dialogue_and_scripts.map_description(test_character)
     expected_stdout = "You look around the house, to the south is the master bedroom."
     self.assertIn(expected_stdout, mock_stdout.getvalue())
 def test_map_description_position_3_2(self, mock_stdout):
     test_character = Character('Jihyo', 10, [3, 2], 0)
     dialogue_and_scripts.map_description(test_character)
     expected_stdout = "You are between the living room and the kitchen. The living room is to your north"
     " and to the south is the kitchen."
     self.assertIn(expected_stdout, mock_stdout.getvalue())
 def test_map_description_position_3_1(self, mock_stdout):
     test_character = Character('Jihyo', 10, [3, 1], 0)
     dialogue_and_scripts.map_description(test_character)
     expected_stdout = "You are between the living room and the kitchen. A small window overlooks the garden."
     self.assertIn(expected_stdout, mock_stdout.getvalue())
 def test_map_description_position_2_4(self, mock_stdout):
     test_character = Character('Jihyo', 10, [2, 4], 0)
     dialogue_and_scripts.map_description(test_character)
     expected_stdout = "This bedroom is small, there is a bunk bed against the wall littered with stuffed animals."
     self.assertIn(expected_stdout, mock_stdout.getvalue())
 def test_map_description_position_2_3(self, mock_stdout):
     test_character = Character('Jihyo', 10, [2, 3], 0)
     dialogue_and_scripts.map_description(test_character)
     expected_stdout = "You are near the center of the house, a photo of a family hangs on the wall. "
     "Where can they be hiding..."
     self.assertIn(expected_stdout, mock_stdout.getvalue())
 def test_map_description_position_4_2(self, mock_stdout):
     test_character = Character('Jihyo', 10, [4, 2], 0)
     dialogue_and_scripts.map_description(test_character)
     expected_stdout = "You look around and open the refrigerator, there are some leftover spaghetti and meatloaf."
     self.assertIn(expected_stdout, mock_stdout.getvalue())
 def test_map_description_position_2_1(self, mock_stdout):
     test_character = Character('Jihyo', 10, [2, 1], 0)
     dialogue_and_scripts.map_description(test_character)
     expected_stdout = "Snacks and tea are on the living room table, the tea is still steaming..."
     self.assertIn(expected_stdout, mock_stdout.getvalue())
示例#10
0
 def test_map_description_position_1_4(self, mock_stdout):
     test_character = Character('Jihyo', 10, [1, 4], 0)
     dialogue_and_scripts.map_description(test_character)
     expected_stdout = "This is a bedroom, it is small. Perhaps it belonged to a child."
     self.assertIn(expected_stdout, mock_stdout.getvalue())
示例#11
0
 def test_map_description_position_1_3(self, mock_stdout):
     test_character = Character('Jihyo', 10, [1, 3], 0)
     dialogue_and_scripts.map_description(test_character)
     expected_stdout = "This is the entrance to the house. Through the shadows you can "
     "see the living room to your west and a small bedroom to your east."
     self.assertIn(expected_stdout, mock_stdout.getvalue())
示例#12
0
 def test_map_description_position_1_2(self, mock_stdout):
     test_character = Character('Jihyo', 10, [1, 2], 0)
     dialogue_and_scripts.map_description(test_character)
     expected_stdout = "You enter the living room, looks like a cozy home..."
     self.assertIn(expected_stdout, mock_stdout.getvalue())
示例#13
0
 def test_map_description_position_4_4(self, mock_stdout):
     test_character = Character('Jihyo', 10, [4, 4], 0)
     dialogue_and_scripts.map_description(test_character)
     expected_stdout = "You open the walk-in closet in the master bedroom. Perhaps they are hiding here..."
     self.assertIn(expected_stdout, mock_stdout.getvalue())
示例#14
0
 def test_map_description_position_4_3(self, mock_stdout):
     test_character = Character('Jihyo', 10, [4, 3], 0)
     dialogue_and_scripts.map_description(test_character)
     expected_stdout = "This is the master bedroom. There is a king-sized bed with maroon bedsheets."
     "They smelled like they had just been changed."
     self.assertIn(expected_stdout, mock_stdout.getvalue())
示例#15
0
 def test_map_description_position_3_4(self, mock_stdout):
     test_character = Character('Jihyo', 10, [3, 4], 0)
     dialogue_and_scripts.map_description(test_character)
     expected_stdout = "You look outside the window, there is a full moon tonight."
     self.assertIn(expected_stdout, mock_stdout.getvalue())
示例#16
0
 def test_map_description_position_4_1(self, mock_stdout):
     test_character = Character('Jihyo', 10, [4, 1], 0)
     dialogue_and_scripts.map_description(test_character)
     expected_stdout = "You enter the kitchen and opened one of the cabinets, "
     "considering to choose another weapon.\nYou decided to stick with the kitchen knife."
     self.assertIn(expected_stdout, mock_stdout.getvalue())
示例#17
0
 def test_map_description_position_2_2(self, mock_stdout):
     test_character = Character('Jihyo', 10, [2, 2], 0)
     dialogue_and_scripts.map_description(test_character)
     expected_stdout = "There is a big TV in this living room. You stop and stare into the reflection.\n"
     "A masked figure mask stares back."
     self.assertIn(expected_stdout, mock_stdout.getvalue())