2018-08-24 摇色子 - 小游戏

2018-08-24  本文已影响0人  莫希子西
image.png
import random

def RollDice(numbers=3, points=None):
    print('<<<<ROLL the Dice!>>>>')
    if points is None:
        points = []
    while numbers > 0:
        point = random.randrange(1, 7)
        points.append(point)
        numbers = numbers - 1
    return points


def RollResult(total):
    isBig = 11 <= total <= 18
    isSmall = 3 <= total <= 10
    if isBig:
        return 'BIG'
    elif isSmall:
        return 'SMALL'

def start_game():
    print('<<<<<GAME STARTS>>>>>')
    money = 1000
    choices = ['BIG', 'SMALL']
    while money != 0:
        your_Choice = input('BIG or SMALL:')
        while your_Choice not in choices:
            if your_Choice == 'E':
                exit()
            else:
                your_Choice = input('BIG or SMALL again:')
        your_bet = input('Your bet:')
        while int(your_bet) > money or int(your_bet) < 1:
            your_bet = input('Invalid bet, please bet again:')
        points = RollDice()
        total = sum(points)
        youwin = your_Choice == RollResult(total)
        if youwin:
            money = money + int(your_bet)
            print('your points is:', points, "You WIN",
                'Your money now is:', money)
        else:
            money = money - int(your_bet)
            print('your points is:', points, "You LOSE"),
            print('Your money now is:', money)
    print('No meney to bet now! You lose ALL')
    print('<<<<<Game Over>>>>>')
    exit()

start_game()

摇色子 - 小游戏 测试:


image.png
上一篇 下一篇

猜你喜欢

热点阅读