Mercurial > rinkhals
annotate gamelib/gameover.py @ 602:1b77bcbfb9e3 default tip
update tags
author | convert-repo |
---|---|
date | Thu, 19 May 2011 15:58:03 +0000 |
parents | a8dde729000a |
children |
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 |
564
fb8ab1ee3eaf
Use actual username in high scores.
Simon Cross <hodgestar@gmail.com>
parents:
562
diff
changeset
|
4 import getpass |
139 | 5 |
6 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
|
7 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
|
8 from pgu.high import Highs |
139 | 9 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
|
10 from pygame.locals import KEYDOWN, K_ESCAPE |
139 | 11 |
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(): | |
566
a8dde729000a
Add 'Save and Quit' option to quit dialog. Move game events from engine to constants to ease 'import engine' fun
Neil Muller <drnlmuller@gmail.com>
parents:
564
diff
changeset
|
90 pygame.event.post(constants.GO_MAIN_MENU) |
139 | 91 |
92 def quit_pressed(): | |
566
a8dde729000a
Add 'Save and Quit' option to quit dialog. Move game events from engine to constants to ease 'import engine' fun
Neil Muller <drnlmuller@gmail.com>
parents:
564
diff
changeset
|
93 pygame.event.post(constants.DO_QUIT) |
139 | 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 |
315
0a3161fec434
Check whether we've made the list before submitting the score
Neil Muller <drnlmuller@gmail.com>
parents:
312
diff
changeset
|
99 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
|
100 if level.is_game_over(gameboard): |
246
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
101 if len(gameboard.chickens) > 0: |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
102 self.survived = WON |
564
fb8ab1ee3eaf
Use actual username in high scores.
Simon Cross <hodgestar@gmail.com>
parents:
562
diff
changeset
|
103 try: |
fb8ab1ee3eaf
Use actual username in high scores.
Simon Cross <hodgestar@gmail.com>
parents:
562
diff
changeset
|
104 player = getpass.getuser() |
fb8ab1ee3eaf
Use actual username in high scores.
Simon Cross <hodgestar@gmail.com>
parents:
562
diff
changeset
|
105 except Exception: |
fb8ab1ee3eaf
Use actual username in high scores.
Simon Cross <hodgestar@gmail.com>
parents:
562
diff
changeset
|
106 player = 'You' |
fb8ab1ee3eaf
Use actual username in high scores.
Simon Cross <hodgestar@gmail.com>
parents:
562
diff
changeset
|
107 scoreboard.submit(score, player) |
246
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
108 message = random.choice(WON_MESSAGES) |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
109 else: |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
110 self.survived = LOST |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
111 message = random.choice(LOST_MESSAGES) |
139 | 112 else: |
246
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
113 self.survived = LEFT |
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
114 message = random.choice(LEFT_MESSAGES) |
562
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
115 |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
116 self.tr() |
246
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
117 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
|
118 colspan=3) |
296
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
119 self.add_spacer() |
562
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
120 |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
121 # heading options |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
122 head_kwargs = { |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
123 'color': constants.FG_COLOR, |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
124 'style': { |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
125 'padding_top': 10, |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
126 'padding_bottom': 5, |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
127 }, |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
128 } |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
129 |
229
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
130 # show the scoreboard |
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
131 |
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
|
132 self.tr() |
562
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
133 self.td(html.HTML('<b>High Scores for Level<i>%s:</i></b>' |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
134 % level.level_name, **head_kwargs), |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
135 colspan=3) |
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
|
136 |
229
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
137 for highscore in scoreboard: |
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
138 self.tr() |
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
139 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
|
140 self.td(gui.Label('%d' % highscore.score, color=constants.FG_COLOR)) |
139 | 141 |
562
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
142 # show player score |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
143 |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
144 self.tr() |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
145 self.td(html.HTML('<b>Your Score:</b>', **head_kwargs), colspan=3) |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
146 |
139 | 147 self.tr() |
148 self.td(gui.Label("Groats : %d" % gameboard.cash, | |
149 color=constants.FG_COLOR)) | |
150 self.td(gui.Label(" Chickens : %d " % len(gameboard.chickens), | |
151 color=constants.FG_COLOR)) | |
152 self.td(gui.Label(" Eggs : %d" % gameboard.eggs, | |
153 color=constants.FG_COLOR)) | |
296
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
154 self.add_spacer() |
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
155 self.tr() |
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
156 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
|
157 color=constants.FG_COLOR), colspan=3) |
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
158 self.add_spacer() |
139 | 159 self.tr() |
229
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
160 self.td(gui.Label("Final score : %d" % score, |
139 | 161 color=constants.FG_COLOR), colspan=3) |
562
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
162 |
315
0a3161fec434
Check whether we've made the list before submitting the score
Neil Muller <drnlmuller@gmail.com>
parents:
312
diff
changeset
|
163 if made_list: |
229
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
164 self.tr() |
246
592bfad67488
Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
165 if self.survived == WON: |
562
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
166 msg = "You made the high scores!" |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
167 scoreboard.save() |
229
96d440bebdaa
Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents:
159
diff
changeset
|
168 else: |
562
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
169 msg = "Pity, you could have made the high scores." |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
170 self.td(html.HTML("<b>%s</b>" % msg, **head_kwargs) |
80725d647569
Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents:
560
diff
changeset
|
171 , colspan=3) |
139 | 172 |
296
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
173 self.add_spacer(50) |
157
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
174 |
139 | 175 return_button = gui.Button("Return to Main Menu") |
176 return_button.connect(gui.CLICK, return_pressed) | |
177 | |
178 quit_button = gui.Button("Quit") | |
179 quit_button.connect(gui.CLICK, quit_pressed) | |
180 | |
181 style = { | |
182 "padding_bottom": 15, | |
183 } | |
184 td_kwargs = { | |
185 "align": 0, | |
186 "style": style, | |
187 "colspan": 3, | |
188 } | |
189 | |
190 self.tr() | |
191 self.td(return_button, **td_kwargs) | |
192 | |
193 self.tr() | |
194 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
|
195 |
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
196 def add_spacer(self, height=5): |
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
197 self.tr() |
010ab166c582
Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents:
295
diff
changeset
|
198 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
|
199 |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
200 |
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
|
201 class ScoreDialog(gui.Dialog): |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
202 |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
203 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
|
204 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
|
205 % level.level_name) |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
206 scoreboard = ScoreTable(level) |
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
207 |
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
|
208 tbl = gui.Table() |
555
296c73dcd286
Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents:
392
diff
changeset
|
209 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
|
210 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
|
211 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
|
212 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
|
213 |
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
|
214 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
|
215 |
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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 return gui.Dialog.event(self, e) |