Mercurial > rinkhals
annotate gamelib/gameover.py @ 560:8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sat, 28 Nov 2009 18:27:59 +0000 |
parents | 296c73dcd286 |
children | 80725d647569 |
rev | line source |
---|---|
139 | 1 """The Game Over Screen""" |
246
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
2 import random |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
3 import os |
139 | 4 |
5 from pgu import gui | |
560
8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
Simon Cross <hodgestar@gmail.com>
parents:
555
diff
changeset
|
6 from pgu import html |
312
dd1ffee5ccf5
Use different score tables fot the different modes. Refactor game modes code as a result
Neil Muller <drnlmuller@gmail.com>
parents:
296
diff
changeset
|
7 from pgu.high import Highs |
139 | 8 import pygame |
560
8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
Simon Cross <hodgestar@gmail.com>
parents:
555
diff
changeset
|
9 from pygame.locals import KEYDOWN, K_ESCAPE |
139 | 10 |
11 import engine | |
12 import constants | |
13 import imagecache | |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
14 import config |
139 | 15 |
246
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
16 WON, LOST, LEFT = range(3) |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
17 |
295
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
18 WON_MESSAGES = [ |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
19 "You won.", |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
20 "You survived!", |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
21 "Your chickens will one day rule the world.", |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
22 ] |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
23 |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
24 LOST_MESSAGES = [ |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
25 "You lost.", |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
26 "You failed to protect your chickens.", |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
27 "Unopposed, the foxes overrun the farm.", |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
28 ] |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
29 |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
30 LEFT_MESSAGES = [ |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
31 "You gave up.", |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
32 "You sold your farm.", |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
33 "Real life got in the way.", |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
34 "Are you siding with the foxes?", |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
35 "What will your chickens do now?", |
d037e37c5240
Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
246
diff
changeset
|
36 ] |
246
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
37 |
389
463802281182
Add basic level support (level choosing needs work)
Neil Muller <drnlmuller@gmail.com>
parents:
315
diff
changeset
|
38 def ScoreTable(level): |
229
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
39 """Create and initialise a score table""" |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
40 score_path = os.path.join(config.config.prefs_folder, "highscores.dat") |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
41 all_scores = Highs(score_path, 4) |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
42 all_scores.load() |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
43 level_scores = all_scores[level.level_name] |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
44 |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
45 if not list(level_scores): |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
46 authors = [auth[2] for auth in constants.AUTHORS] |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
47 scores = [700+i*100 for i in range(len(authors))] |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
48 random.shuffle(scores) |
229
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
49 |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
50 for auth, score in zip(authors, scores): |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
51 level_scores.submit(score, auth, None) |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
52 |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
53 level_scores.save() |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
54 |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
55 return level_scores |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
56 |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
57 def create_game_over(gameboard, level): |
151
082868bea873
Refactor UI so that only a single gui.App is used. Pass all UI events via main_app. Change Toolbar table to use .td() everywhere. Move toolbar to top.
Simon Cross <hodgestar@gmail.com>
parents:
139
diff
changeset
|
58 """Create a game over screen""" |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
59 game_over = GameOver(gameboard, level) |
157
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
60 return GameOverContainer(game_over, align=0, valign=0) |
139 | 61 |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
62 |
139 | 63 class GameOverContainer(gui.Container): |
157
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
64 def __init__(self, game_over, *args, **kwargs): |
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
65 gui.Container.__init__(self, *args, **kwargs) |
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
66 self.add(game_over, 0, 0) |
246
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
67 if game_over.survived == WON: |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
68 self.splash = imagecache.load_image("images/gameover_win.png", |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
69 ["darken_center"]) |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
70 elif game_over.survived == LOST: |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
71 self.splash = imagecache.load_image("images/gameover_lose.png", |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
72 ["darken_center"]) |
157
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
73 else: |
246
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
74 self.splash = imagecache.load_image("images/splash.png", |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
75 ["darken_center"]) |
157
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
76 |
139 | 77 def paint(self, s): |
78 pygame.display.set_caption('Game Over') | |
157
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
79 pygame.display.get_surface().blit(self.splash, (0, 0)) |
139 | 80 gui.Container.paint(self, s) |
81 | |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
82 |
139 | 83 class GameOver(gui.Table): |
246
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
84 |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
85 def __init__(self, gameboard, level, **params): |
139 | 86 gui.Table.__init__(self, **params) |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
87 scoreboard = ScoreTable(level) |
139 | 88 |
89 def return_pressed(): | |
90 pygame.event.post(engine.GO_MAIN_MENU) | |
91 | |
92 def quit_pressed(): | |
93 pygame.event.post(engine.QUIT) | |
94 | |
229
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
95 score = gameboard.cash + \ |
389
463802281182
Add basic level support (level choosing needs work)
Neil Muller <drnlmuller@gmail.com>
parents:
315
diff
changeset
|
96 level.sell_price_chicken * len(gameboard.chickens) + \ |
463802281182
Add basic level support (level choosing needs work)
Neil Muller <drnlmuller@gmail.com>
parents:
315
diff
changeset
|
97 level.sell_price_egg * gameboard.eggs |
229
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
98 |
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
99 self.tr() |
315
0a3161fec434
Check whether we've made the list before submitting the score
Neil Muller <drnlmuller@gmail.com>
parents:
312
diff
changeset
|
100 made_list = scoreboard.check(score) is not None |
392
bb75979b58e6
Move game_over logic from gameboard to level, for later reworking
Neil Muller <drnlmuller@gmail.com>
parents:
389
diff
changeset
|
101 if level.is_game_over(gameboard): |
246
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
102 if len(gameboard.chickens) > 0: |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
103 self.survived = WON |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
104 scoreboard.submit(score, 'Player') |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
105 message = random.choice(WON_MESSAGES) |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
106 else: |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
107 self.survived = LOST |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
108 message = random.choice(LOST_MESSAGES) |
139 | 109 else: |
246
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
110 self.survived = LEFT |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
111 message = random.choice(LEFT_MESSAGES) |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
112 self.td(gui.Label(message, color=constants.FG_COLOR), |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
113 colspan=3) |
296
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
114 self.add_spacer() |
229
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
115 # show the scoreboard |
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
116 |
312
dd1ffee5ccf5
Use different score tables fot the different modes. Refactor game modes code as a result
Neil Muller <drnlmuller@gmail.com>
parents:
296
diff
changeset
|
117 self.tr() |
389
463802281182
Add basic level support (level choosing needs work)
Neil Muller <drnlmuller@gmail.com>
parents:
315
diff
changeset
|
118 self.td(gui.Label('Level: %s' % level.level_name, color=constants.FG_COLOR), |
312
dd1ffee5ccf5
Use different score tables fot the different modes. Refactor game modes code as a result
Neil Muller <drnlmuller@gmail.com>
parents:
296
diff
changeset
|
119 colspan=3) |
dd1ffee5ccf5
Use different score tables fot the different modes. Refactor game modes code as a result
Neil Muller <drnlmuller@gmail.com>
parents:
296
diff
changeset
|
120 |
229
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
121 for highscore in scoreboard: |
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
122 self.tr() |
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
123 self.td(gui.Label(highscore.name, color=constants.FG_COLOR), colspan=2) |
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
124 self.td(gui.Label('%d' % highscore.score, color=constants.FG_COLOR)) |
139 | 125 |
126 self.tr() | |
127 self.td(gui.Label("Groats : %d" % gameboard.cash, | |
128 color=constants.FG_COLOR)) | |
129 self.td(gui.Label(" Chickens : %d " % len(gameboard.chickens), | |
130 color=constants.FG_COLOR)) | |
131 self.td(gui.Label(" Eggs : %d" % gameboard.eggs, | |
132 color=constants.FG_COLOR)) | |
296
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
133 self.add_spacer() |
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
134 self.tr() |
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
135 self.td(gui.Label("You killed %d foxes" % gameboard.killed_foxes, |
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
136 color=constants.FG_COLOR), colspan=3) |
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
137 self.add_spacer() |
139 | 138 self.tr() |
229
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
139 self.td(gui.Label("Final score : %d" % score, |
139 | 140 color=constants.FG_COLOR), colspan=3) |
315
0a3161fec434
Check whether we've made the list before submitting the score
Neil Muller <drnlmuller@gmail.com>
parents:
312
diff
changeset
|
141 if made_list: |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
142 scoreboard.save() |
229
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
143 self.tr() |
246
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
144 if self.survived == WON: |
229
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
145 self.td(gui.Label("You made the high scores", |
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
146 color=constants.FG_COLOR), colspan=3) |
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
147 else: |
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
148 self.td(gui.Label("Pity, you could have made the high scores", |
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
149 color=constants.FG_COLOR), colspan=3) |
139 | 150 |
296
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
151 self.add_spacer(50) |
157
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
152 |
139 | 153 return_button = gui.Button("Return to Main Menu") |
154 return_button.connect(gui.CLICK, return_pressed) | |
155 | |
156 quit_button = gui.Button("Quit") | |
157 quit_button.connect(gui.CLICK, quit_pressed) | |
158 | |
159 style = { | |
160 "padding_bottom": 15, | |
161 } | |
162 td_kwargs = { | |
163 "align": 0, | |
164 "style": style, | |
165 "colspan": 3, | |
166 } | |
167 | |
168 self.tr() | |
169 self.td(return_button, **td_kwargs) | |
170 | |
171 self.tr() | |
172 self.td(quit_button, **td_kwargs) | |
296
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
173 |
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
174 def add_spacer(self, height=5): |
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
175 self.tr() |
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
176 self.td(gui.Spacer(0, height), colspan=3) |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
177 |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
178 |
560
8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
Simon Cross <hodgestar@gmail.com>
parents:
555
diff
changeset
|
179 class ScoreDialog(gui.Dialog): |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
180 |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
181 def __init__(self, level, **params): |
560
8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
Simon Cross <hodgestar@gmail.com>
parents:
555
diff
changeset
|
182 title = html.HTML("<b>High Scores for Level<i>%s</i></b>" |
8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
Simon Cross <hodgestar@gmail.com>
parents:
555
diff
changeset
|
183 % level.level_name) |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
184 scoreboard = ScoreTable(level) |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
185 |
560
8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
Simon Cross <hodgestar@gmail.com>
parents:
555
diff
changeset
|
186 tbl = gui.Table() |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
187 for highscore in scoreboard: |
560
8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
Simon Cross <hodgestar@gmail.com>
parents:
555
diff
changeset
|
188 tbl.tr() |
8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
Simon Cross <hodgestar@gmail.com>
parents:
555
diff
changeset
|
189 tbl.td(gui.Label(highscore.name), colspan=2) |
8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
Simon Cross <hodgestar@gmail.com>
parents:
555
diff
changeset
|
190 tbl.td(gui.Label('%d' % highscore.score)) |
8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
Simon Cross <hodgestar@gmail.com>
parents:
555
diff
changeset
|
191 |
8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
Simon Cross <hodgestar@gmail.com>
parents:
555
diff
changeset
|
192 gui.Dialog.__init__(self, title, tbl, **params) |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
193 |
560
8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
Simon Cross <hodgestar@gmail.com>
parents:
555
diff
changeset
|
194 def event(self, e): |
8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
Simon Cross <hodgestar@gmail.com>
parents:
555
diff
changeset
|
195 if e.type == KEYDOWN and e.key == K_ESCAPE: |
8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
Simon Cross <hodgestar@gmail.com>
parents:
555
diff
changeset
|
196 self.close() |
8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
Simon Cross <hodgestar@gmail.com>
parents:
555
diff
changeset
|
197 return True |
8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
Simon Cross <hodgestar@gmail.com>
parents:
555
diff
changeset
|
198 return gui.Dialog.event(self, e) |