Changeset 54:b8f64db0d39e
- Timestamp:
- Aug 31, 2009, 5:56:13 PM (11 years ago)
- Branch:
- default
- Convert:
- svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@55
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gamelib/gameboard.py
r52 r54 115 115 def use_tool(self, e): 116 116 if self.selected_tool == constants.TOOL_SELL_CHICKEN: 117 for chick in self.chickens: 118 if chick.rect.collidepoint(e.pos): 119 if len(self.chickens) == 1: 120 print "Can't sell your last chicken!" 121 else: 122 self.add_cash(constants.SELL_PRICE_CHICKEN) 123 self.remove_chicken(chick) 124 break 117 self.sell_chicken(e.pos) 125 118 if self.selected_tool == constants.TOOL_SELL_EGG: 126 119 pass 127 120 if self.selected_tool == constants.TOOL_BUY_FENCE: 128 tile_pos = self.tv.screen_to_tile(e.pos) 129 if (self.cash >= constants.BUY_PRICE_FENCE and 130 self.tv.get(tile_pos) == tiles.REVERSE_TILE_MAP['grassland']): 131 self.add_cash(-constants.BUY_PRICE_FENCE) 132 self.tv.set(tile_pos, tiles.REVERSE_TILE_MAP['fence']) 121 self.buy_fence(self.tv.screen_to_tile(e.pos)) 133 122 if self.selected_tool == constants.TOOL_BUY_HENHOUSE: 134 123 pass 124 125 def get_chicken(self, pos): 126 for chick in self.chickens: 127 if chick.rect.collidepoint(pos): 128 return chick 129 return None 130 131 def sell_chicken(self, pos): 132 chick = self.get_chicken(pos) 133 if chick is None: 134 return 135 if len(self.chickens) == 1: 136 print "You can't sell your last chicken!" 137 return 138 self.add_cash(constants.SELL_PRICE_CHICKEN) 139 self.remove_chicken(chick) 140 141 def buy_fence(self, tile_pos): 142 if self.tv.get(tile_pos) != tiles.REVERSE_TILE_MAP['grassland']: 143 return 144 if self.cash < constants.BUY_PRICE_FENCE: 145 print "You can't afford a fence." 146 return 147 self.add_cash(-constants.BUY_PRICE_FENCE) 148 self.tv.set(tile_pos, tiles.REVERSE_TILE_MAP['fence']) 135 149 136 150 def event(self, e):
Note: See TracChangeset
for help on using the changeset viewer.