comparison gamelib/gamestate.py @ 80:a40a76012bd7

Refactor message handling so we can deal with in the gui
author Neil Muller <drnlmuller@gmail.com>
date Wed, 09 May 2012 12:08:44 +0200
parents 364ff3479ef2
children 59afe9f92383
comparison
equal deleted inserted replaced
79:8d1cf0cbe5e1 80:a40a76012bd7
3 3
4 """The actual game state object""" 4 """The actual game state object"""
5 5
6 from gamelib import missions, lab 6 from gamelib import missions, lab
7 from gamelib.game_base import get_subclasses 7 from gamelib.game_base import get_subclasses
8 from gamelib.constants import NEW_SCIENCE, NEW_SCHEMATIC
8 9
9 10
10 class Game(object): 11 class Game(object):
11 12
12 def __init__(self, init_data=None): 13 def __init__(self, init_data=None):
58 if self.points < 0: 59 if self.points < 0:
59 raise RuntimeError('Spent too many points') 60 raise RuntimeError('Spent too many points')
60 new_stuff = self.lab.spend_points(self.cur_allocation, self.points) 61 new_stuff = self.lab.spend_points(self.cur_allocation, self.points)
61 self.points = 0 62 self.points = 0
62 # Process mission results 63 # Process mission results
64 messages = []
63 for result in mission_results: 65 for result in mission_results:
64 result.apply(self) 66 result.apply(self)
67 messages.append((result.outcome, result.msg))
65 for science in new_stuff: 68 for science in new_stuff:
66 # FIXME: Update UI better. 69 # FIXME: Update UI better.
67 print "You learned new stuff:", science.NAME 70 if science.SCIENCE_TYPE == 'research':
71 messages.append((NEW_SCIENCE,
72 "You've started a new line of research in %s"
73 % science.NAME))
74 else:
75 messages.append((NEW_SCHEMATIC,
76 "You've developed blueprints for a %s" % science.NAME))
77 return messages
68 78
69 def save_data(self): 79 def save_data(self):
70 """Serialize the game state into a dict""" 80 """Serialize the game state into a dict"""
71 data = {} 81 data = {}
72 data['money'] = self.money 82 data['money'] = self.money