马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
猜数字plus
改编自小甲鱼的啦
用easygui做了界面,加上了四个难度等级,用pygame搞上了背景音乐,还自带检测历史记录并保存历史记录
才学完小甲鱼的课程
练练手啦!import easygui as g
import sys
import pygame
import sys
from pygame.locals import *
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load("music.ogg")
pygame.mixer.music.set_volume(0.2)
pygame.mixer.music.play()
pygame.display.set_caption("Music")
bg_size = width,height = 3,2
screen = pygame.display .set_mode(bg_size)
pygame.display.set_caption("MUSIC")
pygame.init()
size = width, height = 600,400
speed = [-2,1]
bg = (255,255,255)
g.msgbox("作者曲速飞跃,版本:5.0")
name = g.enterbox('你的名字?')
g.msgbox('很高兴遇见你,' +name )
g.msgbox("游戏规则:系统会随即选择一个数,你来猜那是几。")
msg = '游戏难度等级?(1即在1~10000中找,2即在1~1000中找,以此类推)'
title = '请输入'
choices = ['1','2','3','4']
nan = g.choicebox(msg,title,choices)
nandu = int(nan)
if nandu == 2:
import random
secret = random.randint(1,1000)#系统随机选择1—1000中的一个数
temp = g.enterbox("猜猜宝藏是数字几?")
guess = int(temp)
aaa = ['a']
while guess !=secret:
temp = g.enterbox("猜错了,真可惜,再来吧ヾ◍°∇°◍ノ゙")
guess = int (temp)
aaa.append("a")
if guess == secret:
g.msgbox("啊!你真NB!对辣!๑•̀ㅂ•́و✧")
else:
if guess == 0:
g.msgbox("正确答案是"+ str(secret) +",下次努力叭!")
exit(0) # 无错误退出
else:
if guess >secret:
g.msgbox("大了!哥!")
else:
g.msgbox("小了!小了!")
else:
if nandu == 3:
import random
secret = random.randint(1,100)#系统随机选择1—100中的一个数
temp = g.enterbox("猜猜宝藏是数字几?")
guess = int(temp)
aaa = ['a']
while guess !=secret:
temp = g.enterbox("猜错了,真可惜,再来吧ヾ◍°∇°◍ノ゙")
guess = int (temp)
aaa.append("a")
if guess == secret:
g.msgbox("啊!你真NB!对辣!๑•̀ㅂ•́و✧")
else:
if guess == 0:
g.msgbox("正确答案是"+ str(secret) +",下次努力叭!")
exit(0) # 无错误退出
else:
if guess >secret:
g.msgbox("大了!哥!")
else:
g.msgbox("小了!小了!")
else:
if nandu ==4:
import random
secret = random.randint(1,10)#系统随机选择1—10中的一个数
temp = g.enterbox("猜猜宝藏是数字几?")
guess = int(temp)
aaa = ['a']
while guess !=secret:
temp = g.enterbox("猜错了,真可惜,再来吧ヾ◍°∇°◍ノ゙")
guess = int (temp)
aaa.append("a")
if guess == secret:
g.msgbox("啊!你真NB!对辣!๑•̀ㅂ•́و✧")
else:
if guess == 0:
g.msgbox("正确答案是"+ str(secret) +",下次努力叭!")
exit(0) # 无错误退出
else:
if guess >secret:
g.msgbox("大了!哥!")
else:
g.msgbox("小了!小了!")
else:
import random
secret = random.randint(1,10000)#系统随机选择1—10000中的一个数
temp = g.enterbox("猜猜宝藏是数字几?")
guess = int(temp)
aaa = ['a']
while guess !=secret:
temp = g.enterbox("猜错了,真可惜,再来吧ヾ◍°∇°◍ノ゙")
guess = int (temp)
aaa.append("a")
if guess == secret:
g.msgbox("啊!你真NB!对辣!๑•̀ㅂ•́و✧")
else:
if guess == 0:
g.msgbox("正确答案是"+ str(secret) +",下次努力叭!")
exit(0) # 无错误退出
else:
if guess >secret:
g.msgbox("大了!哥!")
else:
g.msgbox("小了!小了!")
time = int(len(aaa))
g.msgbox("您一共猜了"+ str(time) +"次")
times = int(time)
if nandu == 4:
if time <= 3:
g.msgbox("NICE!!!")
else:
if 3 < time <= 6:
g.msgbox("GREAT!!!")
else:
g.msgbox("GOOD!!!")
else:
if nandu == 3:
if time <= 5:
g.msgbox("NICE!!!")
else:
if 5 < time <= 8:
g.msgbox("GREAT!!!")
else:
g.msgbox("GOOD!!!")
else:
if nandu == 2:
if time <= 7:
g.msgbox("NICE!!!")
else:
if 7 < time <= 13:
g.msgbox("GREAT!!!")
else:
g.msgbox("GOOD!!!")
else:
if time <= 9:
g.msgbox("NICE!!!")
else:
if 9 < time <= 15:
g.msgbox("GREAT!!!")
else:
g.msgbox("GOOD!!!")
if nandu == 4:
a =open('D://my.code/数字宝藏/数据4.txt')
b = a.read()
c = int(b)
if time >= c:
g.msgbox("还是没有超过历史记录哦,历史记录是"+ str(c))
else:
g.msgbox("超过历史记录啦!继续加油吖0∩_∩0!")
with open('数据4.txt','w') as f:
f.write(str(time))
else :
if nandu == 3:
a = open('D://my.code/数字宝藏/数据3.txt')
b = a.read()
c = int(b)
if time >= c:
g.msgbox("还是没有超过历史记录哦,历史记录是" + str(c))
else:
g.msgbox("超过历史记录啦!继续加油啊!")
with open('数据3.txt','w') as f:
f.write(str(time))
else:
if nandu == 2:
a =open('D://my.code/数字宝藏/数据2.txt')
b = a.read()
c = int(b)
if time >= c:
g.msgbox("还是没有超过历史记录哦,历史记录是" + str(c))
else:
g.msgbox("超过历史记录啦!继续加油啊!")
with open('数据2.txt','w') as f:
f.write(str(time))
else:
a =open('D://my.code/数字宝藏/数据1.txt')
b = a.read()
c = int(b)
if time >= c:
g.msgbox("还是没有超过历史记录哦,历史记录是"+ str(c))
else:
g.msgbox("超过历史记录啦!继续加油啊!")
with open('数据1.txt','w') as f:
f.write(str(time))
pygame.mixer.music.stop()
g.msgbox('再见ヾ ̄▽ ̄Bye~Bye~,'+ name )
|