Mercurial > rinkhals
comparison gamelib/gameover.py @ 229:96d440bebdaa
Non-permenant high score table
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Fri, 04 Sep 2009 23:40:13 +0000 |
parents | 7bb8d9d6858a |
children | 592bfad67488 |
comparison
equal
deleted
inserted
replaced
228:f74de4280e20 | 229:96d440bebdaa |
---|---|
1 """The Game Over Screen""" | 1 """The Game Over Screen""" |
2 import tempfile | |
2 | 3 |
3 from pgu import gui | 4 from pgu import gui |
5 from pgu.high import High | |
4 import pygame | 6 import pygame |
5 | 7 |
6 import engine | 8 import engine |
7 import constants | 9 import constants |
8 import imagecache | 10 import imagecache |
9 | 11 |
10 def create_game_over(gameboard): | 12 def 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 | |
21 def create_game_over(gameboard, scores): | |
11 """Create a game over screen""" | 22 """Create a game over screen""" |
12 game_over = GameOver(gameboard) | 23 game_over = GameOver(gameboard, scores) |
13 return GameOverContainer(game_over, align=0, valign=0) | 24 return GameOverContainer(game_over, align=0, valign=0) |
14 | 25 |
15 class GameOverContainer(gui.Container): | 26 class GameOverContainer(gui.Container): |
16 def __init__(self, game_over, *args, **kwargs): | 27 def __init__(self, game_over, *args, **kwargs): |
17 gui.Container.__init__(self, *args, **kwargs) | 28 gui.Container.__init__(self, *args, **kwargs) |
25 pygame.display.set_caption('Game Over') | 36 pygame.display.set_caption('Game Over') |
26 pygame.display.get_surface().blit(self.splash, (0, 0)) | 37 pygame.display.get_surface().blit(self.splash, (0, 0)) |
27 gui.Container.paint(self, s) | 38 gui.Container.paint(self, s) |
28 | 39 |
29 class GameOver(gui.Table): | 40 class GameOver(gui.Table): |
30 def __init__(self, gameboard, **params): | 41 def __init__(self, gameboard, scoreboard, **params): |
31 gui.Table.__init__(self, **params) | 42 gui.Table.__init__(self, **params) |
32 self.tr() | |
33 | 43 |
34 def return_pressed(): | 44 def return_pressed(): |
35 pygame.event.post(engine.GO_MAIN_MENU) | 45 pygame.event.post(engine.GO_MAIN_MENU) |
36 | 46 |
37 def quit_pressed(): | 47 def quit_pressed(): |
38 pygame.event.post(engine.QUIT) | 48 pygame.event.post(engine.QUIT) |
39 | 49 |
50 | |
51 score = gameboard.cash + \ | |
52 constants.SELL_PRICE_CHICKEN * len(gameboard.chickens) + \ | |
53 constants.SELL_PRICE_EGG * gameboard.eggs | |
54 | |
55 self.tr() | |
40 if len(gameboard.chickens) > 0: | 56 if len(gameboard.chickens) > 0: |
41 self.survived = True | 57 self.survived = True |
42 self.td(gui.Label("You Survived", color=constants.FG_COLOR), | 58 self.td(gui.Label("You Survived", color=constants.FG_COLOR), |
43 colspan=3) | 59 colspan=3) |
60 scoreboard.submit(score, 'Player') | |
44 else: | 61 else: |
45 self.survived = False | 62 self.survived = False |
46 self.td(gui.Label("You Lost", color=constants.FG_COLOR), | 63 self.td(gui.Label("You Lost", color=constants.FG_COLOR), |
47 colspan=3) | 64 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)) | |
48 | 71 |
49 self.tr() | 72 self.tr() |
50 self.td(gui.Label("Groats : %d" % gameboard.cash, | 73 self.td(gui.Label("Groats : %d" % gameboard.cash, |
51 color=constants.FG_COLOR)) | 74 color=constants.FG_COLOR)) |
52 self.td(gui.Label(" Chickens : %d " % len(gameboard.chickens), | 75 self.td(gui.Label(" Chickens : %d " % len(gameboard.chickens), |
53 color=constants.FG_COLOR)) | 76 color=constants.FG_COLOR)) |
54 self.td(gui.Label(" Eggs : %d" % gameboard.eggs, | 77 self.td(gui.Label(" Eggs : %d" % gameboard.eggs, |
55 color=constants.FG_COLOR)) | 78 color=constants.FG_COLOR)) |
56 self.tr() | 79 self.tr() |
57 self.td(gui.Label("Final score : %d" % (gameboard.cash + | 80 self.td(gui.Label("Final score : %d" % score, |
58 constants.SELL_PRICE_CHICKEN * len(gameboard.chickens) + | |
59 constants.SELL_PRICE_EGG * gameboard.eggs), | |
60 color=constants.FG_COLOR), colspan=3) | 81 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) | |
61 | 90 |
62 self.tr() | 91 self.tr() |
63 self.td(gui.Spacer(0, 50), colspan=3) | 92 self.td(gui.Spacer(0, 50), colspan=3) |
64 | 93 |
65 return_button = gui.Button("Return to Main Menu") | 94 return_button = gui.Button("Return to Main Menu") |