comparison gamelib/gamestate.py @ 25:27570aca5d17

Fix some stupid bugs
author Neil Muller <drnlmuller@gmail.com>
date Sun, 06 May 2012 19:21:06 +0200
parents f6a3b213857b
children 4d9610c59efa
comparison
equal deleted inserted replaced
24:23720d0fd9a0 25:27570aca5d17
33 self.cur_missions = [] 33 self.cur_missions = []
34 self.cur_allocation = [] 34 self.cur_allocation = []
35 35
36 def get_available_equipment(self): 36 def get_available_equipment(self):
37 """Return a list of equipment we can produce and afford""" 37 """Return a list of equipment we can produce and afford"""
38 available = [x for x in lab.science 38 available = [x for x in self.lab.science
39 if isinstance(x, products.Product) and x.COST <= self.money] 39 if isinstance(x, products.Product) and x.COST <= self.money]
40 return available 40 return available
41 41
42 def end_turn(self): 42 def end_turn(self):
43 # Attempt the missions 43 # Attempt the missions
44 mission_results = [] 44 mission_results = []
45 for mission, equipment in self.cur_missions: 45 for mission, equipment in self.cur_missions:
46 mission_results.appned(mission.attempt(equipment, self)) 46 mission_results.append(mission.attempt(equipment, self))
47 if not mission.available:
48 # Mission no longer available, so we clean up
49 self.missions.remove(mission)
47 # Do the science 50 # Do the science
48 self.points -= len(self.cur_allocation) 51 self.points -= len(self.cur_allocation)
49 if self.points < 0: 52 if self.points < 0:
50 raise RuntimeError('Spent too many points') 53 raise RuntimeError('Spent too many points')
51 new_stuff = self.lab.spend_points(self.cur_allocation, self.points) 54 new_stuff = self.lab.spend_points(self.cur_allocation, self.points)
52 # Process mission results 55 # Process mission results
53 for result in mission_results: 56 for result in mission_results:
54 result.apply(self) 57 result.apply(self)
55 # Update the science state with result of spend_points
56 for science in new_stuff: 58 for science in new_stuff:
57 # FIXME: Update UI better. 59 # FIXME: Update UI better.
58 print "You learned new stuff:", science.NAME 60 print "You learned new stuff:", science.NAME
59 61
60 def save_data(self): 62 def save_data(self):