Mercurial > rinkhals
annotate gamelib/gameover.py @ 156:210fc1ea0516
Stop background music whenever state changes.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Thu, 03 Sep 2009 21:23:34 +0000 |
parents | 082868bea873 |
children | e3572b907028 |
rev | line source |
---|---|
139 | 1 """The Game Over Screen""" |
2 | |
3 from pgu import gui | |
4 import pygame | |
5 | |
6 import engine | |
7 import constants | |
8 import imagecache | |
9 | |
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
|
10 def create_game_over(gameboard): |
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
|
11 """Create a game over screen""" |
139 | 12 game_over = GameOver(gameboard) |
13 | |
14 c = GameOverContainer(align=0, valign=0) | |
15 c.add(game_over, 0, 0) | |
16 | |
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
|
17 return c |
139 | 18 |
19 class GameOverContainer(gui.Container): | |
20 def paint(self, s): | |
21 pygame.display.set_caption('Game Over') | |
22 #splash = imagecache.load_image("images/splash.png") | |
23 #pygame.display.get_surface().blit(splash, (0, 0)) | |
24 gui.Container.paint(self, s) | |
25 | |
26 class GameOver(gui.Table): | |
27 def __init__(self, gameboard, **params): | |
28 gui.Table.__init__(self, **params) | |
29 | |
30 def return_pressed(): | |
31 pygame.event.post(engine.GO_MAIN_MENU) | |
32 | |
33 def quit_pressed(): | |
34 pygame.event.post(engine.QUIT) | |
35 | |
36 if len(gameboard.chickens) > 0: | |
37 self.td(gui.Label("You Survived", color=constants.FG_COLOR), | |
38 colspan=3) | |
39 else: | |
40 self.td(gui.Label("You Lost", color=constants.FG_COLOR), | |
41 colspan=3) | |
42 | |
43 self.tr() | |
44 self.td(gui.Label("Groats : %d" % gameboard.cash, | |
45 color=constants.FG_COLOR)) | |
46 self.td(gui.Label(" Chickens : %d " % len(gameboard.chickens), | |
47 color=constants.FG_COLOR)) | |
48 self.td(gui.Label(" Eggs : %d" % gameboard.eggs, | |
49 color=constants.FG_COLOR)) | |
50 self.tr() | |
51 self.td(gui.Label("Final score : %d" % (gameboard.cash + | |
52 constants.SELL_PRICE_CHICKEN * len(gameboard.chickens) + | |
53 constants.SELL_PRICE_EGG * gameboard.eggs), | |
54 color=constants.FG_COLOR), colspan=3) | |
55 | |
56 return_button = gui.Button("Return to Main Menu") | |
57 return_button.connect(gui.CLICK, return_pressed) | |
58 | |
59 quit_button = gui.Button("Quit") | |
60 quit_button.connect(gui.CLICK, quit_pressed) | |
61 | |
62 style = { | |
63 "padding_bottom": 15, | |
64 } | |
65 td_kwargs = { | |
66 "align": 0, | |
67 "style": style, | |
68 "colspan": 3, | |
69 } | |
70 | |
71 self.tr() | |
72 self.td(return_button, **td_kwargs) | |
73 | |
74 self.tr() | |
75 self.td(quit_button, **td_kwargs) |