二十一点蟒蛇骰子游戏修复?

时间:2018-04-25 15:54:35

标签: python blackjack

如果有人在重播()中说了别的话,除了“不”或“是”之外,由于某种原因甚至没有,它会启动主持人。

我还在学习,这是我的第二个项目,有什么意见吗? 我尝试了很多东西,但它仍然不起作用。

# Blackjack game

import random

global playername, nameofplayer
nameofplayer = input('Enter your name').capitalize()
print ('Hello,', str(nameofplayer))

class Player():
    def __init__(self, banktotal):
        self.banktotal = banktotal

    # adds an amount to the bank

    def addtobank(self, bankadd):
        self.banktotal += bankadd

    # removes an amount from the bank

    def subfrombank(self, subbank):
        self.banktotal -= subbank




def rolldice():
    global playerhand
    playerhand = 0
    print('Your Current hand: ' + str(playerhand))
    playerhand = 0
    print ('...')
    print ('Rolling the dice for you')
    dice = list(range(1,7))
    while playerhand <= 21:
        rolled = random.choice(dice)

        print('Your Current hand: ' + str(playerhand))

        hitstick = str(input('Hit or Stick?').capitalize())
        if hitstick == 'Hit':
             print('You chose to hit!')
             playerhand += rolled

        elif hitstick == 'Stick':
            print('Your exit hand: ' + str(playerhand))
            break
        elif hitstick != 'Hit' or 'Stick':
            print('Enter a valid argument')




    else:
        print('Your Current hand: ' + str(playerhand))

        print ('Busted, Host Wins!')
        print('Reducing 100$ from your account')
        playername.banktotal -= 100
        print('Your bank balance: ' + str(playername.banktotal))

        replay()




def hostchance():
    hosthand = 0
    print ('Current host hand: ' + str(hosthand))
    dice = list(range(1, 7))

    while hosthand <= playerhand:

        rolled = random.choice(dice)
        hosthand += rolled
        print('Rolling the dice for the host')
        print ('Current host hand: ' + str(hosthand))
        if hosthand < playerhand:
            pass
        elif hosthand == playerhand:
            print ('Its a draw!')
            break
        elif hosthand > playerhand and hosthand < 22:
            print('Host Wins!')
            print('Reducing 100$ from your account')
            playername.banktotal -= 100
            break
    if hosthand < playerhand or hosthand > 21:
        print (str(nameofplayer) + ' Wins!')
        print('Adding 100$ to your account')
        playername.banktotal += 100




playername = Player(1000)

def game():

    print ('Your bank balance: ' + str(playername.banktotal))
    rolldice()

    something = input('Enter anything for the host to start his turn')
    print (something)

    print('Host Chance')
    hostchance()
    print ('Your bank balance: ' + str(playername.banktotal))



def replay():
    print('Do you want to play again?')
    replay = input('Input with yes or no: ').lower()


    if replay == 'yes':
        game()
    elif replay == 'no':
        pass


game()
replay()

1 个答案:

答案 0 :(得分:0)

在收到无答案后,您应passexit()而不是quit()