当前位置: 首页>>代码示例>>Python>>正文


Python Score.add_score方法代码示例

本文整理汇总了Python中score.Score.add_score方法的典型用法代码示例。如果您正苦于以下问题:Python Score.add_score方法的具体用法?Python Score.add_score怎么用?Python Score.add_score使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在score.Score的用法示例。


在下文中一共展示了Score.add_score方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from score import Score [as 别名]
# 或者: from score.Score import add_score [as 别名]
    def main(self):
        self.music.play()

        # Screen base
        self.screen.fill((0,0,0))
        self.screen.blit(self.img_background,self.img_background_rect)

        highscores = Highscores()

        # Main instances
        pavement = Pavement(self.unit)
        snake = Snake(self.unit)
        foods = Foods(self.unit)
        walls = Walls(self.unit)
        score = Score(self.unit,self.surface_rect)

        nextgold = random.randint(*Constants.TIMERANGE_GOLD) * Constants.FPS # first gold between 30 & 60 seconds
        makegold = False
        nextwall = random.randint(*Constants.TIMERANGE_WALL) * Constants.FPS # first gold between 30 & 60 seconds
        makewall = False

        updatestats = True

        counter = 0

        flag_music = True
        flag_pause = False
        #MAIN LOOP
        while self.running:
            time = pygame.time.get_ticks()

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.running = False
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        self.running = False

                    elif event.key == pygame.K_m:
                        flag_music = not flag_music
                        if flag_music:
                            self.music.play()
                        else:
                            self.music.stop()

                    elif event.key == pygame.K_1:
                        pygame.image.save(self.screen, "screenshot.jpg")

                    elif event.key == pygame.K_SPACE or event.key == pygame.K_p:
                        flag_pause = True
                        self.print_text("PAUSE")
                        while flag_pause:
                            for event in pygame.event.get():
                                if event.type==pygame.KEYDOWN:
                                    if event.key==pygame.K_p or event.key == pygame.K_SPACE:
                                        flag_pause = False

                    else:
                        # Time to change direction
                        action = 0
                        if event.key == pygame.K_UP or event.key == pygame.K_w: action = 1
                        elif event.key == pygame.K_DOWN or event.key == pygame.K_s: action = 2
                        elif event.key == pygame.K_LEFT or event.key == pygame.K_a: action = 3
                        elif event.key == pygame.K_RIGHT or event.key == pygame.K_d: action = 4
                        if action:
                            self.sounds.play("move")
                            snake.action(action)

            # Snake movements and pavement reactions
            snake.move()
            pavement.passage(snake.head)
            pavement.make_regrow(snake.tail)

            # Snake has eaten?
            if foods.check(snake.head):
                updatestats = True
                snake.grow(Constants.GROW)
                score.add_score(foods.score)
                self.sounds.play("eat")

            # Snake
            if walls.check(snake.head):
                snake.alive = False

            # Snake is dead?
            if not snake.alive:
                #blood splash (bin on head, little on body)
                pavement.bloodsplat(snake.head)
                [pavement.bloodsplat(x,1) for x in snake.body if random.randint(0,2)==0]
                #redraw all the snake
                snake.set_dirty(1)
                self.sounds.play("splat")
                self.running = False

            # Gold generator (After pseudo-random time a golden apple will appear)
            nextgold-=1
            if nextgold<0:
                makegold = True
                nextgold = random.randint(*Constants.TIMERANGE_GOLD)*Constants.FPS

#.........这里部分代码省略.........
开发者ID:juanjoXD,项目名称:seminario_snake,代码行数:103,代码来源:game.py


注:本文中的score.Score.add_score方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。