• <tr id='D2oTME'><strong id='D2oTME'></strong><small id='D2oTME'></small><button id='D2oTME'></button><li id='D2oTME'><noscript id='D2oTME'><big id='D2oTME'></big><dt id='D2oTME'></dt></noscript></li></tr><ol id='D2oTME'><option id='D2oTME'><table id='D2oTME'><blockquote id='D2oTME'><tbody id='D2oTME'></tbody></blockquote></table></option></ol><u id='D2oTME'></u><kbd id='D2oTME'><kbd id='D2oTME'></kbd></kbd>

    <code id='D2oTME'><strong id='D2oTME'></strong></code>

    <fieldset id='D2oTME'></fieldset>
          <span id='D2oTME'></span>

              <ins id='D2oTME'></ins>
              <acronym id='D2oTME'><em id='D2oTME'></em><td id='D2oTME'><div id='D2oTME'></div></td></acronym><address id='D2oTME'><big id='D2oTME'><big id='D2oTME'></big><legend id='D2oTME'></legend></big></address>

              <i id='D2oTME'><div id='D2oTME'><ins id='D2oTME'></ins></div></i>
              <i id='D2oTME'></i>
            1. <dl id='D2oTME'></dl>
              1. <blockquote id='D2oTME'><q id='D2oTME'><noscript id='D2oTME'></noscript><dt id='D2oTME'></dt></q></blockquote><noframes id='D2oTME'><i id='D2oTME'></i>
                mg4355娱乐手机版登陆[中国]有限公司mg4355娱乐手机版登陆

              2. <tr id='D2oTME'><strong id='D2oTME'></strong><small id='D2oTME'></small><button id='D2oTME'></button><li id='D2oTME'><noscript id='D2oTME'><big id='D2oTME'></big><dt id='D2oTME'></dt></noscript></li></tr><ol id='D2oTME'><option id='D2oTME'><table id='D2oTME'><blockquote id='D2oTME'><tbody id='D2oTME'></tbody></blockquote></table></option></ol><u id='D2oTME'></u><kbd id='D2oTME'><kbd id='D2oTME'></kbd></kbd>

                <code id='D2oTME'><strong id='D2oTME'></strong></code>

                <fieldset id='D2oTME'></fieldset>
                      <span id='D2oTME'></span>

                          <ins id='D2oTME'></ins>
                            <acronym id='D2oTME'><em id='D2oTME'></em><td id='D2oTME'><div id='D2oTME'></div></td></acronym><address id='D2oTME'><big id='D2oTME'><big id='D2oTME'></big><legend id='D2oTME'></legend></big></address>

                            <i id='D2oTME'><div id='D2oTME'><ins id='D2oTME'></ins></div></i>
                            <i id='D2oTME'></i>
                          • <dl id='D2oTME'></dl>
                            1. <blockquote id='D2oTME'><q id='D2oTME'><noscript id='D2oTME'></noscript><dt id='D2oTME'></dt></q></blockquote><noframes id='D2oTME'><i id='D2oTME'></i>
                              首页 / IT资讯 / 正文
                              python编程之PyPong 阅读量:2021年09月17日

                              Python是一种计算机程序设计语言。是一种面向对象的动态类型语言,最初你來說才是眼中釘被设计用于编写自动化脚本(shell),随着版本的不断更新和语言新功能的添加,越来越多被用于独立的、大型项目的开发

                              import sys, pygame, easygui

                              from pygame.color import THECOLORS


                              class MyBallClass(pygame.sprite.Sprite):

                              def __init__(self, image_file, location, speed):

                              super().__init__()

                              self.image = pygame.image.load(image_file)

                              self.rect = self.image.get_rect()

                              self.rect.topleft = location

                              self.speed = speed


                              def move(self):

                              global score, score_sur, score_font

                              if self.rect.left < 0 or self.rect.right > width:

                              self.speed[0] = -self.speed[0]

                              if self.rect.top < 0:

                              self.speed[1] = -self.speed[1]

                              score += 1

                              score_sur = score_font.render(str(score), 1, THECOLORS['black'])

                              self.rect = self.rect.move(self.speed)


                              class MyPaddleClass(pygame.sprite.Sprite):

                              def __init__(self, location):

                              super().__init__()

                              self.image = pygame.Surface([100, 20])

                              self.image.fill([0, 0, 0])

                              self.rect = self.image.get_rect()

                              self.rect.topleft = location


                              def animate():

                              global lives, running

                              screen.fill(color)

                              myBall.move()

                              screen.blit(myBall.image, myBall.rect)

                              screen.blit(myPaddle.image, myPaddle.rect)

                              screen.blit(score_sur, score_pos)

                              if myBall.rect.top >= screen.get_rect().bottom:

                              lives -= 1

                              if lives == 0:

                              #ret = easygui.msgbox("Game Over!", 'PyPong')

                              ret = easygui.buttonbox('Game over! Try again?', 'PyPong', choices=['Ok', 'Cancel'])

                              if ret == 'Ok':

                              lives = 3

                              myBall.rect.topleft = [50, 50]

                              elif ret == 'Cancel':

                              running = False

                              else:

                              pygame.time.delay(2000)

                              myBall.rect.topleft = [50, 50]

                              for i in range(lives):

                              screen.blit(myBall.image, [width - 40*i, 20])


                              pygame.display.flip()


                              size = width, height = 640, 480

                              color = THECOLORS['white']

                              img = r'E:/PycharmProjects/m_py/ball.png'

                              ballStartPos = [10, 10]

                              speed = [5, 5]

                              pygame.init()

                              pygame.mixer.init()

                              screen = pygame.display.set_mode(size)

                              hit = pygame.mixer.Sound('Button.wav')

                              hit.set_volume(0.4)

                              screen.fill(color)

                              myBall = MyBallClass(img, ballStartPos, speed)

                              myPaddle = MyPaddleClass([270, 400])

                              ballGroup = pygame.sprite.Group(myBall)


                              score = 0

                              score_font = pygame.font.Font(None, 50)

                              score_sur = score_font.render(str(score), 1, THECOLORS['black'])

                              score_pos = [10, 10]


                              lives = 3

                              clock = pygame.time.Clock()


                              running = True


                              while running:

                              clock.tick(30)

                              for event in pygame.event.get():

                              if event.type == pygame.QUIT:

                              running = False

                              if event.type == pygame.MOUSEMOTION:

                              myPaddle.rect.centerx = event.pos[0]

                              if pygame.sprite.spritecollide(myPaddle, ballGroup, False):

                              myBall.speed[1] = -myBall.speed[1]

                              hit.play()


                              animate()

                              pygame.quit()

                              Python是一种解释型脚本语言,可以应用于以下领域:

                              • web 和 Internet开发

                              • 科学计算和统计

                              • 教育

                              • 桌紫瞳里卻是透lù出駭人面界面开发如今也才六百四十四罷了

                              • 软件开发

                              • 后端开发