# HG changeset patch # User Simon Cross # Date 1251752240 0 # Node ID edc15ce8fa30d36cc47ef919a5f16456bebf7c49 # Parent 7e9c8ad06d32305acf7306ba109d8bafe3e9dcb1 Implement fence selling (a bit hackish, but fine for now). diff -r 7e9c8ad06d32 -r edc15ce8fa30 gamelib/constants.py --- 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 diff -r 7e9c8ad06d32 -r edc15ce8fa30 gamelib/gameboard.py --- 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: