Mercurial > rinkhals
changeset 246:592bfad67488
Add 'You left' game over mode
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 05 Sep 2009 12:27:08 +0000 |
parents | 634491bf37e8 |
children | 5b9cd693fe7c |
files | TODO gamelib/gameover.py |
diffstat | 2 files changed, 30 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/TODO Sat Sep 05 12:15:46 2009 +0000 +++ b/TODO Sat Sep 05 12:27:08 2009 +0000 @@ -19,7 +19,6 @@ * <Nitwit> And we need to start testing for lose conditions, and set an upper time limit -- High score needs finishing - -- Should esc take us to a different state than won / lost? -- Think about length of game (i.e. number of days)
--- a/gamelib/gameover.py Sat Sep 05 12:15:46 2009 +0000 +++ b/gamelib/gameover.py Sat Sep 05 12:27:08 2009 +0000 @@ -1,5 +1,6 @@ """The Game Over Screen""" import tempfile +import random from pgu import gui from pgu.high import High @@ -9,6 +10,13 @@ import constants import imagecache +WON, LOST, LEFT = range(3) + +LOST_MESSAGES = ["You lost", 'You failed to protect yur chickens'] +WON_MESSAGES = ["You survived"] +LEFT_MESSAGES = ["You sold your farm", "You gave up", + "Real life got in the way"] + def ScoreTable(): """Create and initialise a score table""" # We need a true file, so load will work, but, as we never save, @@ -27,10 +35,15 @@ def __init__(self, game_over, *args, **kwargs): gui.Container.__init__(self, *args, **kwargs) self.add(game_over, 0, 0) - if game_over.survived: - self.splash = imagecache.load_image("images/gameover_win.png", ["darken_center"]) + if game_over.survived == WON: + self.splash = imagecache.load_image("images/gameover_win.png", + ["darken_center"]) + elif game_over.survived == LOST: + self.splash = imagecache.load_image("images/gameover_lose.png", + ["darken_center"]) else: - self.splash = imagecache.load_image("images/gameover_lose.png", ["darken_center"]) + self.splash = imagecache.load_image("images/splash.png", + ["darken_center"]) def paint(self, s): pygame.display.set_caption('Game Over') @@ -38,6 +51,7 @@ gui.Container.paint(self, s) class GameOver(gui.Table): + def __init__(self, gameboard, scoreboard, **params): gui.Table.__init__(self, **params) @@ -47,21 +61,24 @@ def quit_pressed(): pygame.event.post(engine.QUIT) - score = gameboard.cash + \ constants.SELL_PRICE_CHICKEN * len(gameboard.chickens) + \ constants.SELL_PRICE_EGG * gameboard.eggs self.tr() - if len(gameboard.chickens) > 0: - self.survived = True - self.td(gui.Label("You Survived", color=constants.FG_COLOR), - colspan=3) - scoreboard.submit(score, 'Player') + if gameboard.is_game_over(): + if len(gameboard.chickens) > 0: + self.survived = WON + scoreboard.submit(score, 'Player') + message = random.choice(WON_MESSAGES) + else: + self.survived = LOST + message = random.choice(LOST_MESSAGES) else: - self.survived = False - self.td(gui.Label("You Lost", color=constants.FG_COLOR), - colspan=3) + self.survived = LEFT + message = random.choice(LEFT_MESSAGES) + self.td(gui.Label(message, color=constants.FG_COLOR), + colspan=3) # show the scoreboard for highscore in scoreboard: @@ -81,7 +98,7 @@ color=constants.FG_COLOR), colspan=3) if scoreboard.check(score) is not None: self.tr() - if self.survived: + if self.survived == WON: self.td(gui.Label("You made the high scores", color=constants.FG_COLOR), colspan=3) else: