2017-02-09 7 views
-2

私はちょうど2週間前にPythonを学び始めました。単純なRPGゲームを作ろうとしています。しかし、ユーザーsais後、彼は何も起こっていない村人と話をしたい。誰かが助けてくれますか?ありがとう!それが現在立っているよう関数はPythonゲームでは機能しません

from random import randint 

import random 
class Character: 
    def __init__(self,name,hp,thaco,ac,inventory,exp): 
     self.name=name 
     self.hp=hp 
     self.thaco=thaco 
     self.ac=ac 
     self.inventory=inventory 
     self.exp=exp 



class Fighter(Character): 
    def __init__(self): 
     super().__init__(name=input("What is your characters name?"),thaco=20,ac=10, 
         hp=10,inventory={"sword","shield"},exp=10) 
    prof = "fighter" 
    maxhp=10 
    level=1 
    hd=10 
    level2=20 

class warior(Character): 
    def __init__(self): 
     super().__init__(name=input("What is your characters name?"),thaco=20,ac=10, 
         hp=8,inventory={""},exp=8) 
    prof= "cleric" 
    maxhp=8 
    level=1 
    hd=8 
    level2=15 
class Mage(Character): 
    def __init__(self): 
     super().__init__(name=input("What is your characters name?"),thaco=20,ac=10, 
         hp=4,inventory={},exp=4) 
    prof= "mage" 
    mana=1 
    maxmana=1 
    maxhp=4 
    level=1 
    hd=4 
    level2=10 
class Goblin(Character): 
    def __init__(self): 
     super().__init__(name="goblin", 
         hp=7,thaco=20, 
         ac=6,inventory={}, 
         exp=7) 


class Orc(Character): 
    def __init__(self): 
     super().__init__(name="orc", 
         hp=8,thaco=18, 
         ac=6,inventory={}, 
         exp=8) 

def profession(): 
    print("What is your class?",'\n', 
      " press f for Fighter",'\n', 
      " press w for warior",'\n', 
      " press m for Mage") 
    pclass=input(">>>") 
    if pclass =="f": 
     Prof = Fighter() 
    elif pclass=="w": 
     Prof = warior() 
    elif pclass == "m": 
     Prof = Mage() 
    else: 
     Prof=Fighter() 
     #profession() 
    return Prof 
hero=profession() 
print("name hp thaco ac inventory xp",'\n', 
     hero.name,hero.hp,hero.thaco,hero.ac,hero.inventory,hero.exp) 




def villager(): 

global npcname 

global response 



response=["hi", " I need your help to fight this monster" ,"i m looking for treasure",] 

print(random.choice(response)) 




print (" a villager is walking by") 
print ("would you like to speak to him? yes or no") 
answer=input(">>>") 

if answer=="yes": 
    villager() 
+0

、それを投稿してください:あなたはもっとこのように見える機能を望んでいました。 – kenorb

+0

さて、何かが起こっていますが、 'villager()'は何も役に立ちません。窪みはそこにありますが、あなたはそれを職業()に入れています。 – roganjosh

+0

ヒント:予期せぬ出力が出ているようです。あなたが得ている入力を 'print'しないでください(または、あなたが欲しいのであれば、それを調べるためにデバッガを使います)? –

答えて

0

あなたのすべてのvillager機能が

def villager(): 

    global npcname 

はあなたが追加する必要があり、グローバル変数はあなたが私が想定しnpcnameグローバル変数を定義した後、この方法は、やりたいこと、これまでどのようなロジック定義されていあなたが任意のエラーを持っている場合は、あなたの質問を絞り込む必要がある

def villager(): 
    response=["hi", " I need your help to fight this monster" ,"i m looking for treasure",] 

    print(random.choice(response)) 
関連する問題