zoukankan      html  css  js  c++  java
  • 摇色子

    登录页面

    """
    Author:Cairo
    """
    import json
    class LogIn(object):
        def AccountType(self,list_BlocKed,list_Access):
            '''账号检测'''
            while True:
                AccountInput = input("请输入您的账号>>:")
                Account = AccountInput.isdigit()
                AccountM = open("blocked.txt","rb")
                Accountm = json.load(AccountM)
                if Account == True:
                    for Accountm_kk in Accountm:
                        if Accountm_kk["ID"] == AccountInput:
                            exit("你的账户:%s 已被锁定,请联系管理员"%AccountInput)
                    ##获取返回值
                    '''获取账号'''
                    Access = open("Access.txt", "rb")
                    Access_T = json.load(Access)
                    for T_ in Access_T:
                        if T_["ID"] == AccountInput:
                            num = 0
                            while True:
                                PassInput = input("请输入您的密码>>:")
                                if T_["PASSWORD"] == PassInput:
                                    print(" *****欢迎来到色子游戏!!!*****")
                                    return (T_["ID"],T_["USERNAME"], T_["MONEY"])
                                elif T_["PASSWORD"] != PassInput:
                                    num += 1
                                    print("你的密码错误,你还有 %d 次机会" % (3-num))
                                    if num == 3:
                                        '''冻结账户'''
                                        LI.blocked(T_,list_BlocKed,AccountInput,list_Access,Access_T)
                        elif T_["ID"] != AccountInput:
                            break
                    Access.close()
                else:
                    print("请输入正确的整数!!!!")
        def blocked(self,T_,list_BlocKed,AccountInput,list_Access,Access_T):
            '''删除账户'''
            for BlocKed in Access_T:
                list_Access.append(BlocKed)
            BLcKed = open("Access.txt", "w")
            for USER in list_Access:
                if USER["ID"] == T_["ID"]:
                    list_Access.remove(T_)
            BLOcK = json.dump(list_Access, BLcKed)
            BLcKed.close()
            '''冻结账户拷贝'''
            blockEd = open("blocked.txt", "rb")
            Blocked = json.load(blockEd)
    
            for BlocKed in Blocked:
                list_BlocKed.append(BlocKed)
            BLOcKed = open("blocked.txt", "w")
            list_BlocKed.append(T_)
            BLOcKeD = json.dump(list_BlocKed, BLOcKed)
            BLOcKed.close()
            blockEd.close()
            exit("你的账号:%s 已被冻结,请联系管理员" % AccountInput)
    LI = LogIn()
    lis = LI.AccountType(list_BlocKed=[],list_Access = [])

    游戏页面

    """
    Author:Cairo
    """
    import random
    import log_in,json
    
    
    '''
    摇色子
    
    '''
    
    class RollDice(object):
        def __init__(self,ID,name,money,list_acc = []):
            self.ID = ID
            self.name = name
            self.money = money
            self.Money = int(self.money)
            self.list_acce = list_acc
    
        def Determine_the_money(self):
            '''
            判断金额
            return:
            '''
    
            while True:
                print("*" * 50)
                Of_Money = input("请输入您要压的金额>>:")
                Of_money = Of_Money.isdigit()
                if (len(Of_Money) != 0):
                    if (Of_money == True):
                        while True:
                            while True:
                                size_of_pressure = input("请输入/大/小/三色>>:")
                                if size_of_pressure !="" and size_of_pressure !="" and size_of_pressure !="三色":
                                    print("你输入的是 %s 不是本游戏的命令,请重新输入!!" % size_of_pressure)
                                    break
                                elif len(size_of_pressure) != 0:
                                    Of_Money = int(Of_Money)
                                    if self.Money < Of_Money:
                                        print("accounts differ !!!")
                                        The_User = input("退出游戏按Q/重新输入按B/前往充值按D >>:").upper()
                                        if The_User == "Q":
                                            exit()
                                        elif The_User == "B":
                                            break
                                        elif The_User == "D":
                                            RD.Recharge()
                                            break
    
                                    else:
                                        RD.Start_game(Of_Money,size_of_pressure)
                                        break
                                else:
                                    print("至少要选择一个下注!!!")
    
                    elif Of_money == False:
                        print("请输入正确的整数金额 !!!")
                        continue
    
                else:
                    print("金额请输入一个整数!!!")
    
        def Start_game(self,Of_Money,size_of_pressure):
            '''
            游戏开始
            :return:
            '''
            # 余额减
            self.Money -= Of_Money
            print(self.Money)
            print("*" * 30)
            print("亲爱的%s ,游戏开始咯!!!"%self.name)
            print("*" * 50)
            # 随机色子
            random1 = random.randint(1, 6)
            random2 = random.randint(1, 6)
            random3 = random.randint(1, 6)
            Random = random1 + random2 + random3
            #比较色子
            if random1 == random2 == random3:
                print("本局的色子为[%d][%d][%d],[%d]为三色!!!!"%(random1,random2,random3,Random))
                if size_of_pressure == "三色":
                    print("恭喜您,中将了!!!")
                    print("本局您赢了%s" % (Of_Money * 5))
                    self.money = self.money + Of_Money * 5
                    print(self.money)
                else:
                    print("您的本局压的是%s, 好可惜啊!!!" % size_of_pressure)
                print("您的余额为¥%d"%self.money)
                RD.close_an_account()
    
            elif Random <= 12:
                print("本局的色子为[%d][%d][%d],[%d]为小!!!!" % (random1, random2, random3, Random))
                if size_of_pressure == "":
                    print("您的本局压的是%s, 好可惜啊!!!"% size_of_pressure)
    
                else:
                    print("恭喜您,中将了!!!")
                    print("本局您赢了%s" % (Of_Money * 2))
                    self.Money = self.Money + Of_Money * 2
    
    
                print("您的余额为¥%d" % self.Money)
                RD.close_an_account()
            else:
                print("本局的色子为[%d][%d][%d],[%d]为大!!!!" % (random1, random2, random3, Random))
                if size_of_pressure == "":
                    print("恭喜您,中将了!!!")
                    print("本局您赢了%s" % (Of_Money * 2))
                    self.money = self.Money + Of_Money * 2
                    print(self.Money)
                else:
                    print("您的本局压的是%s, 好可惜啊!!!" % size_of_pressure)
                print("您的余额为Y%d" % self.Money)
                RD.close_an_account()
    
        def close_an_account(self):
            account = open("Access.txt","rb")
            Account = json.load(account)
            for Account_A in Account:
                self.list_acce.append(Account_A)
            for Account_A in Account:
                if Account_A["ID"] == self.ID:
                    Account_A["MONEY"] = str(self.Money)
                    accountU = open("Access.txt","w")
                    AccountU = json.dump(self.list_acce,accountU)
                    accountU.close()
            account.close()
    
    
    
        def Recharge(self):
            '''
            充值函数
            :return:
            '''
            while True:
                RechargeInputp = input("请输入您要充值的面额 >>:")
                RechargeInput = RechargeInputp.isdigit()
                if RechargeInput == True:
                    RechargeInput = int(RechargeInputp)
                    self.Money += RechargeInput
                    print(self.Money,"充值成功!!!")
                    break
    
                else:
                    print("请正确输入金额!!!")
                    continue
    
    NAME = log_in.lis
    RD =  RollDice(*NAME)
    RD.Determine_the_money()

    txt文件

    [{"ID": "13421731046", "PASSWORD": "13421731046", "USERNAME": "Cairo", "MONEY": "5002000"}, {"ID": "13421731044", "PASSWORD": "13421731044", "USERNAME": "CaIro", "MONEY": "12000"}, {"ID": "13421731045", "PASSWORD": "13421731045", "USERNAME": "CaiRo", "MONEY": "10000"}]

    冻结文件

    [{"ID": "13421731044", "PASSWORD": "13421731044", "USERNAME": "CaIro", "MONEY": "12000"} ]
    """
    Author:Cairo
    """
    import json
    class LogIn(object):
    def AccountType(self,list_BlocKed,list_Access):
    '''账号检测'''
    while True:
    AccountInput = input("请输入您的账号>>:")
    Account = AccountInput.isdigit()
    AccountM = open("blocked.txt","rb")
    Accountm = json.load(AccountM)
    if Account == True:
    for Accountm_kk in Accountm:
    if Accountm_kk["ID"] == AccountInput:
    exit("你的账户:%s 已被锁定,请联系管理员"%AccountInput)
    ##获取返回值
    '''获取账号'''
    Access = open("Access.txt", "rb")
    Access_T = json.load(Access)
    for T_ in Access_T:
    if T_["ID"] == AccountInput:
    num = 0
    while True:
    PassInput = input("请输入您的密码>>:")
    if T_["PASSWORD"] == PassInput:
    print(" *****欢迎来到色子游戏!!!*****")
    return (T_["ID"],T_["USERNAME"], T_["MONEY"])
    elif T_["PASSWORD"] != PassInput:
    num += 1
    print("你的密码错误,你还有 %d 次机会" % (3-num))
    if num == 3:
    '''冻结账户'''
    LI.blocked(T_,list_BlocKed,AccountInput,list_Access,Access_T)
    elif T_["ID"] != AccountInput:
    break
    Access.close()
    else:
    print("请输入正确的整数!!!!")
    def blocked(self,T_,list_BlocKed,AccountInput,list_Access,Access_T):
    '''删除账户'''
    for BlocKed in Access_T:
    list_Access.append(BlocKed)
    BLcKed = open("Access.txt", "w")
    for USER in list_Access:
    if USER["ID"] == T_["ID"]:
    list_Access.remove(T_)
    BLOcK = json.dump(list_Access, BLcKed)
    BLcKed.close()
    '''冻结账户拷贝'''
    blockEd = open("blocked.txt", "rb")
    Blocked = json.load(blockEd)

    for BlocKed in Blocked:
    list_BlocKed.append(BlocKed)
    BLOcKed = open("blocked.txt", "w")
    list_BlocKed.append(T_)
    BLOcKeD = json.dump(list_BlocKed, BLOcKed)
    BLOcKed.close()
    blockEd.close()
    exit("你的账号:%s 已被冻结,请联系管理员" % AccountInput)
    LI = LogIn()
    lis = LI.AccountType(list_BlocKed=[],list_Access = [])




    以上内容作为课堂笔记,如有雷同,请联系于我
  • 相关阅读:
    人机猜拳
    String字符串与字符(char类型)数组互相转换
    String字符串与字符(char类型)数组互相转换
    pytorch(五)超参调试过程的tensorboard可视化
    pytorch(三)建立模型(网络)
    pytorch(二)数据准备工作ETL
    pytorch(一)张量基础及通用操作
    中东冲突及圣城耶路撒冷(希伯来语为和平之城)
    五线谱基础及弹奏姿势
    相机主距与焦距
  • 原文地址:https://www.cnblogs.com/ArtisticMonk/p/9048266.html
Copyright © 2011-2022 走看看