2015-01-16 3 views
0

안녕하세요 저는 그래픽 기반의 후자로 변환 할 수있는 뷰가있는 간단한 텍스트 기반의 슬롯 머신을 만들려고합니다.Start()가 정의되지 않았습니다.

잘 작동하는 메뉴를 표시하는 것으로 시작했습니다. 그러나 사용자가 필요한 '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() 

아이디어가 있으십니까?

+0

내 편집 보존 된 들여 쓰기 – vaultah

+0

이 줄의 오류는'machine = Start()'또는이 하나의'machine.Start()'입니까? – user2097159

답변

1

기계 클래스의 구성원 함수로 Start이 있습니다. machine = Start()self.Start()으로 대체해야합니다.

실제로 사용하려고하는 많은 변수가있는 것처럼 보입니다. 예를 들어, Start는 self.start에 의존 할 것이지만, 매개 변수 (당신이 전달하지는 않음)에 의존한다고 생각합니다.


이 코드에 대한 일반적인 의견으로,이 방법으로 구조화해야하는지/궁금합니다. 당신은 재귀 적으로 객체를 만드는 것처럼 보입니다. 당신이 조금 구조 조정하는 것이 더 나을 것이라고 생각합니다.

+0

그것은 임무를 위해, 우리는 OOP 구조로 만들라고 들었지만 그것 모두에 새로운 ... Noob at python – user3812866

관련 문제