Craps 摇色子游戏

Craps赌博游戏 - 两个色子
第一次摇色子
如果摇出了7点或11点 - 玩家胜
如果摇出了2点、3点或12点 - 庄家胜
如果摇出其他点数 - 游戏继续
继续
如果摇出了7点 - 庄家胜
如果摇出了第一次摇的点数 - 玩家胜
如果摇出了其他点数 - 游戏继续

from random import randint


# =====掷色子
def roll_dice(*, num=1):  # "*," -->命名关键字参数,传参是需给出参数名
    total = 0
    for _ in range(num):
        total += randint(1, 6)
    return total


def main():
    money = 1000
    while money > 0:
        while True:
            print(f'total assets{money}')
            debt = int(input('please bet:'))
            if 0 < debt <= money:
                break
        first = roll_dice(num=2)
        print(f'玩家摇出了{first}点')
        game_over = True
        if first == 7 or first == 11:
            money += debt
            print('player win!')
        elif first == 2 or first == 3 or first == 11:
            money -= debt
            print('banker win!')
        else:
            game_over = False
        while not game_over:
            current = roll_dice(num=2)
            print(f'player roll {current} point')
            if current == 7:
                money -= debt
                print('banker win!')
                game_over = True
            elif current == first:
                money += debt
                print('player win!')
                game_over = True

        print(money)
    print('you\'re broke game over!')


if __name__ == '__main__':
    main()

你可能感兴趣的:(Craps 摇色子游戏)