Mercurial > rinkhals
comparison gamelib/gameboard.py @ 57:08665fa60345
Implement henhouses and henhouse adding.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Mon, 31 Aug 2009 18:34:10 +0000 |
parents | b8f64db0d39e |
children | e2631c8e2cd6 |
comparison
equal
deleted
inserted
replaced
56:205789321a46 | 57:08665fa60345 |
---|---|
3 from pgu import gui | 3 from pgu import gui |
4 | 4 |
5 import data | 5 import data |
6 import tiles | 6 import tiles |
7 import constants | 7 import constants |
8 import buildings | |
8 | 9 |
9 | 10 |
10 class OpaqueLabel(gui.Label): | 11 class OpaqueLabel(gui.Label): |
11 def paint(self, s): | 12 def paint(self, s): |
12 s.fill(self.style.background) | 13 s.fill(self.style.background) |
83 self.create_disp() | 84 self.create_disp() |
84 | 85 |
85 self.selected_tool = None | 86 self.selected_tool = None |
86 self.chickens = [] | 87 self.chickens = [] |
87 self.foxes = [] | 88 self.foxes = [] |
89 self.henhouses = [] | |
88 self.cash = 0 | 90 self.cash = 0 |
89 self.add_cash(constants.STARTING_CASH) | 91 self.add_cash(constants.STARTING_CASH) |
90 | 92 |
91 def create_disp(self): | 93 def create_disp(self): |
92 width, height = pygame.display.get_surface().get_size() | 94 width, height = pygame.display.get_surface().get_size() |
113 self.selected_tool = tool | 115 self.selected_tool = tool |
114 | 116 |
115 def use_tool(self, e): | 117 def use_tool(self, e): |
116 if self.selected_tool == constants.TOOL_SELL_CHICKEN: | 118 if self.selected_tool == constants.TOOL_SELL_CHICKEN: |
117 self.sell_chicken(e.pos) | 119 self.sell_chicken(e.pos) |
118 if self.selected_tool == constants.TOOL_SELL_EGG: | 120 elif self.selected_tool == constants.TOOL_SELL_EGG: |
119 pass | 121 pass |
120 if self.selected_tool == constants.TOOL_BUY_FENCE: | 122 elif self.selected_tool == constants.TOOL_BUY_FENCE: |
121 self.buy_fence(self.tv.screen_to_tile(e.pos)) | 123 self.buy_fence(self.tv.screen_to_tile(e.pos)) |
122 if self.selected_tool == constants.TOOL_BUY_HENHOUSE: | 124 elif self.selected_tool == constants.TOOL_BUY_HENHOUSE: |
123 pass | 125 self.buy_henhouse(self.tv.screen_to_tile(e.pos)) |
124 | 126 |
125 def get_chicken(self, pos): | 127 def get_chicken(self, pos): |
126 for chick in self.chickens: | 128 for chick in self.chickens: |
127 if chick.rect.collidepoint(pos): | 129 if chick.rect.collidepoint(pos): |
128 return chick | 130 return chick |
129 return None | 131 return None |
130 | 132 |
131 def sell_chicken(self, pos): | 133 def sell_chicken(self, pos): |
132 chick = self.get_chicken(pos) | 134 chick = self.get_chicken(pos) |
133 if chick is None: | 135 if chick is None: |
134 return | 136 return |
135 if len(self.chickens) == 1: | 137 if len(self.chickens) == 1: |
144 if self.cash < constants.BUY_PRICE_FENCE: | 146 if self.cash < constants.BUY_PRICE_FENCE: |
145 print "You can't afford a fence." | 147 print "You can't afford a fence." |
146 return | 148 return |
147 self.add_cash(-constants.BUY_PRICE_FENCE) | 149 self.add_cash(-constants.BUY_PRICE_FENCE) |
148 self.tv.set(tile_pos, tiles.REVERSE_TILE_MAP['fence']) | 150 self.tv.set(tile_pos, tiles.REVERSE_TILE_MAP['fence']) |
151 | |
152 def buy_henhouse(self, tile_pos): | |
153 if self.cash < constants.BUY_PRICE_HENHOUSE: | |
154 return | |
155 henhouse = buildings.HenHouse(tile_pos) | |
156 if henhouse.place(self.tv): | |
157 self.add_cash(-constants.BUY_PRICE_HENHOUSE) | |
158 self.add_henhouse(henhouse) | |
149 | 159 |
150 def event(self, e): | 160 def event(self, e): |
151 if e.type == KEYDOWN: | 161 if e.type == KEYDOWN: |
152 if e.key == K_UP: | 162 if e.key == K_UP: |
153 self.tvw.move_view(0, -self.TILE_DIMENSIONS[1]) | 163 self.tvw.move_view(0, -self.TILE_DIMENSIONS[1]) |
175 | 185 |
176 def add_fox(self, fox): | 186 def add_fox(self, fox): |
177 self.foxes.append(fox) | 187 self.foxes.append(fox) |
178 self.tv.sprites.append(fox) | 188 self.tv.sprites.append(fox) |
179 | 189 |
190 def add_henhouse(self, henhouse): | |
191 self.henhouses.append(henhouse) | |
192 self.tv.sprites.append(henhouse) | |
193 | |
180 def remove_fox(self, fox): | 194 def remove_fox(self, fox): |
181 if fox in self.foxes: | 195 if fox in self.foxes: |
182 self.foxes.remove(fox) | 196 self.foxes.remove(fox) |
183 self.tv.sprites.remove(fox) | 197 self.tv.sprites.remove(fox) |
184 | 198 |