Just10.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:CodeRepository 作者: sahirvsahirv 项目源码 文件源码
def control(self):
                """
                1.Main game loop - a big while to check for quit
                2.For loop to receive events
                3.Check for quit all the time, the 
                4.For loop looking for specific quit event is in __checkForQuit
                5.Mouse up and game is over - black screen case
                6.   Get a new DS, redraw the board(erase all and redraw), new game starts
                7.Mouse up but post a movement of a tile
                8.   If game is over, repeat game over routine
                     Display game over message
                9.If move - get the tile clicked, if button down due to game over
                     replay the background music
                10.Update the screen
                """
                running = True
                clickedTile = -1
                movedToTile = -1
                gameOver = False
                while running:
                        self.__checkForQuit()
                        for event in pygame.event.get():
                                if(event.type == pygame.MOUSEBUTTONUP and gameOver==True):
                                        x,y = event.pos

                                        if(MSGTEXTRECT.collidepoint(x,y)):
                                                self.board = self.__getStartingBoardDS()
                                                pygame.draw.rect(SCREEN, GAMEBOARDCOLOR, GAMEBOARDCOORD, 0)
                                                reDraw = True
                                                self.__drawBoard(self.board, "", reDraw)
                                                gameOver = False
                                elif(event.type == pygame.MOUSEBUTTONUP and pygame.MOUSEMOTION and pygame.MOUSEBUTTONDOWN):
                                        #unpack the tuple
                                        x,y = event.pos
                                        movedToTile = self.__getSpotClicked(self.board, x, y)
                                        gameOver = self.__checkIfEmptyAndMove(clickedTile, movedToTile)
                                        if(gameOver):
                                                pygame.mixer.music.stop()
                                                pygame.mixer.music.load('gameover.mp3')
                                                pygame.mixer.music.play(0)
                                                reDraw = False
                                                self.__drawBoard(self.board, "Game Over. Continue?", reDraw)
                                elif(event.type ==  pygame.MOUSEBUTTONDOWN):
                                        if(gameOver):
                                                pygame.mixer.music.stop()
                                                pygame.mixer.music.load('background.mp3')
                                                pygame.mixer.music.play(-1)
                                        #set a boolean flag as to it was pressed and get the cell in which it happened
                                        x,y = event.pos
                                        clickedTile = self.__getSpotClicked(self.board, x, y)

                                #Update the screen
                                pygame.display.update()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号