annotate gamelib/gameover.py @ 564:fb8ab1ee3eaf

Use actual username in high scores.
author Simon Cross <hodgestar@gmail.com>
date Sat, 28 Nov 2009 19:15:25 +0000
parents 80725d647569
children a8dde729000a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
139
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
5
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
11
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
12 import engine
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
13 import constants
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
14 import imagecache
555
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
15 import config
139
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
16
246
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
17 WON, LOST, LEFT = range(3)
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
18
295
d037e37c5240 Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents: 246
diff changeset
19 WON_MESSAGES = [
d037e37c5240 Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents: 246
diff changeset
20 "You won.",
d037e37c5240 Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents: 246
diff changeset
21 "You survived!",
d037e37c5240 Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents: 246
diff changeset
22 "Your chickens will one day rule the world.",
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
d037e37c5240 Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents: 246
diff changeset
25 LOST_MESSAGES = [
d037e37c5240 Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents: 246
diff changeset
26 "You lost.",
d037e37c5240 Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents: 246
diff changeset
27 "You failed to protect your chickens.",
d037e37c5240 Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents: 246
diff changeset
28 "Unopposed, the foxes overrun the farm.",
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
d037e37c5240 Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents: 246
diff changeset
31 LEFT_MESSAGES = [
d037e37c5240 Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents: 246
diff changeset
32 "You gave up.",
d037e37c5240 Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents: 246
diff changeset
33 "You sold your farm.",
d037e37c5240 Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents: 246
diff changeset
34 "Real life got in the way.",
d037e37c5240 Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents: 246
diff changeset
35 "Are you siding with the foxes?",
d037e37c5240 Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents: 246
diff changeset
36 "What will your chickens do now?",
d037e37c5240 Some endgame message changes.
Jeremy Thurgood <firxen@gmail.com>
parents: 246
diff changeset
37 ]
246
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
38
389
463802281182 Add basic level support (level choosing needs work)
Neil Muller <drnlmuller@gmail.com>
parents: 315
diff changeset
39 def ScoreTable(level):
229
96d440bebdaa Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents: 159
diff changeset
40 """Create and initialise a score table"""
555
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
41 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
42 all_scores = Highs(score_path, 4)
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
43 all_scores.load()
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
44 level_scores = all_scores[level.level_name]
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
45
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
46 if not list(level_scores):
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
47 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
48 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
49 random.shuffle(scores)
229
96d440bebdaa Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents: 159
diff changeset
50
555
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
51 for auth, score in zip(authors, scores):
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
52 level_scores.submit(score, auth, None)
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
53
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
54 level_scores.save()
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
55
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
56 return level_scores
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
57
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
58 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
59 """Create a game over screen"""
555
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
60 game_over = GameOver(gameboard, level)
157
e3572b907028 Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents: 151
diff changeset
61 return GameOverContainer(game_over, align=0, valign=0)
139
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
62
555
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
63
139
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
64 class GameOverContainer(gui.Container):
157
e3572b907028 Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents: 151
diff changeset
65 def __init__(self, game_over, *args, **kwargs):
e3572b907028 Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents: 151
diff changeset
66 gui.Container.__init__(self, *args, **kwargs)
e3572b907028 Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents: 151
diff changeset
67 self.add(game_over, 0, 0)
246
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
68 if game_over.survived == WON:
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
69 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
70 ["darken_center"])
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
71 elif game_over.survived == LOST:
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
72 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
73 ["darken_center"])
157
e3572b907028 Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents: 151
diff changeset
74 else:
246
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
75 self.splash = imagecache.load_image("images/splash.png",
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
76 ["darken_center"])
157
e3572b907028 Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents: 151
diff changeset
77
139
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
78 def paint(self, s):
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
79 pygame.display.set_caption('Game Over')
157
e3572b907028 Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents: 151
diff changeset
80 pygame.display.get_surface().blit(self.splash, (0, 0))
139
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
81 gui.Container.paint(self, s)
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
82
555
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
83
139
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
84 class GameOver(gui.Table):
246
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
85
555
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
86 def __init__(self, gameboard, level, **params):
139
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
87 gui.Table.__init__(self, **params)
555
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
88 scoreboard = ScoreTable(level)
139
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
89
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
90 def return_pressed():
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
91 pygame.event.post(engine.GO_MAIN_MENU)
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
92
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
93 def quit_pressed():
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
94 pygame.event.post(engine.QUIT)
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
95
229
96d440bebdaa Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents: 159
diff changeset
96 score = gameboard.cash + \
389
463802281182 Add basic level support (level choosing needs work)
Neil Muller <drnlmuller@gmail.com>
parents: 315
diff changeset
97 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
98 level.sell_price_egg * gameboard.eggs
229
96d440bebdaa Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents: 159
diff changeset
99
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
564
fb8ab1ee3eaf Use actual username in high scores.
Simon Cross <hodgestar@gmail.com>
parents: 562
diff changeset
104 try:
fb8ab1ee3eaf Use actual username in high scores.
Simon Cross <hodgestar@gmail.com>
parents: 562
diff changeset
105 player = getpass.getuser()
fb8ab1ee3eaf Use actual username in high scores.
Simon Cross <hodgestar@gmail.com>
parents: 562
diff changeset
106 except Exception:
fb8ab1ee3eaf Use actual username in high scores.
Simon Cross <hodgestar@gmail.com>
parents: 562
diff changeset
107 player = 'You'
fb8ab1ee3eaf Use actual username in high scores.
Simon Cross <hodgestar@gmail.com>
parents: 562
diff changeset
108 scoreboard.submit(score, player)
246
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
109 message = random.choice(WON_MESSAGES)
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
110 else:
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
111 self.survived = LOST
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
112 message = random.choice(LOST_MESSAGES)
139
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
113 else:
246
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
114 self.survived = LEFT
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
115 message = random.choice(LEFT_MESSAGES)
562
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
116
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
117 self.tr()
246
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
118 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
119 colspan=3)
296
010ab166c582 Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents: 295
diff changeset
120 self.add_spacer()
562
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
121
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
122 # heading options
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
123 head_kwargs = {
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
124 'color': constants.FG_COLOR,
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
125 'style': {
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
126 'padding_top': 10,
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
127 'padding_bottom': 5,
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 }
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
130
229
96d440bebdaa Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents: 159
diff changeset
131 # show the scoreboard
96d440bebdaa Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents: 159
diff changeset
132
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
133 self.tr()
562
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
134 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
135 % level.level_name, **head_kwargs),
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
136 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
137
229
96d440bebdaa Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents: 159
diff changeset
138 for highscore in scoreboard:
96d440bebdaa Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents: 159
diff changeset
139 self.tr()
96d440bebdaa Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents: 159
diff changeset
140 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
141 self.td(gui.Label('%d' % highscore.score, color=constants.FG_COLOR))
139
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
142
562
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
143 # show player score
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
144
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
145 self.tr()
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
146 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
147
139
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
148 self.tr()
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
149 self.td(gui.Label("Groats : %d" % gameboard.cash,
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
150 color=constants.FG_COLOR))
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
151 self.td(gui.Label(" Chickens : %d " % len(gameboard.chickens),
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
152 color=constants.FG_COLOR))
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
153 self.td(gui.Label(" Eggs : %d" % gameboard.eggs,
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
154 color=constants.FG_COLOR))
296
010ab166c582 Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents: 295
diff changeset
155 self.add_spacer()
010ab166c582 Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents: 295
diff changeset
156 self.tr()
010ab166c582 Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents: 295
diff changeset
157 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
158 color=constants.FG_COLOR), colspan=3)
010ab166c582 Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents: 295
diff changeset
159 self.add_spacer()
139
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
160 self.tr()
229
96d440bebdaa Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents: 159
diff changeset
161 self.td(gui.Label("Final score : %d" % score,
139
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
162 color=constants.FG_COLOR), colspan=3)
562
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
163
315
0a3161fec434 Check whether we've made the list before submitting the score
Neil Muller <drnlmuller@gmail.com>
parents: 312
diff changeset
164 if made_list:
229
96d440bebdaa Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents: 159
diff changeset
165 self.tr()
246
592bfad67488 Add 'You left' game over mode
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
166 if self.survived == WON:
562
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
167 msg = "You made the high scores!"
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
168 scoreboard.save()
229
96d440bebdaa Non-permenant high score table
Neil Muller <drnlmuller@gmail.com>
parents: 159
diff changeset
169 else:
562
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
170 msg = "Pity, you could have made the high scores."
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
171 self.td(html.HTML("<b>%s</b>" % msg, **head_kwargs)
80725d647569 Neaten up gameover screen.
Simon Cross <hodgestar@gmail.com>
parents: 560
diff changeset
172 , colspan=3)
139
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
173
296
010ab166c582 Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents: 295
diff changeset
174 self.add_spacer(50)
157
e3572b907028 Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents: 151
diff changeset
175
139
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
176 return_button = gui.Button("Return to Main Menu")
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
177 return_button.connect(gui.CLICK, return_pressed)
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
178
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
179 quit_button = gui.Button("Quit")
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
180 quit_button.connect(gui.CLICK, quit_pressed)
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
181
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
182 style = {
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
183 "padding_bottom": 15,
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
184 }
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
185 td_kwargs = {
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
186 "align": 0,
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
187 "style": style,
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
188 "colspan": 3,
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
189 }
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
190
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
191 self.tr()
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
192 self.td(return_button, **td_kwargs)
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
193
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
194 self.tr()
1d73de63bd71 Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
195 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
196
010ab166c582 Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents: 295
diff changeset
197 def add_spacer(self, height=5):
010ab166c582 Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents: 295
diff changeset
198 self.tr()
010ab166c582 Add killed fox count to gameover. Tweak spacing
Neil Muller <drnlmuller@gmail.com>
parents: 295
diff changeset
199 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
200
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
201
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
202 class ScoreDialog(gui.Dialog):
555
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
203
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
204 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
205 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
206 % level.level_name)
555
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
207 scoreboard = ScoreTable(level)
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
208
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
209 tbl = gui.Table()
555
296c73dcd286 Add high score dialog to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 392
diff changeset
210 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
211 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
212 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
213 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
214
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
215 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
216
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
217 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
218 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
219 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
220 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
221 return gui.Dialog.event(self, e)