2016-03-25 9 views
-4

私は自分のスキルをテストするための私の最初のミニプロジェクトとしてPythonのテキストRPGで少し作業してきましたが、壁。ここにスクリプトがあります。まず、私の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、ect)に戻ります。 誰かが私に何が起こっているのかを教えてもらえますか?

+0

何を返すのですか? – James

+7

[mcve]を投稿してください。あなたが投稿したコードのほとんどはあなたの問題と無関係で、複製する必要はないようです。 – Goyo

+1

デバッガでコードをステップしましたか? –

答えて

1

あなたは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ローカル変数を使用する場合:あなたはあなたが得る「スラッシュ」と入力ない場合。

関連する問題