Changeset 229:96d440bebdaa


Ignore:
Timestamp:
Sep 4, 2009, 11:40:13 PM (11 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@230
Message:

Non-permenant high score table

Location:
gamelib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gamelib/engine.py

    r223 r229  
    11"""Game engine and states."""
    2 
    32from pgu.engine import Game, State, Quit
    43import pygame
     
    1817        self.main_menu = mainmenu.make_main_menu()
    1918        self._open_window = None
     19        self.scoreboard = gameover.ScoreTable()
    2020
    2121    def tick(self):
     
    4646    def create_game_over(self):
    4747        """Create and open the Game Over window"""
    48         game_over = gameover.create_game_over(self.gameboard)
     48        game_over = gameover.create_game_over(self.gameboard, self.scoreboard)
    4949        self.open_window(game_over)
    5050
  • gamelib/gameover.py

    r159 r229  
    11"""The Game Over Screen"""
     2import tempfile
    23
    34from pgu import gui
     5from pgu.high import High
    46import pygame
    57
     
    810import imagecache
    911
    10 def create_game_over(gameboard):
     12def ScoreTable():
     13    """Create and initialise a score table"""
     14    # We need a true file, so load will work, but, as we never save,
     15    # the deletion doesn't bother us.
     16    our_scores = High(tempfile.NamedTemporaryFile(), 4)
     17    for score in range(700,1000,100):
     18        our_scores.submit(score, 'No-one', None)
     19    return our_scores
     20
     21def create_game_over(gameboard, scores):
    1122    """Create a game over screen"""
    12     game_over = GameOver(gameboard)
     23    game_over = GameOver(gameboard, scores)
    1324    return GameOverContainer(game_over, align=0, valign=0)
    1425
     
    2839
    2940class GameOver(gui.Table):
    30     def __init__(self, gameboard, **params):
     41    def __init__(self, gameboard, scoreboard, **params):
    3142        gui.Table.__init__(self, **params)
    32         self.tr()
    3343
    3444        def return_pressed():
     
    3848            pygame.event.post(engine.QUIT)
    3949
     50
     51        score = gameboard.cash + \
     52                constants.SELL_PRICE_CHICKEN * len(gameboard.chickens) + \
     53                constants.SELL_PRICE_EGG * gameboard.eggs
     54
     55        self.tr()
    4056        if len(gameboard.chickens) > 0:
    4157            self.survived = True
    4258            self.td(gui.Label("You Survived", color=constants.FG_COLOR),
    4359                    colspan=3)
     60            scoreboard.submit(score, 'Player')
    4461        else:
    4562            self.survived = False
    4663            self.td(gui.Label("You Lost", color=constants.FG_COLOR),
    4764                    colspan=3)
     65        # show the scoreboard
     66
     67        for highscore in scoreboard:
     68            self.tr()
     69            self.td(gui.Label(highscore.name, color=constants.FG_COLOR), colspan=2)
     70            self.td(gui.Label('%d' % highscore.score, color=constants.FG_COLOR))
    4871
    4972        self.tr()
     
    5578            color=constants.FG_COLOR))
    5679        self.tr()
    57         self.td(gui.Label("Final score : %d" % (gameboard.cash +
    58             constants.SELL_PRICE_CHICKEN * len(gameboard.chickens) +
    59             constants.SELL_PRICE_EGG * gameboard.eggs),
     80        self.td(gui.Label("Final score : %d" % score,
    6081            color=constants.FG_COLOR), colspan=3)
     82        if scoreboard.check(score) is not None:
     83            self.tr()
     84            if self.survived:
     85                self.td(gui.Label("You made the high scores",
     86                    color=constants.FG_COLOR), colspan=3)
     87            else:
     88                self.td(gui.Label("Pity, you could have made the high scores",
     89                    color=constants.FG_COLOR), colspan=3)
    6190
    6291        self.tr()
Note: See TracChangeset for help on using the changeset viewer.