CRAPS赌博小游戏

游戏规则

代码实现

首先把这个规则用代码写出来
1.计算余额
2.下注
3.统计输赢
再在它基础上进行简单的可视化(主要是利用Easygui的界面)

g.ccbox()#选择框
g.msgbox()#提醒框
g.enterbox()#输入文本

最后查缺补漏,看看有没有什么Bug
1.能够随时退出游戏
2.破产后能重新开始游戏
3.每一把结束都告知游戏余额情况
利用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')
posted @   Aaryn21  阅读(33)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示