gpt4 book ai didi

python - 为什么我的兽人战斗停止了并且没有转到 move() 命令 :/

转载 作者:太空宇宙 更新时间:2023-11-03 16:31:00 25 4
gpt4 key购买 nike

在我的代码的某些部分,它只是停止并且不会返回到 move()。我希望它添加分数,我用分数 = 分数 + 100 来做到这一点,但它只是破坏了代码;-;。它有点乱,我对此感到抱歉,但请帮助我不知道为什么会这样做。仅供引用,如果有帮助的话,我正在 pythonroom 上使用这段代码。

import random
weapon = "Wooden Sword"
Damage0 = 1
Damage1 = 8
Speed = 6
lives = 5
score = 0
gold = 80
armor = "Nothing"
health = 20

def please():
name = input("Please put a name and not nothing.")
if name == "":
please1(name)
else:
yon(name)

def please1(name):
name = input("Please put a name and not nothing.")
if name == "":
please1(name)
else:
yon1(name)

def yon(name):
print("So your name is " + name + "?")
yon = input("Is this your name? ''" + name + "'' [Yes] or [No]?")
if yon == "Yes":
begining()
elif yon == "yes":
begining()
else:
sorry(name)

def yon1(name):
yon = input("Is this your +name? ''" + name + "'' [Yes] or [No]?")
if yon == "Yes":
begining()
elif yon == "yes":
begining()
else:
sorry1(name)

def sorry(name):
print(" ")
print("I'm sorry, so what is your name?")
print(" ")
name = input("What is you name?")
if name != "":
yon(name)
else:
please1(name)

def sorry1(name):
name = input("What is you name?")
if name != "":
yon1(name)
else:
please1(name)

def move():
Next = input("Will you go and fight a monster or check stats or quit the game? [Fight] [Stats] [Travel] [Quit]")
Next = Next.lower()
if "tat" in Next:
Stats()
elif "ight" in Next:
Fight()
elif "ravel" in Next:
travel()
elif "uit" in Next:
print("As you quit the game your character disapears...")
else:
move()

def Fight():
your_speed = Speed
enemy_speed = 2
if enemy_speed >= your_speed:
print("The " + enemy + " is faster, it goes first!")
enemy_first()
else:
print("You're faster and get to go first!")
your_first()

def end(enemy_health,your_health):
if your_health > 0:
print(" ")
print("You defeat the Ork")
score = score + 100
gold = gold + 50 'it stops here and won't continue why?
print(gold)
print(score)
move()
else:
print("The ork beat you!")
move()

def your_first():
enemy_health = 20
your_health = health
while your_health > 0 and enemy_health > 0:
your_damage = random.choice(range(Damage0, Damage1))
enemy_health -= your_damage
if enemy_health <= 0:
enemy_health = 0
print(" ")
print("You dealt " + str(your_damage) + " damage!")
print("Enemy's health:" + str(enemy_health))
end(enemy_health,your_health)
else:
print(" ")
print("You dealt " + str(your_damage) + " damage!")
print("Enemy's health:" + str(enemy_health))
enemy_damage = random.choice(range(3, 12))
your_health -= enemy_damage
if your_health <= 0:
your_health = 0
print(" ")
print("Ork dealt " + str(enemy_damage) + " damage!")
print("Your health:" + str(your_health))
end(enemy_health,your_health)
else:
print(" ")
print("Ork dealt " + str(enemy_damage) + " damage!")
print("Your health:" + str(your_health))

def enemy_first():
enemy_health = 20
your_health = health
while your_health > 0 and enemy_health > 0:
enemy_damage = random.choice(range(3, 12))
your_health -= enemy_damage
if your_health <= 0:
your_health = 0
print(" ")
print("Ork dealt " + str(enemy_damage) + " damage!")
print("Your health:" + str(your_health))
end(enemy_health,your_health)
else:
print(" ")
print("Ork dealt " + str(enemy_damage) + " damage!")
print("Your health:" + str(your_health))
your_damage = random.choice(range(Damage0, Damage1))
enemy_health -= your_damage
if enemy_health <= 0:
print(" ")
print("You dealt " + str(your_damage) + " damage!")
print("Enemy's health:" + str(enemy_health))
end(enemy_health,your_health)
else:
print(" ")
print("You dealt " + str(your_damage) + " damage!")
print("Enemy's health:" + str(enemy_health))

