1

以下は、私がまとめているカジノ ゲームのルーレット部分ですが、正しく動作しないようです。プレーヤーが正しい番号を選択したときに認識されません。誰かが理由を教えてくれることを願っています. 明らかに、他のいくつかの部分は完了していませんが、基本を動かそうとしているだけです。また、私はこれにかなり慣れていないので、他のことを自由に批判してください! ありがとう。

from random import randint
from time import sleep

funds = 50



### Straight Up number bet = 35:1
### Odd/Even payout = 1:1

class RouletteTable(object):

    def __init__(self, wallet):
        self.wallet = wallet

    def spin(self, bets):
        print "Spinning..."
        sleep(2)
        print "The winner is..."
        sleep(1)
        winner = 25 #randint(0, 36) #FOR TESTING 
        print "Number ", winner
        if winner in bets == True:
            bets = True
            return bets

        else:
            print "You bet on: ", bets
            print "Better luck next time."
            bets = False
            return bets

    def game(self): 

        while self.wallet >= 0:
            print "\n\nWelcome to Roulette."
            print "Test your luck, and place your bets!"
            print "Current funds: $", self.wallet
            print "\n(1)Place bet or (2)Exit"
            choice = raw_input("> ")

            if choice == "1":
                bets = []
                print '''\n\n\n
          __________
         [     0    ]
         [ 1][ 2][ 3]
         [ 4][ 5][ 6]
         [ 7][ 8][ 9]
         [10][11][12]
         [13][14][15]
         [16][17][18]
         [19][20][21]
         [22][23][24]
         [25][26][27]
         [28][29][30]
         [31][32][33]
         [34][35][36]
         [ODD] [EVEN]

        '''
                print "How much will you bet (per number)?"
                bet_amount = int(raw_input("> $"))
                print "Type a number to bet on, and press Enter."
                print "When finished choosing, just press Enter."
                while True:
                    print "Funds: $", self.wallet
                    print "Current Bets: ", bets
                    number_choice = raw_input("> ")
                    if number_choice != "":
                        bets.append(int(number_choice))
                        self.wallet -= bet_amount

                    else:
                        # start spin
                        self.spin(bets) 
                        # payout for bets
                        if bets == True:
                            print "You win $", bet_amount*35
                            self.wallet += bet_amount*35

                        break

            if choice == "2":
                return self.wallet
                break

        if self.wallet == 0:
            print "You're out of money!\n"

roulette = RouletteTable(funds)
funds = roulette.game()
4

1 に答える 1

0

あなたの主なエラーはこれでした:

# start spin
self.spin(bets) 
# payout for bets

それは読むべきです:

#start spin
bets = self.spin(bets)
# payount bets

以下の変更されたコードはそれを正しく行います。ベットを別のタイプで上書きするのは良いスタイルではありません。別の変数を使用することをお勧めします。またwin in bets、明示的に比較する必要はありませんTrue(学習中の説明がない限り)。

さらに質問がある場合は、コメントしてください;-)

from random import randint
from time import sleep

funds = 50



### Straight Up number bet = 35:1
### Odd/Even payout = 1:1

class RouletteTable(object):

    def __init__(self, wallet):
        self.wallet = wallet

    def spin(self, bets):
        print "Spinning..."
        sleep(2)
        print "The winner is..."
        sleep(1)
        winner = 25 #randint(0, 36) #FOR TESTING 
        print "Number ", winner
        if winner in bets:
            return True

        else:
            print "You bet on: ", bets
            print "Better luck next time."
            return False

    def game(self): 

        while self.wallet >= 0:
            print "\n\nWelcome to Roulette."
            print "Test your luck, and place your bets!"
            print "Current funds: $", self.wallet
            print "\n(1)Place bet or (2)Exit"
            choice = raw_input("> ")

            if choice == "1":
                bets = []
                print '''\n\n\n
          __________
         [     0    ]
         [ 1][ 2][ 3]
         [ 4][ 5][ 6]
         [ 7][ 8][ 9]
         [10][11][12]
         [13][14][15]
         [16][17][18]
         [19][20][21]
         [22][23][24]
         [25][26][27]
         [28][29][30]
         [31][32][33]
         [34][35][36]
         [ODD] [EVEN]

        '''
                print "How much will you bet (per number)?"
                bet_amount = int(raw_input("> $"))
                print "Type a number to bet on, and press Enter."
                print "When finished choosing, just press Enter."
                while True:
                    print "Funds: $", self.wallet
                    print "Current Bets: ", bets
                    number_choice = raw_input("> ")
                    if number_choice != "":
                        bets.append(int(number_choice))
                        self.wallet -= bet_amount

                    else:
                        # start spin
                        did_win = self.spin(bets) 
                        # payout for bets
                        if did_win == True:
                            ammount = bet_amount*35
                            self.wallet += ammount
                            print "You win $", ammount


                        break

            if choice == "2":
                return self.wallet
                break

        if self.wallet == 0:
            print "You're out of money!\n"

roulette = RouletteTable(funds)
funds = roulette.game()
于 2013-07-12T03:54:36.833 に答える