鱼C论坛

 找回密码
 立即注册
查看: 1990|回复: 0

[作品展示] 新写的小游戏

[复制链接]
发表于 2022-4-10 11:24:41 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 QQ小鱼 于 2022-4-10 11:44 编辑

这是我写的小游戏

  1. import os
  2. import pickle

  3. #用户名和登录密码的储存
  4. if not os.path.exists('E:/游戏.pkl'):
  5.     with open('E:/游戏.pkl', 'wb') as f:
  6.         pickle.dump({},f)
  7. else:
  8.     with open('E:/游戏.pkl', 'rb') as f:
  9.         a = pickle.load(f)

  10. #密保和问题的储存
  11. if not os.path.exists('E:/问题.pkl'):
  12.     with open('E:/问题.pkl', 'wb') as f:
  13.         pickle.dump({},f)
  14. else:
  15.     with open('E:/问题.pkl', 'rb') as f:
  16.         sore = pickle.load(f)

  17. #用户名和问题的储存
  18. if not os.path.exists('E:/问题2.pkl'):
  19.     with open('E:/问题2.pkl', 'wb') as f:
  20.         pickle.dump({},f)
  21. else:
  22.     with open('E:/问题2.pkl', 'rb') as f:
  23.         sore2 = pickle.load(f)

  24. def code_grade(code):
  25.     list = r'''!@#$%^&*()_+--={}|:"?><[]\;'.,/'''
  26.     while True:
  27.         length = len(code)
  28.         while (code.isspace() or length == 0):  # 排除空格和没输入密码
  29.             code = input('密码不能空,请重新输入密码:')
  30.             length = len(code)
  31.         if 0 < length <= 8:  # 确定密码的长度
  32.             flag1 = 1
  33.         elif 8 < length <= 16:
  34.             flag1 = 2
  35.         else:
  36.             flag1 = 3

  37.         flag2 = 0  # 提前定义数字

  38.         for each in code:  # 确定字符的类型
  39.             if each.isalpha():
  40.                 flag2 += 1
  41.                 break

  42.         for each in code:
  43.             if each.isdigit():
  44.                 flag2 += 1
  45.                 break

  46.         for each in code:
  47.             if each in list:
  48.                 flag2 += 1
  49.                 break

  50.         print('你的密码等级为:', end='')
  51.         if flag1 == 1 or flag2 == 1:
  52.             print('低')
  53.         elif flag1 == 3 and flag2 == 3 and (code[0].isdigit()):
  54.             print('高')
  55.             break
  56.         else:
  57.             print('中')
  58.             break
  59.         print('''密码等级过低,请通过以下三种方式提高密码等级:
  60.         \t1、密码必须由数字、字母或者特殊符号(@#$)中任意两种搭配
  61.         \t2、密码长度不能低于8位
  62.         \t3、密码必须是字母开头''')
  63.         code = input('请重新输入密码:')
  64.     return code

  65. def user_name(name):
  66.     while 1:
  67.         if name.isdigit():
  68.             b = len(name)
  69.             if b == 11:
  70.                 break
  71.             else:
  72.                 name = input('请输入正确的用户名(手机号):')
  73.         else:
  74.             print('输入不合法')
  75.             name = input('请输入正确的用户名(手机号):')
  76.     return name

  77. def game_session():
  78.     print('''
  79.            欢迎进入猜数字游戏            ''')
  80.     print('''
  81.             猜数字游戏规则
  82. 1、先由坐庄的人来写一个数字(必须在提前规定的范围内);

  83. 2、让大家轮流猜,并告诉大家正确数字比当前猜的数字大或者小;

  84. 3、每猜一次范围就会缩小,最后猜中的人倒霉挨罚;

  85. 4、受罚的人需要进行抽签赢得惩罚”大奖“,依此循环。''')
  86.     while 1:
  87.         import random
  88.         a = [100]
  89.         time = 0
  90.         b = [0]
  91.         secret = random.randint(0, 100)
  92.         if input('请问您是否准备进入游戏(是或否):') == '是':
  93.             print('请输入1-100之间的数字:', end='')
  94.             while 1:
  95.                 temp = int(input())
  96.                 time += 1
  97.                 c = len(a)
  98.                 d = len(b)
  99.                 if temp == secret:
  100.                     print('恭喜你中大奖了')
  101.                     print('请接受惩罚,是真心话还是大冒险')
  102.                     break
  103.                 if time == 1:
  104.                     if temp > secret:
  105.                         print('请输入0到', temp, '的数字:', end='')
  106.                         a.append(temp)
  107.                     else:
  108.                         print('请输入', temp, '到100的数字:', end='')
  109.                         b.append(temp)
  110.                 else:
  111.                     if temp > secret:
  112.                         print('请输入', b[d - 1], '到', temp, '的数字:', end='')
  113.                         a.append(temp)
  114.                     else:
  115.                         print('请输入', temp, '到', a[c - 1], '的数字:', end='')
  116.                         b.append(temp)
  117.         else:
  118.             break

  119. def secret(uer_name):
  120.     print('''
  121. |--- 密保问题设置 ---|
  122. b、你的生日是什么时候?
  123. c、你现在的梦想是什么?
  124. d、你现在的银行卡存款是多少?''')
  125.     temp = input('请输入你选择的密保问题指令(b、c、d):')
  126.     while 1:
  127.         if temp not in 'bcdBCD':
  128.             temp = input('指令输入错误,请重新输入(b、c、d):')
  129.         else:
  130.             break
  131.     if temp in 'bB':
  132.         sore2[uer_name] = '你的生日是什么时候?'
  133.     elif temp in 'cC':
  134.         sore2[uer_name] = '你现在的梦想是什么?'
  135.     else:
  136.          sore2[uer_name] = '你现在的银行卡存款是多少?'
  137.     with open('E:/问题2.pkl', 'wb') as f:
  138.         pickle.dump(sore2, f)
  139.     code = input('请输入答案:')
  140.     if temp == 'b' or temp == 'B':
  141.         sore[code] = '你的生日是什么时候:'
  142.     elif temp == 'c' or temp == 'C':
  143.         sore[code] = '你现在的梦想是什么:'
  144.     else:
  145.         sore[code] = '你现在的银行卡存款是多少:'
  146.     with open('E:/问题.pkl','wb') as f:
  147.         pickle.dump(sore,f)
  148.     print('密保设置成功')


  149. def forget_code():
  150.     temp = input('请输入用户名(手机号):')
  151.     while 1:
  152.         if temp not in a:
  153.             temp = input('您输入的用户名不存在,请重新输入(手机号):')
  154.         else:
  155.             break
  156.     print(sore2[temp])
  157.     b = input('请输入你的答案:')
  158.     while 1:
  159.         if b in sore:
  160.             print('密保答案正确')
  161.             break
  162.         else:
  163.             b = input('密保问题错误,请重新输入:')
  164.     a[temp] = input('请输入要修改的密码:')
  165.     with open('E:/游戏.pkl', 'wb') as f:
  166.         pickle.dump(a, f)




  167. def new_user():
  168.     temp = input('请输入用户名(手机号):')
  169.     temp = user_name(temp)
  170.     while 1:
  171.         if temp in a:
  172.             temp = input('用户名已经存在,请重新输入(手机号):')
  173.             temp = user_name(temp)
  174.         else:
  175.             break
  176.     code = input('请输入密码:')
  177.     code_grade(code)
  178.     a[temp] = code
  179.     secret(temp)
  180.     print('注册成功了,赶紧登录试试吧!')
  181.     with open('E:/游戏.pkl', 'wb') as f:
  182.         pickle.dump(a, f)


  183. def old_user():
  184.     temp = input('请输入用户名(手机号)2:')
  185.     while 1:
  186.         if temp not in a:
  187.             temp = input('您输入的用户名不存在,请重新输入(手机号):')
  188.         else:
  189.             break
  190.     code = input('请输入密码:')
  191.     k = a[temp]
  192.     while 1:
  193.         if k == code:
  194.             game_session()
  195.             print('欢迎下次再来玩 ')
  196.             print('   再见 ')
  197.             break
  198.         else:
  199.             code = input('您输入的密码错误,请重新输入:')


  200. def alter_code():
  201.     temp = input('请输入用户名(手机号):')
  202.     while 1:
  203.         if temp not in a:
  204.             temp = input('您输入的用户名不存在,请重新输入(手机号):')
  205.         else:
  206.             break
  207.     code = input('请输入密码:')
  208.     k = a[temp]
  209.     while 1:
  210.         if code != k:
  211.             code = input('您输入的密码错误,请重新输入:')
  212.         else:
  213.             break
  214.     a[temp] = input('请输入修改的密码:')
  215.     with open('E:/游戏.pkl', 'wb') as f:
  216.         pickle.dump(a, f)


  217. def dain_list():
  218.     promt = '''
  219. |--- 新建用户:N/n ---|
  220. |--- 登录账号:E/e ---|
  221. |--- 修改密码:R/r ---|
  222. |--- 忘记密码:W/w----|
  223. |--- 退出程序:Q/q ---|
  224. |--- 请输入指令代码:'''
  225.     while 1:
  226.         choice = input(promt)
  227.         if choice in 'QqNnEeRrWw':
  228.             if choice == 'n' or choice == 'N':
  229.                 new_user()
  230.             elif choice == 'q' or choice == 'Q':
  231.                 break
  232.             elif choice == 'r' or choice == 'R':
  233.                 alter_code()
  234.             elif choice == 'E' or choice == 'e':
  235.                 old_user()
  236.             else:
  237.                 forget_code()
  238.         else:
  239.             promt = '指令输入错误,请重新输入:'

  240. dain_list()
复制代码

评分

参与人数 1荣誉 +1 鱼币 +1 收起 理由
andy大宝 + 1 + 1 活学活用^_^

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-29 08:35

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表