def Stats():
if weapon == "Wooden Sword":
Damage = 1, 8
Damage0 = 1
Damage1 = 8
Speed = 6
if weapon == "Rusty Sword":
Damage = 13, 17
Damage0 = 13
Damage1 = 17
Speed = 4
if weapon == "Bow":
Damage = 2, 13
Damage0 = 2
Damage1 = 13
Speed = 10
if weapon == "Bronze Sword":
Damage = 18, 24
Damage0 = 18
Damage1 = 24
Speed = 1
if weapon == "Magic Spell":
Damage = 25, 33
Damage0 = 25
Damage1 = 33
Speed = 10
if armor == "Nothing":
health = 20

print(" ")
print(" ")
print("(+)~~~~~~~~~~~~~~~~~~~~~~")
print(" | Your | Health: ")
print(" | Stats | " + str(health) + " ")
print(" |----------------------- ")
print(" | Weapon Stats: ")
print(" | Damage: "+str(Damage)+" ")
print(" | Speed: "+str(Speed)+" ")
print("(+)~~~~~~~~~~~~~~~~~~~~~~")
print(" Your Score:"+ str(score) +" ")
print(" ")
print(" ")
move()

def begining():
print(" ")
print("Welcome to the nexus!")
print("It is the center of this world.")
print("It is also called the hub.")
print("During the game you can gather items and get xp")
print("At the end of the game you can see your score based")
print("on how well you did and how many items you found!")
move()

def travel():
travel = input("Where will you travel to? [Cave] [Market] [Boss]")
if "ve" in travel:
cave()
elif "et" in travel:
market()
elif "ss" in travel:
Boss_fight()
else:
move()

def cave():
print("pie")

def market():
print("pie")

def Boss_fight():
your_speed = Speed
enemy_speed = 2
if enemy_speed >= your_speed:
print("The " + enemy + " is faster, it goes first!")
Boss_Boss_first
else:
print("You're faster and get to go first!")
Boss_Your_First()

def Boss_end(enemy_health,your_health):
if your_health > 0:
print(" ")
print("You defeat The Boss")
score = score + 2000
move()
else:
print(" ")
if lives == 3 or lives == 2 or lives == 1:
print("The Boss beats you!")
lives = lives - 1
print("You have " + str(lives) + " left")
move()
else:
start= input("Restart or Quit?")
if "start" in start or "try" in start:
reset(xp,lvl,weapon)
else:
print(" ")


def Boss_Your_First():
enemy_health = 50
your_health = health
while your_health > 0 and enemy_health > 0:
your_damage = random.choice(range(Damage0, Damage1))
enemy_health -= your_damage
if enemy_health <= 0:
enemy_health = 0
print(" ")
print("You dealt " + str(your_damage) + " damage!")
print("The Boss's health:" + str(enemy_health))
Boss_end(enemy_health,your_health)
else:
print(" ")
print("You dealt " + str(your_damage) + " damage!")
print("The Boss's health:" + str(enemy_health))
enemy_damage = random.choice(range(15, 19))
your_health -= enemy_damage
if your_health <= 0:
your_health = 0
print(" ")
print("The Boss dealt " + str(enemy_damage) + " damage!")
print("Your health:" + str(your_health))
Boss_end(enemy_health,your_health)
else:
print(" ")
print("The Boss dealt " + str(enemy_damage) + " damage!")
print("Your health:" + str(your_health))

def Boss_Boss_first():
enemy_health = 50
your_health = health
while your_health > 0 and enemy_health > 0:
enemy_damage = random.choice(range(15, 19))
your_health -= enemy_damage
if your_health <= 0:
your_health = 0
print(" ")
print("The Boss dealt " + str(enemy_damage) + " damage!")
print("Your health:" + str(your_health))
Boss_end(enemy_health,your_health)
else:
print(" ")
print("The Boss dealt " + str(enemy_damage) + " damage!")
print("Your health:" + str(your_health))
your_damage = random.choice(range(Damage0, Damage1))
enemy_health -= your_damage
if enemy_health <= 0:
print(" ")
print("You dealt " + str(your_damage) + " damage!")
print("The Boss's health:" + str(enemy_health))
Boss_end(enemy_health,your_health)
else:
print(" ")
print("You dealt " + str(your_damage) + " damage!")
print("The Boss's health:" + str(enemy_health))
print(" ")
print("Hello. What is your name?")
print(" ")
name = input("What is you name?")
if name == "":
please()
else:
yon(name)

最佳答案

您尝试在函数 end 中分配全局变量 score,如下所示:

val = 5

def func():
val += 5

它不会工作并会导致UnboundLocalError。为了解决这个问题,只需使用关键字 global :

val = 5

def func():
global val
val += 5

关于python - 为什么我的兽人战斗停止了并且没有转到 move() 命令 :/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37605035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com