CRAPS赌博游戏:
说明:CRAPS又称花旗骰,是美国拉斯维加斯非常受欢迎的一种的桌上赌博游戏。该游戏使用两粒骰子,玩家通过摇两粒骰子获得点数进行游戏。简单的规则是:玩家第一次摇骰子如果摇出了7点或11点,玩家胜;玩家第一次如果摇出2点、3点或12点,庄家胜;其他点数玩家继续摇骰子,如果玩家摇出了7点,庄家胜;如果玩家摇出了第一次摇的点数,玩家胜;其他点数,玩家继续要骰子,直到分出胜负。
我的代码如下:
# CRAPS赌博游戏。
# 说明:CRAPS又称花旗骰,是美国拉斯维加斯非常受欢迎的一种的桌上赌博游戏。
# 该游戏使用两粒骰子,玩家通过摇两粒骰子获得点数进行游戏。简单的规则是:
# 玩家第一次摇骰子如果摇出了7点或11点,玩家胜;玩家第一次如果摇出2点、3
# 点或12点,庄家胜;
# 其他点数玩家继续摇骰子,如果玩家摇出了7点,庄家胜;
# 如果玩家摇出了第一次摇的点数,玩家胜;其他点数,玩家继续要骰子,直到分出胜负。
from random import randint
"""
Craps赌博游戏
我们设定玩家开始游戏时有1000元的赌注
游戏结束的条件是玩家输光所有的赌注
"""
total_money = 1000
index = 0 # 赌局论数
player_win_flag = False
while (total_money > 0):
index += 1
while True:
debt = int(input("请下注:"))
if 0 < debt <= total_money:
break
is_end = False
times = 0 # 每轮掷筛子次数
while (is_end == False):
times += 1
num_player = randint(2, 12)
if times == 1:
if num_player == 7 or num_player == 11:
total_money += debt
player_win_flag = True
is_end == True
break
elif num_player == 2 or num_player == 3 or num_player == 12:
total_money -= debt
player_win_flag = False
is_end == True
break
else:
num_player_first = num_player
continue
else:
if num_player == 7:
player_win_flag = False
total_money -= debt
break
elif num_player == num_player_first:
player_win_flag = True
total_money += debt
break
else:
continue
if player_win_flag == True:
print("第%d轮玩家获胜,结算后玩家总金额是%d。" % (index, total_money))
else:
print("第%d轮玩家失败,结算后玩家剩余总金额是%d。" % (index, total_money))