Python 小練習(xí): CRAPS 花旗骰

一、游戲規(guī)則:

說明:CRAPS又稱花旗骰,是美國拉斯維加斯非常受歡迎的一種的桌上賭博游戲。該游戲使用兩粒骰子,玩家通過搖兩粒骰子獲得點(diǎn)數(shù)進(jìn)行游戲。簡單的規(guī)則是:

  • 玩家第一次搖骰子如果搖出了7點(diǎn)或11點(diǎn),玩家勝;
  • 玩家第一次如果搖出2點(diǎn)、3點(diǎn)或12點(diǎn),莊家勝;
  • 其他點(diǎn)數(shù)玩家繼續(xù)搖骰子,如果玩家搖出了7點(diǎn),莊家勝;
  • 如果玩家搖出了第一次搖的點(diǎn)數(shù),玩家勝;其他點(diǎn)數(shù),玩家繼續(xù)要骰子,直到分出勝負(fù)

注意

  • 一旦分出勝負(fù),游戲要返回到

二、邏輯梳理:

梳理出邏輯大致如下


image.png

三、代碼:

"""
參數(shù)說明:
money 手里的錢
count 擲骰子次數(shù), 勝負(fù)發(fā)生后清零
first_roll 第一次擲骰子的點(diǎn)數(shù)
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.')
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容