Example #1
0
    def highScoreScreen(self):

        # update pygame frame
        pygame.display.update()

        # GUI display
        self.window.fill(self.colors["gray1"])
        self.text("High Scores", self.window_w / 2, 50, "Impact", 48, self.colors["white"], "center")  
        self.displayButton(self.buttons["high_scores_back"])

        hs = highscores.HighScores().outputData()

        for i in range(len(hs)):
            name, score = hs[i]
            self.text(str(i + 1) + ") " + name, 100, i * 28 + 100, "Impact", 18, self.colors["white"], "left") 
            self.text(str(score), 265, i * 28 + 100, "Impact", 18, self.colors["white"], "left") 

        self.displayButton(self.buttons["help_back"]) 

        # event handling
        for event in pygame.event.get():
            # check if the user clicked the mouse
            if (event.type == pygame.MOUSEBUTTONDOWN):
                # get mouse x and y coordinates
                mousePosition = pygame.mouse.get_pos()
                mouseX = mousePosition[0]
                mouseY = mousePosition[1]

                # change screen
                if (self.buttons["high_scores_back"].mouseOver(mouseX, mouseY)):
                    self.screen = "main_menu_screen"

            # allow the user to exit the window
            if (event.type == pygame.QUIT):
                self.openWindow = False
Example #2
0
 def reason(self):
     keys = pygame.key.get_pressed()
     if keys[K_ESCAPE]:
         self.level_manager.current_state.exit()
         return title.Title()
     if self.player.pos_y > self.display.get_height():
         if Game.streak_counter > 1:
             Game.score += 5 * (Game.streak_counter * 2)
         self.level_manager.current_state.exit()
         return highscores.HighScores(Game.score)
Example #3
0
    def winScreen(self):

        # update pygame frame
        pygame.display.update()

        # GUI display
        self.window.fill(self.colors["gray1"])
        self.displayBoard(self.game_board.board, self.tile_w, self.tile_h,
                          self.num_rows, self.num_cols)
        font = pygame.font.SysFont("Impact", 48)
        self.text("You Win!", self.window_w / 2, 50, "Impact", 48,
                  self.colors["white"], "center")
        self.displayButton(self.buttons["play-again-w"])

        pygame.draw.rect(self.window, self.colors["gray2"], [20, 115, 360, 50])
        self.text("Score: " + str(self.score), 25, 125, "Impact", 25,
                  self.colors["white"], "left")

        pygame.draw.rect(self.window, self.colors["gray2"], [20, 190, 360, 50])
        self.text("Enter a name: " + self.name, 25, 200, "Impact", 25,
                  self.colors["white"], "left")

        # event handling
        for event in pygame.event.get():

            if (event.type == pygame.KEYDOWN):
                if (event.key == 8):
                    self.name = self.name[:-1]
                else:
                    self.name += chr(event.key)

            # check if the user clicked the mouse
            if (event.type == pygame.MOUSEBUTTONDOWN):
                # get mouse x and y coordinates
                mousePosition = pygame.mouse.get_pos()
                mouseX = mousePosition[0]
                mouseY = mousePosition[1]

                # change screen
                if (self.buttons["play-again-w"].mouseOver(mouseX, mouseY)):
                    # add score to JSON file
                    hs = highscores.HighScores().addData(self.name, self.score)
                    self.screen = "main_menu_screen"
                    self.firstTurn = True

            # allow the user to exit the window
            elif (event.type == pygame.QUIT):
                self.openWindow = False
Example #4
0
def loop():
    interval = 0

    clock = PT.Clock()
    current = PT.get_ticks()

    while Globals.RUNNING:

        new = PT.get_ticks()
        elapsed = (new - current) / 1000.0
        current = new
        clock.tick()

        # figure out timestep
        # for physics only
        if Globals.STATE == "Title" and Globals.CURRENTSTATE != "Title":
            Globals.CURRENTSTATE = "Title"
            state = title.Title()
        elif Globals.STATE == "Menu" and Globals.CURRENTSTATE != "Menu":
            Globals.CURRENTSTATE = "Menu"
            state = Menu.Menu()
        elif Globals.STATE == "Game" and Globals.CURRENTSTATE != "Game":
            Globals.CURRENTSTATE = "Game"
            Globals.SCORE = 0
            state = Game.Game()
        elif Globals.STATE == "Score" and Globals.CURRENTSTATE != "Score":
            Globals.CURRENTSTATE = "Score"
            state = Score.HighScores()
        elif Globals.STATE == "Quit" and Globals.CURRENTSTATE != "Quit":
            Globals.CURRENTSTATE = "Quit"
            Globals.RUNNING = False

        state.update()
        interval += elapsed

        while interval > .02:
            # print elapsed
            Globals.DELTA = elapsed

            state.render()

            event = PE.get()
            if event:
                state.event(event)

            interval -= .02
Example #5
0
        #
        # Dialog layout
        #
        okbutton = QPushButton('&OK')
        self.connect(okbutton, SIGNAL('clicked()'), self, SLOT('accept()'))
        
        bbox = QHBoxLayout()
        bbox.addStretch()
        bbox.addWidget(okbutton)
        bbox.addStretch()
        
        layout = QVBoxLayout()
        layout.addWidget(frame)
        layout.addLayout(bbox)
        self.setLayout(layout)
        

if __name__ == "__main__":
    import sys
    import highscores
    
    FILENAME = 'pyqtris_highscores'
    ds = highscores.HighScores(10) 
    
    ds.load_from_file(FILENAME)

    app = QApplication(sys.argv)
    dialog = HighscoresDialog(ds.get_list())
    dialog.exec_()