# HG changeset patch # User Neil Muller # Date 1252107613 0 # Node ID 96d440bebdaa2809b140cae0ec48d132b9f4b850 # Parent f74de4280e20bba3a546b71be56428a4100c0f4b Non-permenant high score table diff -r f74de4280e20 -r 96d440bebdaa gamelib/engine.py --- a/gamelib/engine.py Fri Sep 04 23:32:32 2009 +0000 +++ b/gamelib/engine.py Fri Sep 04 23:40:13 2009 +0000 @@ -1,5 +1,4 @@ """Game engine and states.""" - from pgu.engine import Game, State, Quit import pygame from pygame.locals import USEREVENT, QUIT, KEYDOWN, K_ESCAPE, K_n, K_d, K_s, K_i @@ -17,6 +16,7 @@ self.clock = pygame.time.Clock() self.main_menu = mainmenu.make_main_menu() self._open_window = None + self.scoreboard = gameover.ScoreTable() def tick(self): """Tic toc.""" @@ -45,7 +45,7 @@ def create_game_over(self): """Create and open the Game Over window""" - game_over = gameover.create_game_over(self.gameboard) + game_over = gameover.create_game_over(self.gameboard, self.scoreboard) self.open_window(game_over) class MainMenuState(State): diff -r f74de4280e20 -r 96d440bebdaa gamelib/gameover.py --- a/gamelib/gameover.py Fri Sep 04 23:32:32 2009 +0000 +++ b/gamelib/gameover.py Fri Sep 04 23:40:13 2009 +0000 @@ -1,15 +1,26 @@ """The Game Over Screen""" +import tempfile from pgu import gui +from pgu.high import High import pygame import engine import constants import imagecache -def create_game_over(gameboard): +def ScoreTable(): + """Create and initialise a score table""" + # We need a true file, so load will work, but, as we never save, + # the deletion doesn't bother us. + our_scores = High(tempfile.NamedTemporaryFile(), 4) + for score in range(700,1000,100): + our_scores.submit(score, 'No-one', None) + return our_scores + +def create_game_over(gameboard, scores): """Create a game over screen""" - game_over = GameOver(gameboard) + game_over = GameOver(gameboard, scores) return GameOverContainer(game_over, align=0, valign=0) class GameOverContainer(gui.Container): @@ -27,9 +38,8 @@ gui.Container.paint(self, s) class GameOver(gui.Table): - def __init__(self, gameboard, **params): + def __init__(self, gameboard, scoreboard, **params): gui.Table.__init__(self, **params) - self.tr() def return_pressed(): pygame.event.post(engine.GO_MAIN_MENU) @@ -37,14 +47,27 @@ def quit_pressed(): pygame.event.post(engine.QUIT) + + score = gameboard.cash + \ + constants.SELL_PRICE_CHICKEN * len(gameboard.chickens) + \ + constants.SELL_PRICE_EGG * gameboard.eggs + + self.tr() if len(gameboard.chickens) > 0: self.survived = True self.td(gui.Label("You Survived", color=constants.FG_COLOR), colspan=3) + scoreboard.submit(score, 'Player') else: self.survived = False self.td(gui.Label("You Lost", color=constants.FG_COLOR), colspan=3) + # show the scoreboard + + for highscore in scoreboard: + self.tr() + self.td(gui.Label(highscore.name, color=constants.FG_COLOR), colspan=2) + self.td(gui.Label('%d' % highscore.score, color=constants.FG_COLOR)) self.tr() self.td(gui.Label("Groats : %d" % gameboard.cash, @@ -54,10 +77,16 @@ self.td(gui.Label(" Eggs : %d" % gameboard.eggs, color=constants.FG_COLOR)) self.tr() - self.td(gui.Label("Final score : %d" % (gameboard.cash + - constants.SELL_PRICE_CHICKEN * len(gameboard.chickens) + - constants.SELL_PRICE_EGG * gameboard.eggs), + self.td(gui.Label("Final score : %d" % score, color=constants.FG_COLOR), colspan=3) + if scoreboard.check(score) is not None: + self.tr() + if self.survived: + self.td(gui.Label("You made the high scores", + color=constants.FG_COLOR), colspan=3) + else: + self.td(gui.Label("Pity, you could have made the high scores", + color=constants.FG_COLOR), colspan=3) self.tr() self.td(gui.Spacer(0, 50), colspan=3)