i have got a problem with the store section , it's not working i don't know why , and also i'm still beginner in python , when i try to buy it says no enough gold although i have gold and displays an error refers to the below code Q No Enough Gold Traceback (most recent call last): File "d:/youtube/Programing/Python/Titoot/.vs/My First Game/Game File.py", line 219, in <module> if player_choice_store_def == "A": NameError: name 'player_choice_store_def' is not defined ,i tried to forward the items section a little but it didn't work,and this the whole code , so can you help me with this?
import time
from random import randint
#player inputs
player_attack = 15
player_xp_s = 0
Player_gold = 500
player_heal = 10
player_health = 100
player_lv = 0
player_def = 0
#inventory
small_potion_inv = 0
medium_potion_inv = 0
large_potion_inv = 0
leather_armor_inv = 0
iron_armor_inv = 0
full_steel_armor_inv = 0
wooden_sword_inv = 0
small_dagger_inv = 0
iron_sword_inv = 0
steel_sword_inv = 0
#Monster inputs
monster_name = "Mon1"
monster_attack = 5
monster_attack_min = 3
monster_attack_max = 16
monster_xp_g = 2
monster_gold_g = 5
monster_health = 100
monster_def = 0
#Monster Levels:
Mon_level = 0
Mon1_level = 1
Mon2_level = 1
Game_running = True
XP_reset = False
while Game_running == True:
new_round = True
print("---" * 7)
player_name = input("Your Name?")
while new_round == True:
player_won = False
Monster_won = False
#menu:
print("---" * 7)
time.sleep(0.5)
print("A Low Level Monster appeared "+ "(LV"+str(Mon_level)+")")
time.sleep(0.1)
print(player_name + " Has " + str(player_health) + " Health Left")
print(monster_name + " Has " + str(monster_health) + " Health Left")
print("---" * 7)
print("Select Action:")
time.sleep(0.1)
print("1)Attack")
time.sleep(0.1)
print("2)Heal")
time.sleep(0.1)
print("3)Store")
time.sleep(0.1)
print("4)Inventory")
time.sleep(0.1)
print("5)Check Current Status")
time.sleep(0.1)
print("6)Check Monster Status")
time.sleep(0.1)
print("7)Exit Game")
player_choice = input()
elif player_choice == "3":
#variables
#heall
small_potion_hp = 10
small_potion_gold = 5
medium_potion_hp = 15
medium_potion_gold = 7
large_potion_hp = 25
large_potion_gold = 10
#Defence
leather_armor_df = 5
leather_armor_gold = 17
iron_armor_df = 10
iron_armor_gold = 30
full_steel_armor_df = 17
full_steel_armor_gold = 37
#Attack
small_dagger_ap = 3
small_dagger_gold = 15
iron_sword_ap = 7
iron_sword_gold = 27
steel_sword_ap = 15
steel_sword_gold = 34
print("Store:")
print("Items")
print("---"*7)
print("Z)Heal Items")
print("X)Defence Items")
print("C)Attack Items")
player_choice_store = input()
if player_choice_store == "Z":
print("Q)Small Potion : +"+str(small_potion_hp)+"HP =" + str(small_potion_gold)+ " Gold")
print("W)Medium Potion : +"+str(medium_potion_hp)+"HP = "+str(medium_potion_gold)+" Gold")
print("E)Large Potion : +"+str(large_potion_hp)+"HP = "+str(large_potion_gold)+" Gold")
player_choice_store_heal = input()
elif player_choice_store == "X":
print("A)Leather Armor : +"+str(leather_armor_df)+"DF = "+str(leather_armor_gold)+" Gold")
print("S)Iron Armor : +"+str(iron_armor_df)+"DF = "+str(iron_armor_gold)+" Gold")
print("D)Full Steel Armor : +"+str(full_steel_armor_df)+"DF = "+str(full_steel_armor_gold)+" Gold")
player_choice_store_def = input()
elif player_choice_store == "C":
print("R)Small Dagger : +"+str(small_dagger_ap)+"AP = "+str(small_dagger_gold)+" Gold")
print("T)Iron Sword : +"+str(iron_sword_ap)+"AP = "+str(iron_sword_gold)+" Gold")
print("Y)steel Sword : +"+str(steel_sword_ap)+"AP = "+str(steel_sword_gold)+" Gold")
player_choice_store_attack = input()
#Heal
if player_choice_store_heal == "Q":
if Player_gold >> small_potion_gold or Player_gold == 0:
print("No Enough Gold")
else:
print("Small Potion Purchased Successfully")
Player_gold = Player_gold - small_potion_gold
small_potion_inv = small_potion_inv + 1
if player_choice_store_heal == "W":
if Player_gold >> medium_potion_gold or Player_gold == 0:
print("No Enough Gold")
else:
print("Medium Potion Purchased Successfully")
Player_gold = Player_gold - medium_potion_gold
medium_potion_inv = medium_potion_inv + 1
if player_choice_store_heal == "E":
if Player_gold >> large_potion_gold or Player_gold == 0:
print("No Enough Gold")
else:
print("Large Potion Purchased Successfully")
Player_gold = Player_gold - large_potion_gold
large_potion_inv = large_potion_inv + 1
#Defence
if player_choice_store_def == "A":
if Player_gold >> leather_armor_gold or Player_gold == 0:
print("No Enough Gold")
else:
print("Leather Armor Purchased Successfully")
Player_gold = Player_gold - leather_armor_gold
leather_armor_inv = leather_armor_inv + 1
if player_choice_store_def == "S":
if Player_gold >> iron_armor_gold or Player_gold == 0:
print("No Enough Gold")
else:
print("Iron Armor Purchased Successfully")
Player_gold = Player_gold - iron_armor_gold
iron_armor_inv = iron_armor_inv + 1
if player_choice_store_def == "D":
if Player_gold >> full_steel_armor_gold or Player_gold == 0:
print("No Enough Gold")
else:
print("Full Steel Armor Purchased Successfully")
Player_gold = Player_gold - full_steel_armor_gold
full_steel_armor_inv = full_steel_armor_inv + 1
#attack
if player_choice_store_attack == "R":
if Player_gold >> small_dagger_gold or Player_gold == 0:
print("No Enough Gold")
else:
print("Small Dagger Purchased Successfully")
Player_gold = Player_gold - small_dagger_gold
small_dagger_inv = small_dagger_inv + 1
if player_choice_store_attack == "T":
if Player_gold >> iron_sword_gold or Player_gold == 0:
print("No Enough Gold")
else:
print("Iron Sword Purchased Successfully")
Player_gold = Player_gold - iron_sword_gold
iron_sword_inv = iron_sword_inv + 1
if player_choice_store_attack == "Y":
if Player_gold >> steel_sword_gold or Player_gold == 0:
print("No Enough Gold")
else:
print("Steel Sword Purchased Successfully")
Player_gold = Player_gold - steel_sword_gold
steel_sword_inv = steel_sword_inv + 1
if player_choice == "4":
print("Inventory")
print("Heal:")
print("1) Small Potion : " + str(small_potion_inv))
print("2) Medium Potion : " + str(medium_potion_inv))
print("3) Large Potion : " + str(large_potion_inv))
print("Equipment:")
print("4) Wooden Sword : " + str(wooden_sword_inv))
print("5) Small Dagger : " + str(small_dagger_inv))
print("6) Iron Sword : " + str(iron_sword_inv))
print("7) Steel Sword : " + str(steel_sword_inv))
print("---"*7)
print("Next (>)")
print("8) Leather Armor : " + str(leather_armor_inv))
print("9) Iron Armor : " + str(iron_armor_inv))
print("3) Full Steel Armor : " + str(full_steel_armor_inv))
player_choice_inv = input()
if player_choice_inv == "1":
small_potion_inv = small_potion_inv - 1
player_health = player_health + small_potion_hp
elif player_choice == "7":
new_round = False
Game_running = False
# else:
# print("Invalid Input")
if player_won:
print(player_name + " Has Won")
elif Monster_won:
print(monster_name + " Has Won")```
Aucun commentaire:
Enregistrer un commentaire