文件名称:python代码——弹球
文件大小:3KB
文件格式:PY
更新时间:2021-08-03 04:48:07
pyhon 游戏代码
from tkinter import * import random import time 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=[-3,-2,-1,1,2,3] random.shuffle(starts) self.x=starts[0] self.y=-3 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、