A small game implement with Python
Keywords: Pinball, cvavas, Python for kids.
Classes
- class Ball(object):
- class Paddle(object):
- class Borad(object):
Functions
- Ball
- def init(self, canvas, color, paddle):
- def hit_paddle(self, pos):
- def draw(self):
- Paddle
- def init(self, canvas, color):
- def draw(self):
- def left(self, event):
- def right(self, event):
- Borad
- def init(self, canvas):
- def draw(self, ball):
- def def showFinalScore(self, ball):
Main-part
tk = Tk()
tk.title('Game By SJS')
tk.resizable(0, 0)
tk.wm_attributes("-topmost", 1)
canvas = Canvas(tk, width = 500, height = 400, bd = 0,
highlighttickness = 0)
canvas.pack()
canvas.update()
paddle = Paddle(canvas, 'blue')
ball = Ball(canvas, 'red', paddle)
borad = Borad(canvas)
while True:
if ball.hit_bottom == False:
borad.draw(ball)
ball.draw()
paddle.draw()
tk.update_idletasks()
tk.update()
time.sleep(0.01)
if ball.hit_bottom == True:
borad.showFinalScore(ball)
time.sleep(3)
break
Results
chart 1 Initiation of Pinball Game
chart 2 End of Pinball Game