尝试制作游戏时python代码无法正常工作

时间:2018-09-25 13:15:40

标签: python

import random #imports random module
username = ""
lvl = 0
exp = 0
maxexp = 50
oldexp = 0

def newgame():  # Used for creating a New Account
    username = raw_input("Enter your new nickname : ")
    lvl = 0
    exp = 0
    return lvl
    return exp
    return username
    userinfo(username,lvl,exp)  

def userinfo(username,lvl,exp):
        print lvl,exp
        return lvl
        return exp
        return username
        update_userinfo(lvl,exp,0,0)

def update_userinfo(exp,lvl,maxexp,exp_increase):
    exp_up(exp,exp_increase)
    return exp
    if exp >= maxexp:
        exp = exp - maxexp
        lvl_up(lvl,1)
        maxexp = maxexp * 2
        print "You lvled up"

def exp_up(exp,exp_increase):
    exp = exp + exp_increase

def lvl_up(lvl,lvl_increase):
    lvl = lvl + lvl_increase
    return lvl


def kanto():
    print "Welcome new trainer! You are going to begin your game at the Kanto region. Here you will meet variety types of Pokemons. In this world of pokemons your objective is to Find and Catch as many Pokemons as you can. There are also many challenges that you may face along your adventure. Make sure you face them with your upmost courage and deal with them with all your might. May you be the next Pokemon champion."

def johto():
        print "Welcome new trainer! You are going to begin your game at the Johto region. Here you will meet variety types of Pokemons. In this world of pokemons your objective is to Find and Catch as many Pokemons as you can. There are also many challenges that you may face along your adventure. Make sure you face them with your upmost courage and deal with them with all your might. May you be the next Pokemon champion."

def hoenn():
        print "Welcome new trainer! You are going to begin your game at the Hoenn region. Here you will meet variety types of Pokemons. In this world of pokemons your objective is to Find and Catch as many Pokemons as you can. There are also many challenges that you may face along your adventure. Make sure you face them with your upmost courage and deal with them with all your might. May you be the next Pokemon champion."

def gamestart():
    min = 1
    max = 3
    region = random.randint(min,max)
    if region == 1:
        kanto()
    elif region == 2:
        johto()
    elif region == 3:
        hoenn()

def choose_pokemon_kanto():
    print "Proffessor : Ok.... Lets see. We have three Pokeballs here, and all of them have one pokemon that I had caught in my last field trip. I raised all of them to about level 5, and taught them 2 moves, best for beginners right?"
    cont = raw_input("")
    print "Proffessor : First here we have "


update_userinfo(exp,lvl,maxexp,60)

我试图稍微学习python,并尝试制作基于文本的神奇宝贝游戏。不起作用的部分是:

update_userinfo(exp,lvl,maxexp,60)

我是编码的新手,请对此提供帮助。我应该使用那么多的函数,还是只使用if语句来完成整个代码?为什么执行更改变量值的函数时python为什么不更改变量的值。

1 个答案:

答案 0 :(得分:0)

我在那里看到很多错误,但是我想您只是想在使用exp_up后返回exp

def exp_up(exp,exp_increase):
    exp = exp + exp_increase

您可以对新变量exp进行贴花,该变量只能在函数exp_up中使用。如果要在update_user_info函数中使用此函数,则需要从exp函数返回该exp_up。因此您的exp_up看起来像这样:

def exp_up(exp,exp_increase):
    exp = exp + exp_increase
    return exp

和您的update_userinfo

def update_userinfo(exp,lvl,maxexp,exp_increase):
    exp = exp_up(exp,exp_increase)
    return exp
    ...