一、游戲規(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.')