我为我的RPG定义了一些东西,但它不起作用

2024-06-10 03:15:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在做一个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()

不管什么原因,底部的黏液功能都不起作用。我已经定义了相遇,所以我不知道为什么。脚本似乎停止并返回到主菜单(Explore、Check Items等)。 有人能帮我确定发生了什么事吗?你知道吗


Tags: nameinputifdefsleephphasprint
1条回答
网友
1楼 · 发布于 2024-06-10 03:15:49

输入Slime(),然后输入encounter(),同时不输出任何内容。我不知道你该怎么打“斜杠”。如果你不这样做,它就会跳回主菜单。如果你输入“斜杠”,你会得到:

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局部变量,您可能应该使它成为一个传递到interface的对象。你知道吗

相关问题 更多 >