# HG changeset patch # User Neil Muller # Date 1252175451 0 # Node ID dd1ffee5ccf53be75a7b5c5c35af83d5dab0c24f # Parent 245ee075f2aea53cf9c1d35a42432fc3fdfd7523 Use different score tables fot the different modes. Refactor game modes code as a result diff -r 245ee075f2ae -r dd1ffee5ccf5 TODO --- a/TODO Sat Sep 05 18:08:17 2009 +0000 +++ b/TODO Sat Sep 05 18:30:51 2009 +0000 @@ -6,8 +6,8 @@ * Py2app packaging (jerith) -* Sell equipment from chickens in buildings (Neil) - - Display bug with multiple equipment to be resolved +* Show game mode in gameboard + - Warn at days - 1? == POST PYWEEK == diff -r 245ee075f2ae -r dd1ffee5ccf5 gamelib/constants.py --- a/gamelib/constants.py Sat Sep 05 18:08:17 2009 +0000 +++ b/gamelib/constants.py Sat Sep 05 18:30:51 2009 +0000 @@ -45,4 +45,11 @@ TOOL_SELL_EQUIPMENT = 7 NIGHT_LENGTH = 150 -TURN_LIMIT = 14 + +TURN_LIMITS = { + 'Two weeks' : 14, + 'Three months' : 90, + 'Unlimited' : 0, + } + +TURN_LIMIT = TURN_LIMITS['Two weeks'] diff -r 245ee075f2ae -r dd1ffee5ccf5 gamelib/engine.py --- a/gamelib/engine.py Sat Sep 05 18:08:17 2009 +0000 +++ b/gamelib/engine.py Sat Sep 05 18:30:51 2009 +0000 @@ -46,7 +46,10 @@ def create_game_over(self): """Create and open the Game Over window""" - game_over = gameover.create_game_over(self.gameboard, self.scoreboard) + for mode, days in constants.TURN_LIMITS.iteritems(): + if days == constants.TURN_LIMIT: + game_over = gameover.create_game_over(self.gameboard, + self.scoreboard[mode], mode) self.gameboard = None self.open_window(game_over) diff -r 245ee075f2ae -r dd1ffee5ccf5 gamelib/gameover.py --- a/gamelib/gameover.py Sat Sep 05 18:08:17 2009 +0000 +++ b/gamelib/gameover.py Sat Sep 05 18:30:51 2009 +0000 @@ -3,7 +3,7 @@ import random from pgu import gui -from pgu.high import High +from pgu.high import Highs import pygame import engine @@ -36,14 +36,15 @@ """Create and initialise a score table""" # We need a true file, so load will work, but, as we never save, # the deletion doesn't bother us. - our_scores = High(tempfile.NamedTemporaryFile(), 4) - for score in range(700,1000,100): - our_scores.submit(score, 'No-one', None) + our_scores = Highs(tempfile.NamedTemporaryFile(), 4) + for mode in constants.TURN_LIMITS: + for score in range(700,1000,100): + our_scores[mode].submit(score, 'No-one', None) return our_scores -def create_game_over(gameboard, scores): +def create_game_over(gameboard, scores, mode): """Create a game over screen""" - game_over = GameOver(gameboard, scores) + game_over = GameOver(gameboard, scores, mode) return GameOverContainer(game_over, align=0, valign=0) class GameOverContainer(gui.Container): @@ -67,7 +68,7 @@ class GameOver(gui.Table): - def __init__(self, gameboard, scoreboard, **params): + def __init__(self, gameboard, scoreboard, mode, **params): gui.Table.__init__(self, **params) def return_pressed(): @@ -97,6 +98,10 @@ self.add_spacer() # show the scoreboard + self.tr() + self.td(gui.Label('Game Mode: %s' % mode, color=constants.FG_COLOR), + colspan=3) + for highscore in scoreboard: self.tr() self.td(gui.Label(highscore.name, color=constants.FG_COLOR), colspan=2) diff -r 245ee075f2ae -r dd1ffee5ccf5 gamelib/mainmenu.py --- a/gamelib/mainmenu.py Sat Sep 05 18:08:17 2009 +0000 +++ b/gamelib/mainmenu.py Sat Sep 05 18:30:51 2009 +0000 @@ -32,29 +32,26 @@ def quit_pressed(): pygame.event.post(engine.QUIT) - def fortnight_pressed(): - constants.TURN_LIMIT = 14 - pygame.event.post(engine.START_DAY) - - def quarter_pressed(): - constants.TURN_LIMIT = 90 - pygame.event.post(engine.START_DAY) - - def unlimited_pressed(): - constants.TURN_LIMIT = 0 + def start_game(mode): + constants.TURN_LIMIT = constants.TURN_LIMITS[mode] pygame.event.post(engine.START_DAY) def help_pressed(): pygame.event.post(engine.GO_HELP_SCREEN) - fortnight_button = gui.Button("Two weeks") - fortnight_button.connect(gui.CLICK, fortnight_pressed) - - quarter_button = gui.Button("Three months") - quarter_button.connect(gui.CLICK, quarter_pressed) - - unlim_button = gui.Button("Unlimited") - unlim_button.connect(gui.CLICK, unlimited_pressed) + style = { + "padding_bottom": 15, + } + td_kwargs = { + "align": 0, + "style": style, + } + + for mode in constants.TURN_LIMITS: + button = gui.Button(mode) + button.connect(gui.CLICK, start_game, mode) + self.tr() + self.td(button, **td_kwargs) quit_button = gui.Button("Quit") quit_button.connect(gui.CLICK, quit_pressed) @@ -65,23 +62,6 @@ fullscreen_toggle = gui.Button("Toggle Fullscreen") fullscreen_toggle.connect(gui.CLICK, fullscreen_toggled) - style = { - "padding_bottom": 15, - } - td_kwargs = { - "align": 0, - "style": style, - } - - self.tr() - self.td(fortnight_button, **td_kwargs) - - self.tr() - self.td(quarter_button, **td_kwargs) - - self.tr() - self.td(unlim_button, **td_kwargs) - self.tr() self.td(help_button, **td_kwargs)