Python 小练习: CRAPS 花旗骰

一、游戏规则:

说明:CRAPS又称花旗骰,是美国拉斯维加斯非常受欢迎的一种的桌上赌博游戏。该游戏使用两粒骰子,玩家通过摇两粒骰子获得点数进行游戏。简单的规则是:

  • 玩家第一次摇骰子如果摇出了7点或11点,玩家胜;
  • 玩家第一次如果摇出2点、3点或12点,庄家胜;
  • 其他点数玩家继续摇骰子,如果玩家摇出了7点,庄家胜;
  • 如果玩家摇出了第一次摇的点数,玩家胜;其他点数,玩家继续要骰子,直到分出胜负

注意

  • 一旦分出胜负,游戏要返回到

二、逻辑梳理:

梳理出逻辑大致如下


image.png

三、代码:

"""
参数说明:
money 手里的钱
count 掷骰子次数, 胜负发生后清零
first_roll 第一次掷骰子的点数
bet 掷骰子钱下注的金额
"""
import random

money = 1000
count = 0
first_roll = 0

while money > 0:
    print('-----------')
    bet = input('Enter your bet: ')
    bet = int(bet)
    if bet <= money:
        count += 1
        dice_a = random.randrange(1, 7)
        dice_b = random.randrange(1, 7)
        print('The %d roll...' % count)
        print('Dice A is %d' % dice_a)
        print('Dice B is %d' % dice_b)
        total = dice_a + dice_b
        if count == 1:
            first_roll = total
            if total in [7, 11]:
                print('YOU WIN!!!')
                money += bet
                count = 0
                print('Your money: %d' % money)
            elif total in [2, 3, 12]:
                print('YOU LOSE!!!')
                money -= bet
                count = 0
                print('Your money: %d' % money)
            else:
                print('Nobody wins, dice again...')
        elif count > 1:
            if total == 7:
                print('YOU LOSE!!!')
                money -= bet
                count = 0
                print('Your money: %d' % money)
            elif total == first_roll:
                print('YOU WIN!!!')
                money += bet
                count = 0
                print('Your money: %d' % money)
            else:
                print('Nobody wins, dice again...')

        print('The first roll: %d' % first_roll)
    else:
        print("You don't have enough money. Reduce your bet.")
else:
    print('GAME OVER.')
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容