Mercurial > rinkhals
comparison gamelib/gameover.py @ 246:592bfad67488
Add 'You left' game over mode
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 05 Sep 2009 12:27:08 +0000 |
parents | 96d440bebdaa |
children | d037e37c5240 |
comparison
equal
deleted
inserted
replaced
245:634491bf37e8 | 246:592bfad67488 |
---|---|
1 """The Game Over Screen""" | 1 """The Game Over Screen""" |
2 import tempfile | 2 import tempfile |
3 import random | |
3 | 4 |
4 from pgu import gui | 5 from pgu import gui |
5 from pgu.high import High | 6 from pgu.high import High |
6 import pygame | 7 import pygame |
7 | 8 |
8 import engine | 9 import engine |
9 import constants | 10 import constants |
10 import imagecache | 11 import imagecache |
12 | |
13 WON, LOST, LEFT = range(3) | |
14 | |
15 LOST_MESSAGES = ["You lost", 'You failed to protect yur chickens'] | |
16 WON_MESSAGES = ["You survived"] | |
17 LEFT_MESSAGES = ["You sold your farm", "You gave up", | |
18 "Real life got in the way"] | |
11 | 19 |
12 def ScoreTable(): | 20 def ScoreTable(): |
13 """Create and initialise a score table""" | 21 """Create and initialise a score table""" |
14 # We need a true file, so load will work, but, as we never save, | 22 # We need a true file, so load will work, but, as we never save, |
15 # the deletion doesn't bother us. | 23 # the deletion doesn't bother us. |
25 | 33 |
26 class GameOverContainer(gui.Container): | 34 class GameOverContainer(gui.Container): |
27 def __init__(self, game_over, *args, **kwargs): | 35 def __init__(self, game_over, *args, **kwargs): |
28 gui.Container.__init__(self, *args, **kwargs) | 36 gui.Container.__init__(self, *args, **kwargs) |
29 self.add(game_over, 0, 0) | 37 self.add(game_over, 0, 0) |
30 if game_over.survived: | 38 if game_over.survived == WON: |
31 self.splash = imagecache.load_image("images/gameover_win.png", ["darken_center"]) | 39 self.splash = imagecache.load_image("images/gameover_win.png", |
40 ["darken_center"]) | |
41 elif game_over.survived == LOST: | |
42 self.splash = imagecache.load_image("images/gameover_lose.png", | |
43 ["darken_center"]) | |
32 else: | 44 else: |
33 self.splash = imagecache.load_image("images/gameover_lose.png", ["darken_center"]) | 45 self.splash = imagecache.load_image("images/splash.png", |
46 ["darken_center"]) | |
34 | 47 |
35 def paint(self, s): | 48 def paint(self, s): |
36 pygame.display.set_caption('Game Over') | 49 pygame.display.set_caption('Game Over') |
37 pygame.display.get_surface().blit(self.splash, (0, 0)) | 50 pygame.display.get_surface().blit(self.splash, (0, 0)) |
38 gui.Container.paint(self, s) | 51 gui.Container.paint(self, s) |
39 | 52 |
40 class GameOver(gui.Table): | 53 class GameOver(gui.Table): |
54 | |
41 def __init__(self, gameboard, scoreboard, **params): | 55 def __init__(self, gameboard, scoreboard, **params): |
42 gui.Table.__init__(self, **params) | 56 gui.Table.__init__(self, **params) |
43 | 57 |
44 def return_pressed(): | 58 def return_pressed(): |
45 pygame.event.post(engine.GO_MAIN_MENU) | 59 pygame.event.post(engine.GO_MAIN_MENU) |
46 | 60 |
47 def quit_pressed(): | 61 def quit_pressed(): |
48 pygame.event.post(engine.QUIT) | 62 pygame.event.post(engine.QUIT) |
49 | 63 |
50 | |
51 score = gameboard.cash + \ | 64 score = gameboard.cash + \ |
52 constants.SELL_PRICE_CHICKEN * len(gameboard.chickens) + \ | 65 constants.SELL_PRICE_CHICKEN * len(gameboard.chickens) + \ |
53 constants.SELL_PRICE_EGG * gameboard.eggs | 66 constants.SELL_PRICE_EGG * gameboard.eggs |
54 | 67 |
55 self.tr() | 68 self.tr() |
56 if len(gameboard.chickens) > 0: | 69 if gameboard.is_game_over(): |
57 self.survived = True | 70 if len(gameboard.chickens) > 0: |
58 self.td(gui.Label("You Survived", color=constants.FG_COLOR), | 71 self.survived = WON |
59 colspan=3) | 72 scoreboard.submit(score, 'Player') |
60 scoreboard.submit(score, 'Player') | 73 message = random.choice(WON_MESSAGES) |
74 else: | |
75 self.survived = LOST | |
76 message = random.choice(LOST_MESSAGES) | |
61 else: | 77 else: |
62 self.survived = False | 78 self.survived = LEFT |
63 self.td(gui.Label("You Lost", color=constants.FG_COLOR), | 79 message = random.choice(LEFT_MESSAGES) |
64 colspan=3) | 80 self.td(gui.Label(message, color=constants.FG_COLOR), |
81 colspan=3) | |
65 # show the scoreboard | 82 # show the scoreboard |
66 | 83 |
67 for highscore in scoreboard: | 84 for highscore in scoreboard: |
68 self.tr() | 85 self.tr() |
69 self.td(gui.Label(highscore.name, color=constants.FG_COLOR), colspan=2) | 86 self.td(gui.Label(highscore.name, color=constants.FG_COLOR), colspan=2) |
79 self.tr() | 96 self.tr() |
80 self.td(gui.Label("Final score : %d" % score, | 97 self.td(gui.Label("Final score : %d" % score, |
81 color=constants.FG_COLOR), colspan=3) | 98 color=constants.FG_COLOR), colspan=3) |
82 if scoreboard.check(score) is not None: | 99 if scoreboard.check(score) is not None: |
83 self.tr() | 100 self.tr() |
84 if self.survived: | 101 if self.survived == WON: |
85 self.td(gui.Label("You made the high scores", | 102 self.td(gui.Label("You made the high scores", |
86 color=constants.FG_COLOR), colspan=3) | 103 color=constants.FG_COLOR), colspan=3) |
87 else: | 104 else: |
88 self.td(gui.Label("Pity, you could have made the high scores", | 105 self.td(gui.Label("Pity, you could have made the high scores", |
89 color=constants.FG_COLOR), colspan=3) | 106 color=constants.FG_COLOR), colspan=3) |