Пример #1
0
 def test_store1_new_character(self, mock_stdout):
     new_character = {
         'Charisma': 5,
         'Class': 'Jedi Knight',
         'Constitution:': 4,
         'Dexterity': 7,
         'HP': 6,
         'Intelligence': 14,
         'Inventory': 'Lightsaber - Blue',
         'Name': 'Dustin',
         'Position': [3, 4],
         'Strength': 6,
         'Wisdom': 18,
         'XP': 0
     }
     expected_output = "Thanks for playing! We'll remember you when you come back, Dustin\n"
     store_new_character(new_character)
     self.assertEqual(mock_stdout.getvalue(), expected_output)
Пример #2
0
 def test_store4_new_character(self, mock_stdout):
     new_character = {
         'Charisma': 5,
         'Class': 'Imperial Agent',
         'Constitution:': 10,
         'Dexterity': 7,
         'HP': 6,
         'Intelligence': 18,
         'Inventory': 'Blaster Rifle',
         'Name': 'IG-88',
         'Position': [2, 7],
         'Strength': 6,
         'Wisdom': 5,
         'XP': 0
     }
     expected_output = "Thanks for playing! We'll remember you when you come back, IG-88\n"
     store_new_character(new_character)
     self.assertEqual(mock_stdout.getvalue(), expected_output)
Пример #3
0
 def test_store3_new_character(self, mock_stdout):
     new_character = {
         'Charisma': 5,
         'Class': 'Sith Warrior',
         'Constitution:': 4,
         'Dexterity': 7,
         'HP': 6,
         'Intelligence': 14,
         'Inventory': 'Lightsaber - Red',
         'Name': 'Destroyer of Worlds',
         'Position': [1, 1],
         'Strength': 6,
         'Wisdom': 18,
         'XP': 0
     }
     expected_output = "Thanks for playing! We'll remember you when you come back, Destroyer of Worlds\n"
     store_new_character(new_character)
     self.assertEqual(mock_stdout.getvalue(), expected_output)
Пример #4
0
 def test_second_option_new_or_old_character(self,
                                             mock_new_or_old_character,
                                             mock_create_character):
     old_character = {
         "Name": "Dustin",
         "Class": "Imperial Agent",
         "HP": 10,
         "Strength": 17,
         "Dexterity": 5,
         "Constitution:": 13,
         "Intelligence": 3,
         "Wisdom": 9,
         "Charisma": 3,
         "XP": 0,
         "Inventory": "Sniper Rifle",
         "Position": [2, 4]
     }
     store_new_character(old_character)
     self.assertEqual(new_or_old_character(), old_character)
Пример #5
0
def main():
    # Prints intro then sets up the game board
    print_intro()
    new_board = create_game_board()
    new_board = set_border(new_board)
    # Determines if user needs to create a new character or not
    new_character = load_character.new_or_old_character()
    # Places the character on the board depending on their 'Position' key
    if new_character['Position'] == (7, 4):
        starting_position(new_board)
    else:
        place_character(new_board, new_character)
        print_game_board(new_board)

    # Begins the game loop
    continue_game = True
    while continue_game is True:
        user_input = input(
            "Type n, s, w, e to move north, south, west, or east. Type 'h' to see your health"
            " or type 'quit' to exit\n")
        # If the user enters 'n' - call move_north function and set their position
        if user_input == "n":
            move_north(new_board)
            set_position(new_board, new_character)
            # Call randint(1, 10) to determine if they have encountered a monster
            monster_chance = random.randint(1, 10)
            if monster_chance == 1:
                monster.monster_combat(new_character)
            # If characters 'HP' equals 0 or goes below 0 then end the game
            if new_character['HP'] <= 0:
                print("Your character has died, game over")
                continue_game = False
            # Increase character's health by 1
            if monster_chance != 1:
                character.increase_character_health(new_character)

        # If the user enters 's' - call move_south function and set their position
        elif user_input == "s":
            move_south(new_board)
            set_position(new_board, new_character)
            monster_chance = random.randint(1, 10)
            if monster_chance == 1:
                monster.monster_combat(new_character)
            if new_character['HP'] <= 0:
                print("Your character has died, game over")
                continue_game = False
            if monster_chance != 1:
                character.increase_character_health(new_character)

        # If the user enters 'w' - call move_west function and set their position
        elif user_input == "w":
            move_west(new_board)
            set_position(new_board, new_character)
            monster_chance = random.randint(1, 10)
            if monster_chance == 1:
                monster.monster_combat(new_character)
            if new_character['HP'] <= 0:
                print("Your character has died, game over")
                continue_game = False
            if monster_chance != 1:
                character.increase_character_health(new_character)

        # If the user enters 'e' - call move_east function and set their position
        elif user_input == "e":
            move_east(new_board)
            set_position(new_board, new_character)
            monster_chance = random.randint(1, 10)
            if monster_chance == 1:
                monster.monster_combat(new_character)
            if new_character['HP'] <= 0:
                print("Your character has died, game over")
                continue_game = False
            if monster_chance != 1:
                character.increase_character_health(new_character)

        # If the user enters 'h' - call get_character_health function
        elif user_input == "h":
            character.get_character_health(new_character)

        # If the user enters 'quit' - store the character and end the game
        elif user_input == "quit":
            load_character.store_new_character(new_character)
            continue_game = False
        else:
            print("That was not correct input, try again")