def title_sequence():
title_file = open("title_main.txt", "r")
all_title = title_file.read()
print(all_title)
title_file.close()
def title_option(title_option):
VALID = ("new", "load", "exit")
entry = " "
print("Would you like to begin a new game, or load an old one?")
while entry not in VALID:
entry = input("Please enter either 'new' or 'load': ").lower()
return entry
def difficulty_sequence(difficulty):
VALID1 = ("easy", "hard")
difficulty = " "
while difficulty not in VALID1:
print("That is not a valid difficulty setting, please select enter either 'easy' or 'hard'.")
difficulty = input("Would you like to play on easy or hard difficulty?: ").lower()
return difficulty
import random
def easy_difficulty():
health = 100
xp = 100
enemy_spawn = random.randrange(1,4)
level_req = xp//10 + xp
health_spawn = random.randrange(1,5)
enemy_hit = random.randrange(3, 10)
easy_difficulty = {"enemy_spawn" : enemy_spawn,
"level_req" : level_req,
"health_spawn" : health_spawn,
"enemy_hit" : enemy_hit}
new_player = player.append(easy_difficulty)
return new_player
print(easy_difficulty)
def hard_difficulty():
health = 100
xp = 100
enemy_spawn = random.randrange(1,4)
level_req = xp//25 + xp
health_spawn = random.randrange (1,7)
enemy_hit = random.randrange(6,14)
hard_difficulty = {"enemy_spawn" : enemy_spawn,
"level_req" : level_req,
"health_spawn" : health_spawn,
"enemy_hit" : enemy_hit}
new_player = player.append(hard_difficulty)
return new_player
print(hard_difficulty)
def main():
player = {"health" : 100,
"xp" : 100,
"strength" : 0,
"dexterity" : 0,
"wisdom" : 0,
"enemy_spawn" : None,
"level_req" : None,
"health_spawn" : None,
"enemy_hit" : None}
choice = difficulty_sequence(difficulty)
if choice == "easy":
new_player = easy_difficulty()
player = new_player
elif choice == "hard":
new_player = hard_difficulty()
player = new_player
title_sequence()
title_option = title_option(title_option)
difficulty_sequence = difficulty_sequence(difficulty)
I'm trying to create this text based adventure game, but so far I've gotten hung up on calling variables to and from functions. Quite simply, this part of the code should display what title sequence I place in the file, ask the user which difficulty they would like to play on, then change the player stats in the main accordingly. The error occurs in the main I believe, was wondering if anyone could point me in the right direction. (Don't eat me I'm new here) Thanks!
Traceback (most recent call last):
File "C:\Users\Harry\Desktop\Python\Project\new game test.py", line 83, in <module>
main()
File "C:\Users\Harry\Desktop\Python\Project\new game test.py", line 68, in main
choice = difficulty_sequence(difficulty)
UnboundLocalError: local variable 'difficulty_sequence' referenced before assignment
difficulty_sequencefunction is up there?