好的基本内容完成了,我们来做一些优化。
【1】
计分系统
我打算还是用time,活一段时间就算一分!
那么可以在前面加上一句:
st=time.time()
yes.Perfect.
好然后我们来做一个写字的画笔,程序【全文】我直接写在这里了:
#coding=utf-8
import turtle
import time
import random
turtle.title("project:ball game----make it interesting and make you interested.")
turtle.bgcolor("skyblue")
turtle.setup(600,600,0,0)
t=turtle.Pen()
t.penup()
t.shape("circle")
t.goto(-300,0)
t.fillcolor("red")
g=turtle.Pen()
g.penup()
g.goto(-300,-10)
g.pendown()
g.forward(600)
g.hideturtle()
sp=5
t.speed(0)
g.speed(0)
gd=0
ti=99999999999999999999999999999999999999999999999999
st=time.time()
d=turtle.Pen()
d.penup()
d.hideturtle()
d.goto(-150,200)
def jump():
global gd,t,ti
ti=int(time.time())
gd+=1
t.sety(gd*20)
def make_road():
global g
rd=["-","-","-"]
for i in range(17):
a=random.randint(1,2)
if a==1 and not( rd[-1]==rd[-2]==rd[-3]==" "):
rd.append(" ")
else:
rd.append("-")
return rd
f=["-","-","-","-","-","-","-","-","-","-","-","-","-","-","-","-","-","-","-","-"]
timew=-1
nw=0
d.write("得分:"+str(0)+"分",font=("宋体",30,"normal"))
while True:
bf=int((time.time()-st)/2)
if bf != nw:
d.clear()
d.write("得分:"+str(bf)+"分",font=("宋体",30,"normal"))
nw=int((time.time()-st)/2)
timew+=1
t.sety(gd*20)
if tuple(t.position())[0]>300:
timew=-1
t.goto(-300,gd*20)
g.clear()
g.penup()
g.goto(-300,-10)
g.pendown()
f=make_road()
for i in f:
if i=="-":
g.forward(30)
else:
g.penup()
g.forward(30)
g.pendown()
else:
if gd==0:
s=(timew+1)%20
if f[int(timew/int(600/(20*sp)))]=="-":
t.circle(0,-180)
t.setheading(0)
t.forward(sp)
else:
t.setheading(-90)
t.forward(300)
d.clear()
d.write("得分:"+str(int((time.time()-st)/2))+"分,游戏结束",font=("宋体",30,"normal"))
break
else:
t.circle(0, -180)
t.setheading(0)
t.forward(sp)
if int(time.time())-ti==1:
gd-=1
turtle.onkey(jump,"Up")
time.sleep(0.01)
turtle.mainloop()
92lines,very long but perfect.
行。
---------------------------------未完下文:【4】---------------------------------------------------------
这篇博客展示了一个使用Python turtle模块编写的趣味游戏。游戏中,玩家控制角色跳跃避开障碍物,随着时间推移得分增加。游戏界面包含得分显示、随机生成的跑道以及按键响应等功能,代码实现详细且完整。

708

被折叠的 条评论
为什么被折叠?



