comparison gamelib/gameboard.py @ 512:b112bcf4d435

Add restore game button to main menu.
author Simon Cross <hodgestar@gmail.com>
date Thu, 26 Nov 2009 23:36:20 +0000
parents 3b5717d742b2
children 55b95bb25ced
comparison
equal deleted inserted replaced
511:57f9077fb7fb 512:b112bcf4d435
295 chicken.start_night() 295 chicken.start_night()
296 self.toolbar.update_egg_counter(self.eggs) 296 self.toolbar.update_egg_counter(self.eggs)
297 self._cache_animal_positions() 297 self._cache_animal_positions()
298 298
299 def start_day(self): 299 def start_day(self):
300 if hasattr(self, '_skip_start_day'):
301 del self._skip_start_day
302 return
300 self.day, self.night = True, False 303 self.day, self.night = True, False
301 self.tv.sun(True) 304 self.tv.sun(True)
302 self.reset_states() 305 self.reset_states()
303 self.toolbar.start_day() 306 self.toolbar.start_day()
304 self._pos_cache.clear() 307 self._pos_cache.clear()
305 self.advance_day() 308 self.advance_day()
306 self.clear_foxes() 309 self.clear_foxes()
307 for chicken in self.chickens.copy(): 310 for chicken in self.chickens.copy():
308 chicken.start_day() 311 chicken.start_day()
309 self.redraw_counters() 312 self.redraw_counters()
313
314 def skip_next_start_day(self):
315 # used to skip the start of the day triggered after
316 # reloading a save game
317 self._skip_start_day = True
310 318
311 def in_bounds(self, pos): 319 def in_bounds(self, pos):
312 """Check if a position is within the game boundaries""" 320 """Check if a position is within the game boundaries"""
313 if pos.x < 0 or pos.y < 0: 321 if pos.x < 0 or pos.y < 0:
314 return False 322 return False
1057 def save_game(self): 1065 def save_game(self):
1058 # clear selected animals and tool states before saving 1066 # clear selected animals and tool states before saving
1059 self.reset_states() 1067 self.reset_states()
1060 return serializer.simplify(self) 1068 return serializer.simplify(self)
1061 1069
1062 def restore_game(self, data): 1070 @staticmethod
1063 if 'refid' not in data or 'class' not in data or data['class'] != self.__class__.__name__: 1071 def restore_game(gameboard):
1064 raise ValueError("Invalid save game.")
1065
1066 new_gameboard = serializer.unsimplify(data)
1067
1068 import engine 1072 import engine
1069 pygame.event.post(pygame.event.Event(engine.DO_LOAD_SAVEGAME, gameboard=new_gameboard)) 1073 pygame.event.post(pygame.event.Event(engine.DO_LOAD_SAVEGAME, gameboard=gameboard))
1070 1074
1071 1075
1072 class TextDialog(gui.Dialog): 1076 class TextDialog(gui.Dialog):
1073 def __init__(self, title, text, **params): 1077 def __init__(self, title, text, **params):
1074 title_label = gui.Label(title) 1078 title_label = gui.Label(title)