Start() 未定义
Start() is not defined
嘿,我正在尝试创建一个简单的基于文本的老虎机,以便将其转换为图形老虎机。
我已经开始使用它提示一个工作正常的菜单。但是,当用户输入所需的 '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()
有什么想法吗?
您有 Start
作为机器 class 的成员函数。您需要将 machine = Start()
替换为 self.Start()
。
您似乎尝试使用的许多变量实际上就是这种情况。例如,我希望 Start 依赖于 self.start,但它依赖于参数(你没有传入)。
作为对此代码的一般评论,我想知道您是否真的 need/want 以这种方式构建它。您似乎正在递归地创建对象,我认为您最好重构一下。
嘿,我正在尝试创建一个简单的基于文本的老虎机,以便将其转换为图形老虎机。
我已经开始使用它提示一个工作正常的菜单。但是,当用户输入所需的 '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()
有什么想法吗?
您有 Start
作为机器 class 的成员函数。您需要将 machine = Start()
替换为 self.Start()
。
您似乎尝试使用的许多变量实际上就是这种情况。例如,我希望 Start 依赖于 self.start,但它依赖于参数(你没有传入)。
作为对此代码的一般评论,我想知道您是否真的 need/want 以这种方式构建它。您似乎正在递归地创建对象,我认为您最好重构一下。