未定义Start()

时间:2015-01-16 18:42:25

标签: python python-3.x

嘿,我正在尝试创建一个简单的基于文本的老虎机,并将视图转换为后者的图形。

我已经开始提示菜单工作正常。但是当用户输入所需的'p'继续时,它将不会调用下一个函数,因为我还没有定义它......我有吗?

from time import sleep
from random import shuffle

#Creates the class
class Machine():
    #This is the constructor full of attributes
    def __init__(self):
        self.reel1 = ["Lemon", "Bell", "Cherry"]
        self.reel2 = ["Lemon", "Bell", "Cherry"]
        self.reel3 = ["Lemon", "Bell", "Cherry"]
        firstSlide = self.reel1
        secondSlide = self.reel2
        thirdSlide = self.reel3
        self.currentFunds = "10"
        funds = self.currentFunds
        f = open('score.txt', 'w')
        f.write(funds)

#Dictates all the funds and checks if the user has enough money or needs to add money
    def Funds(self):
        if self.currentFunds == "0":  
            print("You are out of credits! :( \n")
            Menu()


#Starts the spinning and randomizes the lists
    def Start(self, firstSlide, secondSlide, thirdSlide):
        shuffle(firstSlide, secondSlide, thirdSlide)
        print(firstSlide[0], secondSlide[1], thirdSlide[3])

#Intro Menu to give player stats and options
    def Menu(self):
        play = ""
        m = Machine()
        print('*****************\n')
        print('     WELCOME!  \n')
        print('*****************\n')
        print('Current Credits: ', m.currentFunds)
        if input("Press P to play \n") == "P" or "p":
            machine = Start()
            machine.Start()

machine = Machine()            
while True:
    machine.Menu()

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

您有Start作为Machine类的成员函数。您需要将machine = Start()替换为self.Start()

实际上,您似乎尝试使用了许多变量。例如,我希望Start会依赖于self.start,但它依赖于参数(你没有传入)。


作为对此代码的一般评论,我想知道您是否真的需要/希望以这种方式构建它。你好像是在递归地创建对象,我认为你可能会更好地重组一下。