用户:
沉著的飞叶龙uZWJ查看:1 回复:1 评论:1 创建时间:2020-04-24T18:45:27
【作品展示】

【作品介绍】
修复了打开存档时会出现的一个bug。现在大家可以放心玩啦!感谢我吧!
【作品源代码】
import turtle
import random
import easygui
import os
import time#准备
wanjia = turtle.Pen()
enemy = turtle.Pen()
paodan = turtle.Pen()#准备
wanjia.penup()
enemy.penup()
paodan.penup()#还是准备
turtle.bgcolor('black')
wanjia.color('white', 'white')
enemy.color('white', 'white')
paodan.color('white', 'white')#还是准备!
enemy.speed(0)
coin = 0
fuwwengchengjiu=1
maiguangshangdianchemgjiu=1
paodan.left(90)
enemy.right(90)#还是准备!!
def left():
wanjia.setx(wanjia.xcor()- 10)
def right():
wanjia.setx(wanjia.xcor() + 10)
def fire():
paodan.goto(wanjia.xcor(), wanjia.ycor())
paodan.forward(600)
#还是准备!!!
def plane():
enemy.setheading(0)
enemy.pencolor("#666666")
enemy.fillcolor("#666666")
enemy.begin_fill()
enemy.penup()
enemy.forward(50)
enemy.left(90)
enemy.pendown()
enemy.forward(100)
enemy.circle(50, 90)
enemy.setheading(90)
enemy.pensize(5)
enemy.forward(100)
enemy.pensize(1)
enemy.backward(100)
enemy.left(90)
enemy.circle(50, 90)
enemy.forward(100)
enemy.end_fill()
enemy.pencolor("#000000")
enemy.fillcolor("#000000")
enemy.penup()
enemy.goto((-25), 120)
enemy.setheading(0)
enemy.pendown()
enemy.begin_fill()
for __count in range(2):
enemy.forward(50)
enemy.right(90)
enemy.forward(20)
enemy.right(90)
enemy.end_fill()
enemy.penup()
enemy.goto((-50), 0)
enemy.pendown()
enemy.pencolor("#666600")
enemy.fillcolor("#666600")
enemy.begin_fill()
enemy.goto((-200), (-100))
enemy.forward(400)
enemy.goto(50, 0)
enemy.end_fill()
enemy.right(90)
enemy.pencolor("#666666")
enemy.fillcolor("#666666")
enemy.penup()
enemy.goto(50, (-100))
enemy.pendown()
enemy.begin_fill()
for __count in range(2):
enemy.forward(60)
enemy.right(90)
enemy.forward(100)
enemy.right(90)
enemy.end_fill()
enemy.penup()
enemy.goto((-50), (-160))
enemy.pendown()
enemy.pencolor("#ff0000")
enemy.fillcolor("#ff0000")
enemy.penup()
for __count in range(100):
enemy.goto(random.uniform((-50), 50), random.uniform((-160), (-300)))
enemy.dot(5)
enemy.setheading(-90)
enemy.penup()#画飞机的函数(初始位置0,0)P.S:终于不是准备了TOT
opt = '0'
your_texiao=['boom!']
texiao_now='boom!'
paodan.speed(8)
your_color = ['white']
total_score = 0
total_play = 0#没想到吧还是准备!哈哈哈!!!!!!!!!
texiao=['王炸!','超神!','喵!','命中!','First blood','Double 喵','Trible 喵','Altra 喵','Penta 喵','Legendary',]
def randomcolor():
colour='#'
List = ['0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f']
for _count in range(6):
colour+=random.choice(List)
return colour #还是……准……备
color = ['red', 'orange', 'yellow', 'green', 'blue', 'dark blue',
'purple', 'pink', 'grey', 'gold', 'sky blue', 'brown']#同……上……
enemy.goto(0,0)#到画飞机的初始位置
plane()#画飞机
name=turtle.textinput('输入你的名字','玩家名称')#字面意思
def data_in_dir():
for file in os.listdir():
if file=="data.txt":
return True
return False#寻找是否有之前的数据
if data_in_dir():#找到
if easygui.ynbox('检测到你有以前的游戏数据,是否还原?','!有以前的数据!',('还原','不了,谢谢')):#是否还原
easygui.msgbox('还原中……','飞机大战-还原','我知道了')
time.sleep(1)
data = open('data.txt')
data_readline=data.readline()
total_score = int(data_readline.split(':')[-1])
data_readline = data.readline()
total_play = int(data_readline.split(':')[-1])
data_readline = data.readline()
coin = int(data_readline.split(':')[-1])
data_readline = data.readline()
your_texiao = (data_readline.split(':')[-1]).split(',')
data_readline = data.readline()
your_color = (data_readline.split(':')[-1]).split(',')
data.close()
easygui.msgbox('还原成功!', '飞机大战-还原', '我知道了')#导入数据
for i in range(len(your_color)):
your_color[i] = your_color[i].replace('\n', '')
for i in range(len(your_texiao)):
your_texiao[i]=your_texiao[i].replace('\n','')
else: # 没有找到
with open('data.txt','w')as f:
f.write('total_score:'+str(total_score)+'\n')
f.write('total_play:'+str(total_play)+'\n')
f.write('coin:'+str(coin)+'\n')
f.write('your_texiao:'+str(your_texiao).replace('[','').replace(']','').replace("'",'')+'\n')
f.write('your_color:'+str(your_color).replace('[', '').replace(']', '').replace("'", '')+'\n')#新建数据
time.sleep(2)
easygui.msgbox('开始加载游戏……')
for i in range(1,101):
wanjia.goto(0,100)
wanjia.write("{}%".format(i),font=("微软雅黑",10,'bold'))
time.sleep(0.08)
wanjia.undo()
wanjia.left(90)
easygui.msgbox('加载成功!')
time.sleep(1)#加载程序
t=time.ctime()[0:3]
while True:#游戏主体
if time.ctime()[0:3]!=t:
t = time.ctime()[0:3]
easygui.msgbox('每日签到,请收下30金币','签到','点我签到')
coin+=30
opt = easygui.buttonbox(
'想干什么呢?', '飞机大战', ('开战', '商店', '抽奖', '设置皮肤', '设置特效', '查看档案', '玩法说明','退出'))
if opt=='开战': #↑玩家的操作位于这个变量里面
total_play+=1#总局数+1
wanjia.clear()
paodan.clear()#清空除飞机外的痕迹
defen = 0#重置得分
wanjia.sety(-300)
enemy.goto(random.randint(-300, 300), 300)#设置飞机位置
while enemy.ycor() > -300:
enemy.forward(10)#敌机移动
time.sleep(0.1)
turtle.onkey(left, 'a')
turtle.onkey(right, 'd')
turtle.onkey(fire, 'space')#按键操作
turtle.listen()#监听键盘
if abs(paodan.xcor()-enemy.xcor()) <= 5:#命中的条件
defen += 1#得分+1
total_score += 1#总得分+1
paodan.speed(0)
paodan.goto(enemy.xcor(), enemy.ycor())
paodan.speed(8)
paodan.pendown()
paodan.write(texiao_now)#特效绘制
paodan.penup()
enemy.goto(random.randint(-300, 300), 300)#重置敌机坐标
wanjia.write('game over')
coin += defen#游戏结束
easygui.msgbox('你的分数是{}分,增加{}个金币'.format(defen, defen),'得分提示','领取金币')#游戏结果报告
elif opt == '商店':
if easygui.ynbox('进入皮肤商店还是击杀特效商店','商店选择',("皮肤商店",'击杀特效商店')):#商店选择
easygui.msgbox('你现在有{}个金币'.format(coin), '商店')#金币数量报告
easygui.msgbox('商店内有{}'.format(color), '商店')#店内物品
buy = turtle.textinput('商店','想买哪个?一个10金币哦~')
if buy in color:#输入正确的情况
if coin<10:#钱不够的情况
easygui.msgbox('买不起哦,下次再来!^_^','缺钱提示','好的')
else:#钱够的情况
easygui.msgbox('得到皮肤!真棒!($_$)','购买成功提示')
color.pop(color.index(buy))
coin-=10
your_color.append(buy)
else:#输入不正确的情况
easygui.msgbox('没有这个商品!', '输入有误通知', '好的')
else:
easygui.msgbox('你现在有{}个金币'.format(coin), '商店') # 金币数量报告
easygui.msgbox('商店内有{}'.format(texiao)) # 店内物品
buy = turtle.textinput('商店', '想买哪个?一个10金币哦~')
if buy in texiao: # 输入正确的情况
if coin < 10: # 钱不够的情况
easygui.msgbox('买不起哦,下次再来!^_^', '缺钱提示', '好的')
else: # 钱够的情况
easygui.msgbox('得到特效!真棒!($_$)', '购买成功提示')
texiao.pop(texiao.index(buy))
coin -= 10
your_texiao.append(buy)
else: # 输入不正确的情况
easygui.msgbox('没有这个商品!', '输入有误通知', '好的')
elif opt == '玩法说明':
easygui.msgbox('a键→飞机向左移动', '玩法说明', '知道了')
easygui.msgbox('d键→飞机向右移动', '玩法说明', '知道了')
easygui.msgbox('空格键→发喵弹', '玩法说明', '知道了')#玩法说明
elif opt == '抽奖':
easygui.msgbox('欢迎来到抽奖环节!')#欢迎提示
if easygui.ynbox('50金币一次抽奖。准备好了吗?','抽奖',('准备好了','还没有')):
if coin<50:#喵抽奖的情况
easygui.msgbox('喵抽奖哦ToT','缺钱提示')
else:#可以抽奖的情况
easygui.msgbox('抽奖开始!')
time.sleep(2)
easygui.msgbox('(转盘正在转)')
time.sleep(2)
choujiang=randomcolor()
easygui.msgbox('抽奖成功!你获得了皮肤{}'.format(choujiang),'抽奖成功提示')
coin-=50
your_color.append(choujiang)#抽奖过程
elif opt=='设置皮肤':
easygui.msgbox('你现在有皮肤{}'.format(your_color))#皮肤报告
if your_color==['white']:#只有初始皮肤的情况
easygui.msgbox('你没有皮肤可换!')
else:#有其他皮肤的情况
skin=turtle.numinput('皮肤设置',"告诉我你要换成的皮肤的序号。")
try:#输入的对的情况
wanjia.color(your_color[int(skin)])
easygui.msgbox("更换皮肤完成!")
except: # 输入的不对的情况
easygui.msgbox('输入有误!', '输入有误通知', '好的')
elif opt=='设置特效':
easygui.msgbox('你现在有特效{}'.format(your_texiao)) # 击杀特效报告
if your_texiao == ['boom!']: # 只有初始特效的情况
easygui.msgbox('你没有特效可换!')
else:#有其他皮特效的情况
tx=turtle.numinput('特效设置','告诉我你要换成的特效的序号。')
try: # 输入的对的情况
texiao_now = your_texiao[int(tx)]
easygui.msgbox('更换特效完成!')
except: # 输入的不对的情况
easygui.msgbox('输入有误!', '输入有误通知', '好的')
elif opt == '查看档案':
wanjia.goto(0,100)
wanjia.write('玩家名称:', font=('微软雅黑', 30, 'normal'))
wanjia.goto(200, 100)
wanjia.write(name, font=("微软雅黑", 25, 'italic'))
wanjia.goto(0, 50)
wanjia.write('总局数:', font=('微软雅黑', 30, 'normal'))
wanjia.goto(150, 50)
wanjia.write(total_play, font=("微软雅黑", 25, 'italic'))
wanjia.goto(0, 0)
wanjia.write('总得分/总击杀:', font=("微软雅黑", 30, 'normal'))
wanjia.goto(300, 0)
wanjia.write(total_score, font=("微软雅黑", 25, 'italic'))
wanjia.goto(0, -50)
wanjia.write('总皮肤数:',font=("微软雅黑",30,'normal'))
wanjia.goto(200,-50)
wanjia.write(len(your_color), font=("微软雅黑", 25, 'italic'))
wanjia.goto(0, -100)
wanjia.write('总特效数:', font=("微软雅黑", 30, 'normal'))
wanjia.goto(200, -100)
wanjia.write(len(your_texiao), font=(
"微软雅黑", 25, 'italic')) # 在海龟画布上书写档案
elif opt == '退出':
quit()
else:
easygui.msgbox('你发现了彩蛋!','彩蛋','作者最帅')#彩蛋
if coin >= 100 and fuwwengchengjiu:#成就
easygui.msgbox('完成隐藏成就“富翁”(拥有100枚金币),免费赠送您海龟形状!','成就','领取')
wanjia.shape('turtle')
fuwwengchengjiu=0
if color==[] and maiguangshangdianchemgjiu:#成就
easygui.msgbox('完成隐藏成就“买光商店”(和你想的一样),获得1000金币!','成就','领取')
maiguangshangdianchemgjiu=0
coin+=1000
with open('data.txt','w')as f:
f.write('total_score:'+str(total_score)+'\n')
f.write('total_play:'+str(total_play)+'\n')
f.write('coin:'+str(coin)+'\n')
f.write('your_texiao:'+str(your_texiao).replace('[','').replace(']','').replace("'",'')+'\n')
f.write('your_color:'+str(your_color).replace('[', '').replace(']', '').replace("'", '')+'\n')
#更新数据↑
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn