|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 QQ小鱼 于 2022-4-10 11:44 编辑
这是我写的小游戏
- import os
- import pickle
- #用户名和登录密码的储存
- if not os.path.exists('E:/游戏.pkl'):
- with open('E:/游戏.pkl', 'wb') as f:
- pickle.dump({},f)
- else:
- with open('E:/游戏.pkl', 'rb') as f:
- a = pickle.load(f)
- #密保和问题的储存
- if not os.path.exists('E:/问题.pkl'):
- with open('E:/问题.pkl', 'wb') as f:
- pickle.dump({},f)
- else:
- with open('E:/问题.pkl', 'rb') as f:
- sore = pickle.load(f)
- #用户名和问题的储存
- if not os.path.exists('E:/问题2.pkl'):
- with open('E:/问题2.pkl', 'wb') as f:
- pickle.dump({},f)
- else:
- with open('E:/问题2.pkl', 'rb') as f:
- sore2 = pickle.load(f)
- def code_grade(code):
- list = r'''!@#$%^&*()_+--={}|:"?><[]\;'.,/'''
- while True:
- length = len(code)
- while (code.isspace() or length == 0): # 排除空格和没输入密码
- code = input('密码不能空,请重新输入密码:')
- length = len(code)
- if 0 < length <= 8: # 确定密码的长度
- flag1 = 1
- elif 8 < length <= 16:
- flag1 = 2
- else:
- flag1 = 3
- flag2 = 0 # 提前定义数字
- for each in code: # 确定字符的类型
- if each.isalpha():
- flag2 += 1
- break
- for each in code:
- if each.isdigit():
- flag2 += 1
- break
- for each in code:
- if each in list:
- flag2 += 1
- break
- print('你的密码等级为:', end='')
- if flag1 == 1 or flag2 == 1:
- print('低')
- elif flag1 == 3 and flag2 == 3 and (code[0].isdigit()):
- print('高')
- break
- else:
- print('中')
- break
- print('''密码等级过低,请通过以下三种方式提高密码等级:
- \t1、密码必须由数字、字母或者特殊符号(@#$)中任意两种搭配
- \t2、密码长度不能低于8位
- \t3、密码必须是字母开头''')
- code = input('请重新输入密码:')
- return code
- def user_name(name):
- while 1:
- if name.isdigit():
- b = len(name)
- if b == 11:
- break
- else:
- name = input('请输入正确的用户名(手机号):')
- else:
- print('输入不合法')
- name = input('请输入正确的用户名(手机号):')
- return name
- def game_session():
- print('''
- 欢迎进入猜数字游戏 ''')
- print('''
- 猜数字游戏规则
- 1、先由坐庄的人来写一个数字(必须在提前规定的范围内);
- 2、让大家轮流猜,并告诉大家正确数字比当前猜的数字大或者小;
- 3、每猜一次范围就会缩小,最后猜中的人倒霉挨罚;
- 4、受罚的人需要进行抽签赢得惩罚”大奖“,依此循环。''')
- while 1:
- import random
- a = [100]
- time = 0
- b = [0]
- secret = random.randint(0, 100)
- if input('请问您是否准备进入游戏(是或否):') == '是':
- print('请输入1-100之间的数字:', end='')
- while 1:
- temp = int(input())
- time += 1
- c = len(a)
- d = len(b)
- if temp == secret:
- print('恭喜你中大奖了')
- print('请接受惩罚,是真心话还是大冒险')
- break
- if time == 1:
- if temp > secret:
- print('请输入0到', temp, '的数字:', end='')
- a.append(temp)
- else:
- print('请输入', temp, '到100的数字:', end='')
- b.append(temp)
- else:
- if temp > secret:
- print('请输入', b[d - 1], '到', temp, '的数字:', end='')
- a.append(temp)
- else:
- print('请输入', temp, '到', a[c - 1], '的数字:', end='')
- b.append(temp)
- else:
- break
- def secret(uer_name):
- print('''
- |--- 密保问题设置 ---|
- b、你的生日是什么时候?
- c、你现在的梦想是什么?
- d、你现在的银行卡存款是多少?''')
- temp = input('请输入你选择的密保问题指令(b、c、d):')
- while 1:
- if temp not in 'bcdBCD':
- temp = input('指令输入错误,请重新输入(b、c、d):')
- else:
- break
- if temp in 'bB':
- sore2[uer_name] = '你的生日是什么时候?'
- elif temp in 'cC':
- sore2[uer_name] = '你现在的梦想是什么?'
- else:
- sore2[uer_name] = '你现在的银行卡存款是多少?'
- with open('E:/问题2.pkl', 'wb') as f:
- pickle.dump(sore2, f)
- code = input('请输入答案:')
- if temp == 'b' or temp == 'B':
- sore[code] = '你的生日是什么时候:'
- elif temp == 'c' or temp == 'C':
- sore[code] = '你现在的梦想是什么:'
- else:
- sore[code] = '你现在的银行卡存款是多少:'
- with open('E:/问题.pkl','wb') as f:
- pickle.dump(sore,f)
- print('密保设置成功')
- def forget_code():
- temp = input('请输入用户名(手机号):')
- while 1:
- if temp not in a:
- temp = input('您输入的用户名不存在,请重新输入(手机号):')
- else:
- break
- print(sore2[temp])
- b = input('请输入你的答案:')
- while 1:
- if b in sore:
- print('密保答案正确')
- break
- else:
- b = input('密保问题错误,请重新输入:')
- a[temp] = input('请输入要修改的密码:')
- with open('E:/游戏.pkl', 'wb') as f:
- pickle.dump(a, f)
- def new_user():
- temp = input('请输入用户名(手机号):')
- temp = user_name(temp)
- while 1:
- if temp in a:
- temp = input('用户名已经存在,请重新输入(手机号):')
- temp = user_name(temp)
- else:
- break
- code = input('请输入密码:')
- code_grade(code)
- a[temp] = code
- secret(temp)
- print('注册成功了,赶紧登录试试吧!')
- with open('E:/游戏.pkl', 'wb') as f:
- pickle.dump(a, f)
- def old_user():
- temp = input('请输入用户名(手机号)2:')
- while 1:
- if temp not in a:
- temp = input('您输入的用户名不存在,请重新输入(手机号):')
- else:
- break
- code = input('请输入密码:')
- k = a[temp]
- while 1:
- if k == code:
- game_session()
- print('欢迎下次再来玩 ')
- print(' 再见 ')
- break
- else:
- code = input('您输入的密码错误,请重新输入:')
- def alter_code():
- temp = input('请输入用户名(手机号):')
- while 1:
- if temp not in a:
- temp = input('您输入的用户名不存在,请重新输入(手机号):')
- else:
- break
- code = input('请输入密码:')
- k = a[temp]
- while 1:
- if code != k:
- code = input('您输入的密码错误,请重新输入:')
- else:
- break
- a[temp] = input('请输入修改的密码:')
- with open('E:/游戏.pkl', 'wb') as f:
- pickle.dump(a, f)
- def dain_list():
- promt = '''
- |--- 新建用户:N/n ---|
- |--- 登录账号:E/e ---|
- |--- 修改密码:R/r ---|
- |--- 忘记密码:W/w----|
- |--- 退出程序:Q/q ---|
- |--- 请输入指令代码:'''
- while 1:
- choice = input(promt)
- if choice in 'QqNnEeRrWw':
- if choice == 'n' or choice == 'N':
- new_user()
- elif choice == 'q' or choice == 'Q':
- break
- elif choice == 'r' or choice == 'R':
- alter_code()
- elif choice == 'E' or choice == 'e':
- old_user()
- else:
- forget_code()
- else:
- promt = '指令输入错误,请重新输入:'
- dain_list()
复制代码 |
评分
-
查看全部评分
|