Я использовал такие вещи, как def example()
, затем написал строку кода, например, что-то, что я хотел бы иметь, чтобы вернуться в меню боя, но, скажем, перед битвой я определил hp игрока в определенной переменнойменю Я получаю сообщение об ошибке в меню битвы, в котором говорится, что я ссылался на переменную здоровья игрока до того, как она была назначена, но она была назначена в последнем определении.
Единственное решение состояло в том, чтобы определить переменную в каждом определенномменю. Я определил переменные и использовал эти определения в качестве меню, к которому я могу вернуться для своей игры, например, в битве после атаки, и он вычисляет и определяет новые суммы hp, которые он возвращает тому же сценарию, который вы увидите всам код, но там, где количество hp определено в одной строке, оно не переносится на следующую, поэтому я поместил его во все из них, что привело к сбросу hp, а переменные остались прежними.
import random
def Game_start():
beater_hp = 10
beater_health = '10'
beater_mp = 0
beater_mana = '0'
beater_atk = 3
beater_attack = '3'
ogre_hp = 10
ogre_health = '10'
ogre_atk = 4
ogre_attack = '4'
wolf_hp = 5
wolf_health = '5'
wolf_atk = 2
wolf_attack = '2'
child_hp = 1
child_health = '1'
child_atk = 1
child_attack = '1'
print("its time to start your adventure!")
print("Your going to need to choose a class to start your adventure")
print("Friend: Hey! I have a really vague plot reason that explains why i want to give you this Class voucher! Here take it!")
choice = input("do you take the key story item? yes or no ")
if choice.lower() == 'no':
print("You choose not to take the only item you need to start the entire game knowing full well you need it, you disobedient little shit.")
print("you die instantly because you defied the creator. Game over")
print("would you like to restart? ")
restart = input("Yes or no? ")
if restart.lower() == 'yes':
Game_start()
if restart.lower() == 'no':
print("Okay fuck you")
if choice.lower() == 'yes':
print(inventory)
print('You gained the Class Voucher!')
inventory.insert(0,"Class Voucher")
print("you walk towards the old class machine which you remember
being placed in your town in a very mysterious way")
print("You remember the armed soldiers bringing the machine here but
thats got nothing to do with anything, you remember being told that by
your mother.")
print("you realise that was the same day your dad disappeared")
print("as you walk closer you place the Class voucher into the
machine and wait for it to allow you to choose the class that could give
you untold riches and power")
def class_menu():
beater_hp = 10
beater_health = '10'
beater_mp = 0
beater_mana = '0'
beater_atk = 3
beater_attack = '3'
ogre_hp = 10
ogre_health = '10'
ogre_atk = 4
ogre_attack = '4'
wolf_hp = 5
wolf_health = '5'
wolf_atk = 2
wolf_attack = '2'
child_hp = 1
child_health = '1'
child_atk = 1
child_attack = '1'
print("it works and the marvelous journey begins as the class menu appears")
class_ = input("Beater, Pussy, Tank, ???, Mega-Demon ")
if class_.lower() == '???':
print("you need to input a special code but it warns you of the fatal consequences if it is entered incorrectly")
print("There is a hint. Cheese")
phrase = input("Enter the phrase ")
if phrase.lower() == 'cheesy stats':
print("Suddenly a heavenly light breakes the cloudy sky as the omnipitent god known as the mighty death bringer and peace creator GLUB appears before you")
print("GLUB: Glub Glub Glub, Glub Glub. GLUB Gblub.")
print("you don't know what he said but suddenly you are filled with untold power and you gain infinite riches. GLUB disappears back to his place in the heavans")
print("you win")
class_restart = input("would you like to restart from the class menu, yes or no? ")
if class_restart.lower() == 'yes':
class_menu()
if class_restart.lower() == 'no':
print("Understandable my child")
else:
print("You've entered the wrong phrase and must be punished, you die.")
print("Game over")
class_restart = input("would you like to restart from the class menu, yes or no? ")
if class_restart.lower() == 'yes':
class_menu()
if class_restart.lower() == 'no':
print("Good we don't want you anyway")
if class_.lower() == 'mega-demon':
print("you will need to sacrifice your soul from within your inventory.")
sacrifice = input("do you sacrifice your soul? ")
if sacrifice.lower() == 'no':
class_menu()
if sacrifice.lower() == 'yes':
print("A demon emerges from the machine and he claims your soul before T-Posing on you to assert his dominance")
print("You waker up hours later with a sword through you as you couldn't control the immense power and went on a rampage killing everyone you love and destroying your home town.")
print("The end")
class_restart = input("would you like to restart from the class menu, yes or no? ")
if class_restart.lower() == 'yes':
class_menu()
if class_restart.lower() == 'no':
print("Okay, fuck you")
if class_.lower() == 'beater':
inventory.insert(0, 'starting sword')
print("your journey has begun and now you may choose your next destination")
Movement_menu_1()
def Movement_menu_1():
beater_hp = 10
beater_health = '10'
beater_mp = 0
beater_mana = '0'
beater_atk = 3
beater_attack = '3'
ogre_hp = 10
ogre_health = '10'
ogre_atk = 4
ogre_attack = '4'
wolf_hp = 5
wolf_health = '5'
wolf_atk = 2
wolf_attack = '2'
child_hp = 1
child_health = '1'
child_atk = 1
child_attack = '1'
print('1. The store')
print('2. The inner woods')
print('3. The town gates')
movement = input('Please input your destination or you may check your inventory ')
if movement.lower() == 'inventory':
print(inventory)
Movement_menu_1()
if movement.lower() == '1':
shop_menu()
if movement.lower() == '2':
beater_hp = 10
beater_health = '10'
beater_mp = 0
beater_mana = '0'
beater_atk = 3
beater_attack = '3'
ogre_hp = 10
ogre_health = '10'
ogre_atk = 4
ogre_attack = '4'
wolf_hp = 5
wolf_health = '5'
wolf_atk = 2
wolf_attack = '2'
child_hp = 1
child_health = '1'
child_atk = 1
child_attack = '1'
print("You choose to visit the towns local xp fa- i mean dangerous woodland, as an adventurer you are finally able to explore it without dying to the weak as- i mean dangerous monsters")
print("As you enter the woods you see the classic warning sign and several missing person posters littering it, you recall your childhood best friend billy planning to sneak into the woods at night")
print("Speak of the devil, theres his missing poster. Let's not connect any dots here to avoid reliving childhood truama.")
print("Next you see the sign that explains some solid information you'll need to get money and progress the rest of the game. You know unless you're a youtuber trying to see if its possible to win with the basic items.")
print("Enemies:")
print("1. Wolf. Wolf pelts are worth 1 gold")
print("2. Spirit of dea")
print("2. Spirit of missing and totally evil child. These make annoying ghost sounds and you'll be paid 3 gold for killing one")
print("3. Ogre. They have layers. Their worth like 5 gold")
print("you press on and now its fight time baby")
print("you walk around looking for something to kill")
Encounter_1()
def Encounter_2():
print('ur mum gay, you deserve an award for reaching this as its not even coded yet')
def Encounter_1():
beater_hp = 10
beater_health = '10'
beater_mp = 0
beater_mana = '0'
beater_atk = 3
beater_attack = '3'
ogre_hp = 10
ogre_health = '10'
ogre_atk = 4
ogre_attack = '4'
wolf_hp = 5
wolf_health = '5'
wolf_atk = 2
wolf_attack = '2'
child_hp = 1
child_health = '1'
child_atk = 1
child_attack = '1'
random_encounter = random.randint(1,3)
if random_encounter == 1:
beater_hp = 10
beater_health = '10'
beater_mp = 0
beater_mana = '0'
beater_atk = 3
beater_attack = '3'
ogre_hp = 10
ogre_health = '10'
ogre_atk = 4
ogre_attack = '4'
wolf_hp = 5
wolf_health = '5'
wolf_atk = 2
wolf_attack = '2'
child_hp = 1
child_health = '1'
child_atk = 1
child_attack = '1'
print("You encounter a wild wolf and luckily i can show you doing literally anything with it because i'm not an Irwin so Peta has no beef with me")
print("Now for the battle menu, it's pretty unoriginal so no tutorial is needed")
Battlemenu_wolf_beater()
if random_encounter == 2:
beater_hp = 10
beater_health = '10'
beater_mp = 0
beater_mana = '0'
beater_atk = 3
beater_attack = '3'
ogre_hp = 10
ogre_health = '10'
ogre_atk = 4
ogre_attack = '4'
wolf_hp = 5
wolf_health = '5'
wolf_atk = 2
wolf_attack = '2'
child_hp = 1
child_health = '1'
child_atk = 1
child_attack = '1'
print("You encounter Bil- i mean an evil spirit you've never seen before!")
print("Now for the battle menu to be explained, a tutorial might rip you from the truama you're undergoing right now so i won't give you one")
Battlemenu_spirit_beater()
if random_encounter == 3:
beater_hp = 10
beater_health = '10'
beater_mp = 0
beater_mana = '0'
beater_atk = 3
beater_attack = '3'
ogre_hp = 10
ogre_health = '10'
ogre_atk = 4
ogre_attack = '4'
wolf_hp = 5
wolf_health = '5'
wolf_atk = 2
wolf_attack = '2'
child_hp = 1
child_health = '1'
child_atk = 1
child_attack = '1'
print("You encounyter a wild and ruthless ogre ready to beat your ass because you've invaded his swamp")
print("Scum like you don't deserve a tutorial")
Battlemenu_ogre_beater()
def Battlemenu_ogre_beater():
print("Attack.")
print("Inventory.")
print("Skip turn.")
print("Run.")
fight_menu = input("What will you do? ")
if fight_menu.lower() == 'attack':
crit_chance = random.randint(1,10)
if crit_chance == 1:
beater_atk_2 = beater_atk * 2
print("Crit!")
ogre_hp = ogre_hp - beater_atk_2
print(str(ogre_hp))
if ogre_hp <= 0:
print("You have asserted dominance over its swamp, you obtain its prised onion")
inventory.insert(0, 'ogre onion')
continue_menu = input("do you want to keep looking or go back to town? ")
if continue_menu.lower() == 'keep looking':
Encounter_1()
if continue_menu.lower() == 'go back':
Movement_menu_1()
else:
print("The ogre attacks for " + ogre_attack)
beater_hp = beater_hp - ogre_atk
if beater_hp <= 0:
print("You die")
Movement_menu_1()
else:
Battlemenu_ogre_beater()
else:
ogre_hp = ogre_hp - beater_atk
print("You attack mercilessly for " + beater_attack)
print(str(ogre_hp))
if ogre_hp <= 0:
print("You have asserted dominance over its swamp, you obtain its prised onion")
inventory.insert(0, 'ogre onion')
continue_menu = input("Do you want to keep looking or go back to town? ")
if continue_menu.lower() == 'keep looking':
Encounter_1()
if continue_menu.lower() == 'go back':
Movement_menu_1()
else:
beater_hp = beater_hp - ogre_atk
print("The ogre attacks for " + ogre_attack)
print(str(beater_hp))
if beater_hp <= 0:
print("You lose")
Movement_menu_1()
else:
Battlemenu_ogre_beater()
if fight_menu.lower() == 'inventory':
print(str(inventory))
if 'health potion' or 'mana potion' in inventory:
inventory_menu = input("Do you want to use an item? ")
if inventory_menu.lower() == 'yes':
item_use = input("which item? ")
if item_use.lower() == 'health potion':
beater_hp = (int(beater_hp + health_potion))
print("You used a health potion, you gained " + health_potion)
if beater_hp >= beater_hp_2:
beater_hp = beater_hp_2
print(str(beater_hp))
print("The ogre attacks for " + ogre_attack)
beater_hp = beater_hp - ogre_atk
print(beater_hp)
if beater_hp <= 0:
print("You lose")
Movement_menu_1()
else:
Battlemenu_ogre_beater()
else:
beater_hp = beater_hp - ogre_atk
print("The ogre attacks for " + ogre_attack)
if beater_hp <= 0:
print("You lose.")
Movement_menu_1()
else:
Battlemenu_ogre_beater()
if item_use.lower() == 'mana potion':
beater_mana_2 = beater_mana + mana_potion
print(str(beater_mana_2))
beater_hp = beater_hp - ogre_atk
print("The ogre attacks for " + ogre_attack)
if beater_hp <= 0:
print("You lose")
Movement_menu_1()
else:
Battlemenu_ogre_beater()
else:
print("You don't have that lol")
Battlemenu_ogre_beater()
if inventory_menu.lower() == 'no':
Battlemenu_ogre_beater()
else:
print(str(inventory))
Battlemenu_ogre_beater()
if fight_menu.lower() == 'skip':
beater_mana_2 = (int(beater_mana))
print("Your mana is restored by " + beater_mana)
beater_hp = beater_hp - ogre_atk
print("The ogre attacks for " + ogre_attack)
print(str(beater_hp))
if beater_hp <= 0:
print("You lose.")
Movement_menu_1()
else:
Battlemenu_ogre_beater()
if fight_menu.lower() == 'run':
run_chance = random.randint(1,5)
if run_chance == 1:
print("You got away happily")
continue_menu = input("do you want to keep looking around or go back to town? ")
if continue_menu.lower() == 'keep looking':
print("You choose to keep looking because the reason you ran like a little bitch wasn't major")
Encounter_1()
if continue_menu.lower() == 'go back':
print("You choose to go back to town")
Movement_menu_1()
else:
print("You fall like a dumbcunt and everyone laughs at you because you're a failure")
beater_hp = (int((beater_hp - ogre_atk) * 2))
print("The ogre starts kicking your ass while your down for double damage")
print(str(beater_hp))
if beater_hp == 0:
print("You die poor and alone. Game over")
restart = input("Would you like to restart? ")
if restart.lower() == 'yes':
Game_start()
if restart.lower() == 'no':
print("Okay, fuck you")
def Battlemenu_spirit_beater():
print("Attack.")
print("Inventory.")
print("Skip turn.")
print("Run.")
fight_menu = input("What will you do? ")
if fight_menu.lower() == 'attack':
crit_chance = random.randint(1,10)
if crit_chance == 1:
beater_atk_2 = beater_atk * 2
print("Crit!")
spirit_hp = spirit_hp - beater_atk_2
print(str(spirit_hp))
if spirit_hp <= 0:
print("You have quite literally beaten the truama and have obtained the missing poster")
inventory.insert(0, 'missing poster')
continue_menu = input("do you want to keep looking or go back to town? ")
if continue_menu.lower() == 'keep looking':
Encounter_1()
if continue_menu.lower() == 'go back':
Movement_menu_1()
else:
print("Billy attacks for " + spirit_attack)
beater_hp = beater_hp - spirit_atk
if beater_hp <= 0:
print("You die")
Movement_menu_1()
else:
Battlemenu_spirit_beater()
else:
spirit_hp = spirit_hp - beater_atk
print("You attack mercilessly for " + beater_attack)
print(str(spirit_hp))
if spirit_hp <= 0:
print("You have quite literally beaten the truama and have obtained the missing poster")
inventory.insert(0, 'Missing poster')
continue_menu = input("Do you want to keep looking or go back to town? ")
if continue_menu.lower() == 'keep looking':
Encounter_1()
if continue_menu.lower() == 'go back':
Movement_menu_1()
else:
beater_hp = beater_hp - spirit_atk
print("Billy attacks for " + spirit_attack)
print(str(beater_hp))
if beater_hp <= 0:
print("You lose")
Movement_menu_1()
else:
Battlemenu_spirit_beater()
if fight_menu.lower() == 'inventory':
print(str(inventory))
if 'health potion' or 'mana potion' in inventory:
inventory_menu = input("Do you want to use an item? ")
if inventory_menu.lower() == 'yes':
item_use = input("which item? ")
if item_use.lower() == 'health potion':
beater_hp = (int(beater_hp + health_potion))
print("You used a health potion, you gained " + health_potion)
if beater_hp >= beater_hp_2:
beater_hp = beater_hp_2
print(str(beater_hp))
print("Billy attacks for " + spirit_attack)
beater_hp = beater_hp - spirit_atk
print(beater_hp)
if beater_hp <= 0:
print("You lose")
Movement_menu_1()
else:
Battlemenu_spirit_beater()
else:
beater_hp = beater_hp - spirit_atk
print("Billy attacks for " + spirit_attack)
if beater_hp <= 0:
print("You lose.")
Movement_menu_1()
else:
Battlemenu_spirit_beater()
if item_use.lower() == 'mana potion':
beater_mana_2 = beater_mana + mana_potion
print(str(beater_mana_2))
beater_hp = beater_hp - spirit_atk
print("Billy attacks for " + spirit_attack)
if beater_hp <= 0:
print("You lose")
Movement_menu_1()
else:
Battlemenu_spirit_beater()
else:
print("You don't have that lol")
Battlemenu_spirit_beater()
if inventory_menu.lower() == 'no':
Battlemenu_spirit_beater()
else:
print(str(inventory))
Battlemenu_spirit_beater()
if fight_menu.lower() == 'skip':
beater_mana_2 = (int(beater_mana))
print("Your mana is restored by " + beater_mana)
beater_hp = beater_hp - spirit_atk
print("The spirit attacks for " + spirit_attack)
print(str(beater_hp))
if beater_hp <= 0:
print("You lose.")
Movement_menu_1()
else:
Battlemenu_spirit_beater()
if fight_menu.lower() == 'run':
run_chance = random.randint(1,5)
if run_chance == 1:
print("You got away happily")
continue_menu = input("do you want to keep looking around or go back to town? ")
if continue_menu.lower() == 'keep looking':
print("You choose to keep looking because the reason you ran like a little bitch wasn't major")
Encounter_1()
if continue_menu.lower() == 'go back':
print("You choose to go back to town")
Movement_menu_1()
else:
print("You fall like a dumbcunt and everyone laughs at you because you're a failure")
beater_hp = (int((beater_hp - spirit_atk) * 2))
print("Must feel pretty bad to get the shit kicked out of you by a dead child")
print(str(beater_hp))
if beater_hp == 0:
print("You die poor and alone. Game over")
restart = input("Would you like to restart? ")
if restart.lower() == 'yes':
Game_start()
if restart.lower() == 'no':
print("Okay, fuck you")
def Battlemenu_wolf_beater():
print("Attack.")
print("Inventory.")
print("Skip turn.")
print("Run.")
fight_menu = input("What will you do? ")
if fight_menu.lower() == 'attack':
crit_chance = random.randint(1,10)
if crit_chance == 1:
beater_atk_2 = beater_atk * 2
print("Crit!")
wolf_hp = wolf_hp - beater_atk_2
print(str(wolf_hp))
if wolf_hp <= 0:
print("It's dead, you take its pelt")
inventory.insert(0, 'wolf pelt')
continue_menu = input("do you want to keep looking or go back to town? ")
if continue_menu.lower() == 'keep looking':
Encounter_1()
if continue_menu.lower() == 'go back':
Movement_menu_1()
else:
print("The wolf attacks for " + wolf_attack)
beater_hp = beater_hp - wolf_atk
print(str(beater_hp))
if beater_hp <= 0:
print("You die")
Movement_menu_1()
else:
Battlemenu_wolf_beater()
else:
wolf_hp = wolf_hp - beater_atk
print("You attack mercilessly for " + beater_attack)
print(str(wolf_hp))
if wolf_hp <= 0:
print("You win and get the wolfs pelt")
inventory.insert(0, 'wolf pelt')
continue_menu = input("Do you want to keep looking or go back to town? ")
if continue_menu.lower() == 'keep looking':
Encounter_1()
if continue_menu.lower() == 'go back':
Movement_menu_1()
else:
beater_hp = beater_hp - wolf_atk
print("The wolf attacks for " + wolf_attack)
print(str(beater_hp))
if beater_hp <= 0:
print("You lose")
Movement_menu_1()
else:
Battlemenu_wolf_beater()
if fight_menu.lower() == 'inventory':
print(str(inventory))
if 'health potion' or 'mana potion' in inventory:
inventory_menu = input("Do you want to use an item? ")
if inventory_menu.lower() == 'yes':
item_use = input("which item? ")
if item_use.lower() == 'health potion':
beater_hp = (int(beater_hp + health_potion))
print("You used a health potion, you gained " + health_potion)
if beater_hp >= beater_hp_2:
beater_hp = beater_hp_2
print(str(beater_hp))
print("The wolf attacks for " + wolf_attack)
beater_hp = beater_hp - wolf_atk
print(beater_hp)
if beater_hp <= 0:
print("You lose")
Movement_menu_1()
else:
Battlemenu_wolf_beater()
else:
beater_hp = beater_hp - wolf_atk
print("The wolf attacks for " + wolf_attack)
if beater_hp <= 0:
print("You lose.")
Movement_menu_1()
else:
Battlemenu_wolf_beater()
if item_use.lower() == 'mana potion':
beater_mana_2 = (int(beater_mana + mana_potion))
print(str(beater_mana_2))
beater_hp = beater_hp - wolf_atk
print("The wolf attacks for " + wolf_attack)
if beater_hp <= 0:
print("You lose")
Movement_menu_1()
else:
Battlemenu_wolf_beater()
else:
print("You don't have that lol")
Battlemenu_wolf_beater()
if inventory_menu.lower() == 'no':
Battlemenu_wolf_beater()
else:
print(str(inventory))
Battlemenu_wolf_beater()
if fight_menu.lower() == 'skip':
beater_mana_2 = (int(beater_mana))
print("Your mana is restored by " + beater_mana)
beater_hp = beater_hp - wolf_atk
print("The wolf attacks for " + wolf_attack)
print(str(beater_hp))
if beater_hp <= 0:
print("You lose.")
Movement_menu_1()
else:
Battlemenu_wolf_beater()
if fight_menu.lower() == 'run':
run_chance = random.randint(1,5)
if run_chance == 1:
print("You got away happily")
continue_menu = input("do you want to keep looking around or go back to town? ")
if continue_menu.lower() == 'keep looking':
print("You choose to keep looking because the reason you ran like a little bitch wasn't major")
Encounter_1()
if continue_menu.lower() == 'go back':
print("You choose to go back to town")
Movement_menu_1()
else:
print("You fall like a dumbcunt and everyone laughs at you because you're a failure")
beater_hp = (int((beater_hp - wolf_atk) * 2))
print("The wolf starts kicking your ass while your down for double damage")
print(str(beater_hp))
if beater_hp == 0:
print("You die poor and alone. Game over")
restart = input("Would you like to restart? ")
if restart.lower() == 'yes':
Game_start()
if restart.lower() == 'no':
print("Okay, fuck you")
gold = (int('0'))
money = (str('0'))
inventory = ['soul']
Game_start()
class_menu()
Movement_menu_1()
Encounter_3()
Encounter_2()
Encounter_1()
Battlemenu_ogre_beater()
Battlemenu_spirit_beater()
Battlemenu_wolf_beater()
shop_menu()
В нем говорится, что переменные ссылаются перед присваиванием, когда оно присваивается. Я не знаю, написал ли я это правильно с частью кода