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
|
|
10 def add_game_over(app, gameboard):
|
|
11 """Add the game over menu to the app"""
|
|
12 for widget in app.widgets[:]:
|
|
13 app.remove(widget)
|
|
14 game_over = GameOver(gameboard)
|
|
15
|
|
16 c = GameOverContainer(align=0, valign=0)
|
|
17 c.add(game_over, 0, 0)
|
|
18
|
|
19 app.init(c)
|
|
20
|
|
21 class GameOverContainer(gui.Container):
|
|
22 def paint(self, s):
|
|
23 pygame.display.set_caption('Game Over')
|
|
24 #splash = imagecache.load_image("images/splash.png")
|
|
25 #pygame.display.get_surface().blit(splash, (0, 0))
|
|
26 gui.Container.paint(self, s)
|
|
27
|
|
28 class GameOver(gui.Table):
|
|
29 def __init__(self, gameboard, **params):
|
|
30 gui.Table.__init__(self, **params)
|
|
31
|
|
32 def return_pressed():
|
|
33 pygame.event.post(engine.GO_MAIN_MENU)
|
|
34
|
|
35 def quit_pressed():
|
|
36 pygame.event.post(engine.QUIT)
|
|
37
|
|
38 if len(gameboard.chickens) > 0:
|
|
39 self.td(gui.Label("You Survived", color=constants.FG_COLOR),
|
|
40 colspan=3)
|
|
41 else:
|
|
42 self.td(gui.Label("You Lost", color=constants.FG_COLOR),
|
|
43 colspan=3)
|
|
44
|
|
45 self.tr()
|
|
46 self.td(gui.Label("Groats : %d" % gameboard.cash,
|
|
47 color=constants.FG_COLOR))
|
|
48 self.td(gui.Label(" Chickens : %d " % len(gameboard.chickens),
|
|
49 color=constants.FG_COLOR))
|
|
50 self.td(gui.Label(" Eggs : %d" % gameboard.eggs,
|
|
51 color=constants.FG_COLOR))
|
|
52 self.tr()
|
|
53 self.td(gui.Label("Final score : %d" % (gameboard.cash +
|
|
54 constants.SELL_PRICE_CHICKEN * len(gameboard.chickens) +
|
|
55 constants.SELL_PRICE_EGG * gameboard.eggs),
|
|
56 color=constants.FG_COLOR), colspan=3)
|
|
57
|
|
58 return_button = gui.Button("Return to Main Menu")
|
|
59 return_button.connect(gui.CLICK, return_pressed)
|
|
60
|
|
61 quit_button = gui.Button("Quit")
|
|
62 quit_button.connect(gui.CLICK, quit_pressed)
|
|
63
|
|
64 style = {
|
|
65 "padding_bottom": 15,
|
|
66 }
|
|
67 td_kwargs = {
|
|
68 "align": 0,
|
|
69 "style": style,
|
|
70 "colspan": 3,
|
|
71 }
|
|
72
|
|
73 self.tr()
|
|
74 self.td(return_button, **td_kwargs)
|
|
75
|
|
76 self.tr()
|
|
77 self.td(quit_button, **td_kwargs)
|