def test_monster_combat(self, mock_stdout, mock_select_a_monster, mock_input): random.seed(1) new_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]} expected_output = """You've encountered a Rancor! You successfully ran away without taking damage!\n""" monster_combat(new_character) self.assertEqual(mock_stdout.getvalue(), expected_output) random.seed()
def test_2nd_monster_combat(self, mock_stdout, mock_select_a_monster, mock_input): random.seed(3) new_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]} expected_output = """You've encountered a Krayt Dragon! Dustin hits for 2 The new health of the Krayt Dragon is 3 The Krayt Dragon hits for 5 The new health of Dustin is 5 Dustin hits for 5 The new health of the Krayt Dragon is -2 The Krayt Dragon has died\n""" monster_combat(new_character) self.assertEqual(mock_stdout.getvalue(), expected_output) random.seed()
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")