Pinball in 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-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

begin

chart 1 Initiation of Pinball Game

end

chart 2 End of Pinball Game

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值