Python-100-Days/Day01-15/Day05/code/craps.py

49 lines
1.3 KiB
Python
Raw Normal View History

2018-03-02 00:09:06 +08:00
"""
Craps赌博游戏
玩家摇两颗色子 如果第一次摇出7点或11点 玩家胜
如果摇出2点 3 12 庄家胜 其他情况游戏继续
玩家再次要色子 如果摇出7点 庄家胜
如果摇出第一次摇的点数 玩家胜
否则游戏继续 玩家继续摇色子
玩家进入游戏时有1000元的赌注 全部输光游戏结束
Version: 0.1
Author: 骆昊
Date: 2018-03-02
"""
from random import randint
money = 1000
while money > 0:
2019-05-03 21:17:36 +08:00
print('你的总资产为:', money)
needs_go_on = False
while True:
debt = int(input('请下注: '))
if debt > 0 and debt <= money:
break
first = randint(1, 6) + randint(1, 6)
print('玩家摇出了%d' % first)
if first == 7 or first == 11:
print('玩家胜!')
money += debt
elif first == 2 or first == 3 or first == 12:
print('庄家胜!')
money -= debt
else:
needs_go_on = True
2018-03-02 00:09:06 +08:00
2019-05-03 21:17:36 +08:00
while needs_go_on:
current = randint(1, 6) + randint(1, 6)
print('玩家摇出了%d' % current)
if current == 7:
print('庄家胜')
money -= debt
needs_go_on = False
elif current == first:
print('玩家胜')
money += debt
needs_go_on = False
2018-03-02 00:09:06 +08:00
print('你破产了, 游戏结束!')