Pinball with Python

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

        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

begin

chart 1 Initiation of Pinball Game

end

chart 2 End of Pinball Game

posted @ 2017-11-11 17:34  _Ade  阅读(178)  评论(0编辑  收藏  举报