Mercurial > sypikslang
comparison gamelib/gamestate.py @ 124:685301e35f88
Add a minion cost to missions
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Thu, 10 May 2012 12:16:15 +0200 |
parents | 4a44d133ad2e |
children | 8f717b2b3378 |
comparison
equal
deleted
inserted
replaced
123:7cd716328a44 | 124:685301e35f88 |
---|---|
10 | 10 |
11 class Game(object): | 11 class Game(object): |
12 | 12 |
13 def __init__(self, init_data=None): | 13 def __init__(self, init_data=None): |
14 self.money = 1000 | 14 self.money = 1000 |
15 self.minions = 1 | |
15 self.milestone = "basement" | 16 self.milestone = "basement" |
16 # Will be updated on the next turn | 17 # Will be updated on the next turn |
17 self.points = 0 | 18 self.points = 0 |
18 self.reputation = 0 | 19 self.reputation = 0 |
19 self.turn = 0 | 20 self.turn = 0 |
32 self.missions.append(cls()) | 33 self.missions.append(cls()) |
33 | 34 |
34 def start_turn(self): | 35 def start_turn(self): |
35 # Make more flexible? | 36 # Make more flexible? |
36 self.points += 1 + M_VALS[self.milestone] * 2 | 37 self.points += 1 + M_VALS[self.milestone] * 2 |
38 self.minions += 1 + M_VALS[self.milestone] * 2 | |
37 self.turn += 1 | 39 self.turn += 1 |
38 self.cur_missions = [] | 40 self.cur_missions = [] |
39 self.cur_allocation = [] | 41 self.cur_allocation = [] |
40 | 42 |
41 def get_available_equipment(self): | 43 def get_available_equipment(self): |
67 self.points -= len(self.cur_allocation) | 69 self.points -= len(self.cur_allocation) |
68 if self.points < 0: | 70 if self.points < 0: |
69 raise RuntimeError('Spent too many points') | 71 raise RuntimeError('Spent too many points') |
70 new_stuff = self.lab.spend_points(self.cur_allocation, self.points) | 72 new_stuff = self.lab.spend_points(self.cur_allocation, self.points) |
71 self.points = 0 | 73 self.points = 0 |
74 self.minions = 0 | |
72 # Process mission results | 75 # Process mission results |
73 messages = [] | 76 messages = [] |
74 for result in mission_results: | 77 for result in mission_results: |
75 result.apply(self) | 78 result.apply(self) |
76 messages.append((result.outcome, result.message)) | 79 messages.append((result.outcome, result.message)) |
87 | 90 |
88 def save_data(self): | 91 def save_data(self): |
89 """Serialize the game state into a dict""" | 92 """Serialize the game state into a dict""" |
90 data = {} | 93 data = {} |
91 data['money'] = self.money | 94 data['money'] = self.money |
95 data['minions'] = self.minions | |
92 data['reputation'] = self.reputation | 96 data['reputation'] = self.reputation |
93 data['milestone'] = self.milestone | 97 data['milestone'] = self.milestone |
94 data['points'] = self.points | 98 data['points'] = self.points |
95 data['lab'] = self.lab.save_data() | 99 data['lab'] = self.lab.save_data() |
96 data['turn'] = self.turn | 100 data['turn'] = self.turn |
102 return data | 106 return data |
103 | 107 |
104 def _load_data(self, data): | 108 def _load_data(self, data): |
105 """Restore the game state""" | 109 """Restore the game state""" |
106 self.money = data['money'] | 110 self.money = data['money'] |
111 self.minions = data['minions'] | |
107 self.reputation = data['reputation'] | 112 self.reputation = data['reputation'] |
108 self.points = data['points'] | 113 self.points = data['points'] |
109 self.turn = data['turn'] | 114 self.turn = data['turn'] |
110 self.lab = lab.Lab(data['lab']) | 115 self.lab = lab.Lab(data['lab']) |
111 for mis_class in missions.Mission.__subclasses__(): | 116 for mis_class in missions.Mission.__subclasses__(): |