未定义Start()

2024-10-03 04:32:33 发布

您现在位置:Python中文网/ 问答频道 /正文

嘿,我正试图创建一个简单的文本为基础的老虎机与视图转换成一个图形。你知道吗

我已经开始了,它提示一个菜单,这很好的工作。但是,当用户输入所需的“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()

有什么想法吗?你知道吗


Tags: theselfdefmachinemenulemoncherryfunds
1条回答
网友
1楼 · 发布于 2024-10-03 04:32:33

Start作为Machine类的成员函数。您需要用self.Start()替换machine = Start()。你知道吗

事实上,对于你试图使用的许多变量来说,情况就是这样。例如,我希望Start将依赖于自启动,但它依赖于参数(您没有传入这些参数)。你知道吗


作为对这段代码的一般性评论,我想知道您是否真的需要/想要以这种方式构建这段代码。您似乎在递归地创建对象,我认为您最好重新构造一下。你知道吗

相关问题 更多 >