我一直在研究Python文本RPG作为我的第一个测试我的技能的迷你项目,但我已经遇到了一些问题。这是剧本;首先:
from time import sleep
import random
EXP = 0
EXPCap = 1
Lv = 1
ATK = 5
MATK = 5
DEF = 10
MDEF = 10
HP = 100
EATK = 0
EMATK = 0
EDEF = 0
EMDEF = 0
EHP = 0
MHP = 1
Ename = ("None")
fireorbcount = 0
waterorbcount = 0
earthorbcount = 0
ironcount = 0
windorbcount = 0
windsword = 0
firesword = 0
earthsword = 0
watersword = 0
movement = 1
burn = ("No")
poison = ("No")
Slash = ("UnLocked")
DoubleSlash = ("Locked")
Fireball = ("UnLocked")
FirePillar = ("Locked")
Battlecry = ("Locked")
def Slime():
EHP = 90
EATK = 5
EDEF = 10
EMATK = 5
EMDEF = 2
Ename = Slime
def enemyatk():
if movement == 1:
if random.randint(0,100) >51:
print("Slime uses Stomp!")
HP = HP - (20 + EATK - (DEF / 3))
sleep(0.2)
print( name , "has" , HP , "HP out of" , MHP,"!")
sleep(0.2)
if random.randit(0,100) <50:
print("Slime uses Piercing Stomp!")
HP = HP - (20 + EATK)
sleep(0.2)
print( name , "has" , HP , "HP out of" , MHP,"!")
sleep(0.2)
else:
movement = movement + 1
def getdrops():
print("You have defeated" , Ename,"!")
sleep(0.1)
print("You have recieved one water orb!")
waterorbcount = waterorbcount + 1
encounter()
def encounter():
if DoubleSlash == ("UnLocked"):
print("Double Slash")
if FirePillar == ("UnLocked"):
print("Fire Pillar")
if Battlecry == ("Unlocked"):
print("Battle Cry")
atk_1 = input()
if atk_1 == ("Slash"):
EHP = EHP - (40 + ATK - (EDEF / 4))
print( Ename , "has" , EHP , "HP remaining!")
enemyatk()
if HP <1:
print("You have been defeated!")
quit()
if EHP <1:
print("The enemy has died!")
getdrops()
print("Please input your name")
name = input()
print("Welcome," , name , "to Pellandia! Please select an action.")
while 1 + 1 == 2:
sleep(0.2)
print("Check Items")
sleep(0.2)
print("Craft")
sleep(0.2)
print("Explore")
sleep(0.2)
print("Quit")
choice = input()
if choice == ("Quit"):
quit()
if choice == ("Check Items"):
print("Fire Orbs:" , fireorbcount)
sleep(0.2)
print("Water Orbs:" , waterorbcount)
sleep(0.2)
print("Wind Orbs:" , windorbcount)
sleep(0.2)
print("Earth Orbs:" , earthorbcount)
sleep(0.2)
print("Iron:" , ironcount)
if choice == ("Explore"):
print("Where would you like to explore?")
sleep(0.2)
print("Plains")
sleep(0.2)
print("Caves")
sleep(0.2)
print("Lava Mountains")
sleep(0.2)
print("Underwater Abyss")
sleep(0.2)
print("Ishgria")
explorec = input()
if explorec == ("Plains"):
Slime()
无论出于何种原因,底部的粘液功能都无效。我已经定义了这次遭遇,所以我不确定为什么。该脚本似乎停止并返回主菜单(浏览,检查项目等)。 有人可以帮我确定一下发生了什么吗?
答案 0 :(得分:1)
输入Slime()
,然后输入encounter()
,而不输出任何内容。您如何知道输入“Slash”我不确定。如果你不这样做,只需跳回主菜单即可。如果你输入“Slash”,你会得到:
Traceback (most recent call last):
File "game.py", line 123, in <module>
Slime()
File "game.py", line 63, in Slime
encounter()
File "game.py", line 75, in encounter
EHP = EHP - (40 + ATK - (EDEF / 4))
UnboundLocalError: local variable 'EHP' referenced before assignment
如果你想使用Slime
局部变量,你可能应该把它变成一个传递给遭遇的对象。