Mercurial > rinkhals
changeset 66:edc15ce8fa30
Implement fence selling (a bit hackish, but fine for now).
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Mon, 31 Aug 2009 20:57:20 +0000 |
parents | 7e9c8ad06d32 |
children | 9171d9b9ab35 |
files | gamelib/constants.py gamelib/gameboard.py |
diffstat | 2 files changed, 15 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/gamelib/constants.py Mon Aug 31 20:44:00 2009 +0000 +++ b/gamelib/constants.py Mon Aug 31 20:57:20 2009 +0000 @@ -22,6 +22,7 @@ STARTING_CASH = 1000 SELL_PRICE_CHICKEN = 10 BUY_PRICE_FENCE = 50 +SELL_PRICE_FENCE = 25 TOOL_SELL_CHICKEN = 1 TOOL_SELL_EGG = 2
--- a/gamelib/gameboard.py Mon Aug 31 20:44:00 2009 +0000 +++ b/gamelib/gameboard.py Mon Aug 31 20:57:20 2009 +0000 @@ -78,6 +78,9 @@ TILE_DIMENSIONS = (20, 20) TOOLBAR_WIDTH = 140 + GRASSLAND = tiles.REVERSE_TILE_MAP['grassland'] + FENCE = tiles.REVERSE_TILE_MAP['fence'] + def __init__(self): self.tv = tiles.FarmVid() self.tv.tga_load_tiles(data.filepath('tiles.tga'), self.TILE_DIMENSIONS) @@ -145,13 +148,19 @@ self.remove_chicken(chick) def buy_fence(self, tile_pos): - if self.tv.get(tile_pos) != tiles.REVERSE_TILE_MAP['grassland']: + if self.tv.get(tile_pos) != self.GRASSLAND: return if self.cash < constants.BUY_PRICE_FENCE: print "You can't afford a fence." return self.add_cash(-constants.BUY_PRICE_FENCE) - self.tv.set(tile_pos, tiles.REVERSE_TILE_MAP['fence']) + self.tv.set(tile_pos, self.FENCE) + + def sell_fence(self, tile_pos): + if self.tv.get(tile_pos) != self.FENCE: + return + self.add_cash(constants.SELL_PRICE_FENCE) + self.tv.set(tile_pos, self.GRASSLAND) def buy_building(self, tile_pos, building_cls): building = building_cls(tile_pos) @@ -162,11 +171,14 @@ self.add_building(building) def sell_building(self, tile_pos): + if self.tv.get(tile_pos) == self.FENCE: + return self.sell_fence(tile_pos) for building in self.buildings: if building.covers(tile_pos): self.add_cash(building.sell_price()) building.remove(self.tv) self.remove_building(building) + break def event(self, e): if e.type == KEYDOWN: