Example #1
0
    def test_can_move_print_output_with_valid_arguments(self, mock_stdout):
        """Test can_move if it prints output properly with valid arguments.

        The result is expected True
        """
        moving.can_move('n', 1, randint(1, 8))
        expected_output = "You can't move that way!\n"
        self.assertEqual(mock_stdout.getvalue(), expected_output)
Example #2
0
def play(user: dict) -> None:
    """Get a dictionary(user's info) and play game.

    Until user input 'quit', keep playing game
    check if user's input is valid, if so move inside boundary
    if user encounters monster, ask whether fight or run away
    if user tries to run away, monster hits user as much as 1d4 by 10 percent chance
    if user fight, invoke combat() to death
    if user doesn't encounter monster and user's hp is below 10, up 1hp each move
    if user input invalid input for direction, print helpful message
    PARAM: user, a dictionary
    PRECONDITION: user, must be a dictionary has valid keys and values
    POSTCONDITION: Print helpful message when user input invalid string
    """
    user_input = ""
    map.show_map(user)
    while user_input != "quit":
        user_input = input(
            "Which way do you want to go? (E/W/N/S) ").strip().lower()
        if moving.can_move(user_input, user['row'], user['column']):
            moving.move(user_input, user)
            if monster.encounter_monster():
                combat.fight_or_run_away(user)
                if combat.is_dead(user):
                    user[
                        'Hp'], user_input = 10, "quit"  # Hp full up for the next game, and quit the game.
            else:
                support_function.up_1_hp(user)
        elif user_input == "quit":
            support_function.save_user_info(user)
        else:
            print("Enter the direction again please.")
Example #3
0
    def test_can_move_fourth_condition_with_invalid_arguments(self):
        """Test the fourth condition of can_move with valid arguments.
        user_input in ['west', 'w'] and column == 2

        The result is expected True
        """
        self.assertTrue(moving.can_move('w', randint(1, 8), 2))
Example #4
0
    def test_can_move_third_condition_with_invalid_arguments(self):
        """Test the third condition of can_move with invalid arguments.
        user_input in ['south', 's'] and row == map.get_map_size() - 3

        The result is expected True
        """
        self.assertTrue(moving.can_move('s', 5, randint(1, 8)))
Example #5
0
    def test_can_move_second_condition_with_invalid_arguments(self):
        """Test the second condition of can_move with invalid arguments.
        user_input in ['east', 'e'] and column == map.get_map_size() - 3

        The result is expected True
        """
        self.assertTrue(moving.can_move('e', randint(1, 8), 5))
Example #6
0
    def test_can_move_first_condition_with_invalid_arguments(self):
        """Test first condition of can_move with invalid arguments.
        user_input in ['north', 'n'] and row == 2

        The result is expected True
        """
        self.assertTrue(moving.can_move('n', 2, randint(1, 8)))
Example #7
0
    def test_can_move_first_condition_with_valid_arguments(self):
        """Test the first condition of can_move with valid arguments.
        user_input in ['north', 'n'] and row == 1

        The result is expected false
        """
        self.assertFalse(moving.can_move('n', 1, randint(1, 8)))
Example #8
0
    def test_can_move_with_invalid_string(self):
        """Test can_move with invalid string which is not in directions.

        The result is expected False
        """
        self.assertEqual(moving.can_move('anything other than directions', 1, 1), False)