具有函数而不是while循环的游戏结构

时间:2017-12-14 11:35:44

标签: python function

当我开始在python或其他应用程序上创建游戏时,我被教导使用while循环,其中游戏将持续注册事件并做出相应的反应。

然而,在我接受教学之前,我应用了一种不同的方法,包括从一个功能顺序跳到下一个功能。我真的很喜欢这种方法,因为它对我来说似乎很简单,但我想知道它是否会出现一些问题,因为似乎没有人使用它。

这是一个例子:

def funcA(x):
    x = input("Give a True or False value for x: ")
    #We create a menu of possible actions:
    if x:
        funcB():
    else:
        funcC():

def funcB():
    #Some sort of job is completed here:
    #----------
    #And then we return back to the menu:
    funcA(x)

def funcC():
    #Some other job is completed here:
    #----------
    #And then we return back to the menu:
    funcA(x)

我怀疑是python在函数内的每个级别放入内存,并且使用这种方法,连续运行它将最终处于无限的内存需求中。

0 个答案:

没有答案