CRAPS赌博小游戏

craps · 浏览次数 : 0

小编点评

```python import easygui as gstate import random money = 1000 while True: state = g.ccbox( msg="欢迎进入赌博游戏,赌博有风险,游戏需谨慎", choices=("开始游戏", "退出游戏"), ) if state == 1: g.msgbox(msg="游戏余额{}元".format(money), title="Running") while money > 0 and state == 1: while True and money != 0 and state == 1: debt = g.enterbox(msg="请下注", title="Running...") print(debt) if debt == None: money -= 1 break else: debt = int(debt) if debt >= 0 and debt <= money: break if flag == 0 and money != -1: point = random.randint(1, 6) + random.randint(1, 6) if point == 7 or point == 11: money += debt state = g.ccbox("玩家胜利,余额{}元".format(money), choices=("继续下注", "退出游戏")) elif point == 2 or point == 3 or point == 12: money -= debt if money != 0: state = g.ccbox("庄家胜利,余额{}元".format(money), choices=("继续下注", "退出游戏")) else: flag = 1 while flag == 1 and money != -1: tag = random.randint(1, 6) + random.randint(1, 6) if tag == 7: money -= debt if money != 0: state = g.ccbox("庄家胜利,余额{}元".format(money), choices=("继续下注", "退出游戏")) flag = 0 elif tag == point: money += debt state = g.ccbox("玩家胜利,余额{}元".format(money), choices=("继续下注", "退出游戏")) flag = 0 else: flag = 1 if money == 0: state = g.ccbox("玩家破产,游戏结束", choices=("再玩一局", "退出游戏")) money = 1000 flag = 0 if state == 1: g.msgbox(msg="游戏余额{}元".format(money), title="Running")

正文

游戏规则

代码实现

首先把这个规则用代码写出来
再在它基础上进行简单的可视化(主要是利用Easygui的界面)
最后查缺补漏,看看有没有什么Bug
利用pyinstaller -F -w -i xx.ico craps.py命令打包成exe文件

from random import randint
import easygui as g
state=1
while state==1:
    state=g.ccbox('欢迎进入赌博游戏,赌博有风险,游戏需谨慎',choices=('开始游戏','退出游戏'))
    flag=0
    money=1000
    if state==1:
        g.msgbox(msg=f'游戏余额{money}元',title='Running')
    while money>0 and state==1:
        while True and money!=0 and state==1:
            debt=g.enterbox(msg='请下注',title='Running...')
            print(debt)
            if debt==None:
                money=-1
                break
            else:
                debt=int(debt)
            if debt>0 and debt<=money:
                break
        if flag==0 and money!=-1:
            point=randint(1,6)+randint(1,6)
            if point==7 or point==11:
                money+=debt
                state=g.ccbox(f'玩家胜利,余额{money}元',choices=('继续下注','退出游戏'))
            elif point==2 or point==3 or point==12:
                money-=debt
                if money!=0:
                    state=g.ccbox(f'庄家胜利,余额{money}元',choices=('继续下注','退出游戏'))
            else:
                flag=1
        while flag==1 and money!=-1:
            tag=randint(1,6)+randint(1,6)
            if tag==7:
                money-=debt
                if money!=0:
                    state=g.ccbox(f'庄家胜利,余额{money}元',choices=('继续下注','退出游戏'))
                flag=0
            elif tag==point:
                money+=debt
                state=g.ccbox(f'玩家胜利,余额{money}元',choices=('继续下注','退出游戏'))
                flag=0
            else:
                flag=1
        if money==0:
            state=g.ccbox('玩家破产,游戏结束',choices=('再玩一局','退出游戏'))
            money=1000
            flag=0
            if state==1:
                g.msgbox(msg=f'游戏余额{money}元',title='Running')

与CRAPS赌博小游戏相似的内容: