用户:
我是曲奇饼干查看:0 回复:0 评论:0 创建时间:2019-09-07T19:59:37
【作品展示】

【作品介绍】
very good随便传了一个图片
【作品源代码】
from tkinter import *
import random
import time
import turtle
import math
times=0
timess=0
time.sleep(2)
class Ball:
def __init__(self,canvas,paddle,color):
self.canvas=canvas
self.paddle=paddle
self.id=canvas.create_oval(10,10,25,25,fill=color)
self.canvas.move(self.id,245,100)
starts=[-70,-65,-60,-57,-55,-53,-51,-49,-47,-45,-43,-41,-39,-37,37,39,41,43,45,47,49,51,53,55,57,60,65,70]
random.shuffle(starts)
self.x=starts[0]
speeds=[-7,-8,-9,-10,-11]
random.shuffle(speeds)
self.y=speeds[0]
self.canvas_height=self.canvas.winfo_height()
self.canvas_width=self.canvas.winfo_width()
self.hit_bottom=False
def hit_paddle(self,pos):
paddle_pos=self.canvas.coords(self.paddle.id)
if pos[2]>=paddle_pos[0] and pos[0]<=paddle_pos[2]:
if pos[3]>=paddle_pos[1] and pos[3]<=paddle_pos[3]:
return True
return False
def draw(self):
self.canvas.move(self.id,self.x,self.y)
pos=self.canvas.coords(self.id)
if pos[1]<=0:
self.y=14.5
if pos[3]>=self.canvas_height:
self.hit_bottom=True
if self.hit_paddle(pos)==True:
self.y=-14.5
if pos[0]<=0:
self.x=14
if pos[2]>=self.canvas_width:
self.x=-14
class Paddle:
def __init__(self, canvas,color,length):
l=length
self.canvas=canvas
self.id=canvas.create_rectangle(0,0,l,15,fill=color)
self,canvas.move(self.id,200,300)
self.x=0
self.canvas_width=self.canvas.winfo_width()
self.canvas.bind_all('',self.turn_left)
self.canvas.bind_all('',self.turn_right)
def draw(self):
self.canvas.move(self.id,self.x,0)
pos=self.canvas.coords(self.id)
if pos[0]<=0:
self.x=0
elif pos[2]>=self.canvas_width:
self.x=0
def turn_left(self,evt):
self.x=-10
def turn_right(self,evt):
self.x=10
tk=Tk()
tk.title("弹球")
tk.resizable(0,0)
tk.wm_attributes("-topmost",1)
canvas=Canvas(tk,width=500,height=400,bd=0,highlightthickness=0)
canvas.pack()
tk.update()
a=random.randint(70,130)
paddle=Paddle(canvas,'#ffcc00',a)
ball=Ball(canvas,paddle,"red")
start=time.time()
while 1==1:
times=times+0.13
timess=timess+1
if ball.hit_bottom==False:
paddle.draw()
ball.draw()
timesss=end-start
b=math.floor(timesss*10)/10
print('你玩了',b,'秒')
else:
break
tk.update_idletasks()
tk.update()
time.sleep(0.1)
print('你的得分是',b,'分')
if timesss>=100:
print('你真是一个好守门员!')
elif timesss>=85:
print('你还算是优秀的')
elif timesss>=75:
print('你还是良好的!')
elif timesss>=60:
print('你刚刚及格!')
else:
print('你还得再练!')
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn