Mercurial > rinkhals
comparison gamelib/buildings.py @ 65:7e9c8ad06d32
Implement building selling.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Mon, 31 Aug 2009 20:44:00 +0000 |
parents | 99fbb652ce8d |
children | 437cbd856a03 |
comparison
equal
deleted
inserted
replaced
64:99fbb652ce8d | 65:7e9c8ad06d32 |
---|---|
16 self.night_image = imagecache.load_image(self.IMAGE, ('night',)) | 16 self.night_image = imagecache.load_image(self.IMAGE, ('night',)) |
17 self.pos = pos | 17 self.pos = pos |
18 self.size = self.SIZE | 18 self.size = self.SIZE |
19 self.tile_no = self.TILE_NO | 19 self.tile_no = self.TILE_NO |
20 self._buy_price = self.BUY_PRICE | 20 self._buy_price = self.BUY_PRICE |
21 self._sell_price = self.SELL_PRICE | |
21 | 22 |
22 # Create the building somewhere far off screen | 23 # Create the building somewhere far off screen |
23 Sprite.__init__(self, self.day_image, (-1000, -1000)) | 24 Sprite.__init__(self, self.day_image, (-1000, -1000)) |
24 | 25 |
25 def tile_positions(self): | 26 def tile_positions(self): |
45 | 46 |
46 def place(self, tv): | 47 def place(self, tv): |
47 """Check that the building can be placed at its current position | 48 """Check that the building can be placed at its current position |
48 and place it if possible. | 49 and place it if possible. |
49 """ | 50 """ |
50 xpos, ypos = self.pos | |
51 xsize, ysize = self.size | |
52 | |
53 # check that all spaces under the structure are grassland | 51 # check that all spaces under the structure are grassland |
54 for tile_pos in self.tile_positions(): | 52 for tile_pos in self.tile_positions(): |
55 if not tv.get(tile_pos) == self.GRASSLAND: | 53 if not tv.get(tile_pos) == self.GRASSLAND: |
56 return False | 54 return False |
57 | 55 |
59 for tile_pos in self.tile_positions(): | 57 for tile_pos in self.tile_positions(): |
60 tv.set(tile_pos, self.tile_no) | 58 tv.set(tile_pos, self.tile_no) |
61 | 59 |
62 return True | 60 return True |
63 | 61 |
62 def covers(self, tile_pos): | |
63 """Return True if build covers tile_pos, False otherwise.""" | |
64 xpos, ypos = self.pos | |
65 xsize, ysize = self.size | |
66 return (xpos <= tile_pos[0] < xpos + xsize) and \ | |
67 (ypos <= tile_pos[1] < ypos + ysize) | |
68 | |
69 def remove(self, tv): | |
70 """Remove the building from its current position.""" | |
71 # remove tile | |
72 for tile_pos in self.tile_positions(): | |
73 tv.set(tile_pos, self.GRASSLAND) | |
74 | |
64 def buy_price(self): | 75 def buy_price(self): |
65 return self._buy_price | 76 return self._buy_price |
77 | |
78 def sell_price(self): | |
79 return self._sell_price | |
66 | 80 |
67 def sun(self, sun_on): | 81 def sun(self, sun_on): |
68 if sun_on: | 82 if sun_on: |
69 self.setimage(self.day_image) | 83 self.setimage(self.day_image) |
70 else: | 84 else: |
74 class HenHouse(Building): | 88 class HenHouse(Building): |
75 """A HenHouse.""" | 89 """A HenHouse.""" |
76 | 90 |
77 TILE_NO = tiles.REVERSE_TILE_MAP['henhouse'] | 91 TILE_NO = tiles.REVERSE_TILE_MAP['henhouse'] |
78 BUY_PRICE = 100 | 92 BUY_PRICE = 100 |
93 SELL_PRICE = 90 | |
79 SIZE = (3, 2) | 94 SIZE = (3, 2) |
80 IMAGE = 'sprites/henhouse.png' | 95 IMAGE = 'sprites/henhouse.png' |
81 NAME = 'Hen House' | 96 NAME = 'Hen House' |
82 | 97 |
83 | 98 |
84 class GuardTower(Building): | 99 class GuardTower(Building): |
85 """A GuardTower.""" | 100 """A GuardTower.""" |
86 | 101 |
87 TILE_NO = tiles.REVERSE_TILE_MAP['guardtower'] | 102 TILE_NO = tiles.REVERSE_TILE_MAP['guardtower'] |
88 BUY_PRICE = 200 | 103 BUY_PRICE = 200 |
104 SELL_PRICE = 150 | |
89 SIZE = (2, 2) | 105 SIZE = (2, 2) |
90 IMAGE = 'sprites/watchtower.png' | 106 IMAGE = 'sprites/watchtower.png' |
91 NAME = 'Watch Tower' | 107 NAME = 'Watch Tower' |
92 | 108 |
93 def is_building(obj): | 109 def is_building(obj): |