Mercurial > rinkhals
annotate gamelib/gameboard.py @ 64:99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Mon, 31 Aug 2009 20:25:11 +0000 |
parents | e2631c8e2cd6 |
children | 7e9c8ad06d32 |
rev | line source |
---|---|
35 | 1 import pygame |
39
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
2 from pygame.locals import MOUSEBUTTONDOWN, KEYDOWN, K_UP, K_DOWN, K_LEFT, K_RIGHT |
35 | 3 from pgu import gui |
9 | 4 |
5 import data | |
24
7584453f4944
Add support for PNG tiles.
Simon Cross <hodgestar@gmail.com>
parents:
17
diff
changeset
|
6 import tiles |
40
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
7 import constants |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
8 import buildings |
9 | 9 |
35 | 10 |
40
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
11 class OpaqueLabel(gui.Label): |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
12 def paint(self, s): |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
13 s.fill(self.style.background) |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
14 gui.Label.paint(self, s) |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
15 |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
16 def update_value(self, value): |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
17 self.value = value |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
18 self.style.width, self.style.height = self.font.size(self.value) |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
19 self.repaint() |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
20 |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
21 |
35 | 22 class ToolBar(gui.Table): |
23 def __init__(self, gameboard, **params): | |
24 gui.Table.__init__(self, **params) | |
25 self.gameboard = gameboard | |
40
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
26 self.cash_counter = OpaqueLabel("Groats: ", color=constants.FG_COLOR) |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
27 self.tr() |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
28 self.add(self.cash_counter) |
52
0d4799866bcf
Sell chickens and buy fences.
Jeremy Thurgood <firxen@gmail.com>
parents:
40
diff
changeset
|
29 self.add_tool_button("Sell chicken", constants.TOOL_SELL_CHICKEN) |
0d4799866bcf
Sell chickens and buy fences.
Jeremy Thurgood <firxen@gmail.com>
parents:
40
diff
changeset
|
30 self.add_tool_button("Sell egg", constants.TOOL_SELL_EGG) |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
60
diff
changeset
|
31 self.add_tool_button("Sell building", constants.TOOL_SELL_BUILDING) |
52
0d4799866bcf
Sell chickens and buy fences.
Jeremy Thurgood <firxen@gmail.com>
parents:
40
diff
changeset
|
32 self.add_tool_button("Buy fence", constants.TOOL_BUY_FENCE) |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
60
diff
changeset
|
33 for building_cls in buildings.BUILDINGS: |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
60
diff
changeset
|
34 self.add_tool_button("Buy %s" % (building_cls.NAME,), building_cls) |
35 | 35 |
40
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
36 def update_cash_counter(self, amount): |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
37 self.cash_counter.update_value("Groats: %s" % amount) |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
38 self.repaint() |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
39 |
35 | 40 def add_tool_button(self, text, tool): |
41 button = gui.Button(text) | |
42 button.connect(gui.CLICK, lambda: self.gameboard.set_selected_tool(tool)) | |
43 self.tr() | |
36
5569430fd82e
Display cleanup and rationalisation.
Jeremy Thurgood <firxen@gmail.com>
parents:
35
diff
changeset
|
44 self.add(button) |
35 | 45 |
46 | |
47 class VidWidget(gui.Widget): | |
48 def __init__(self, gameboard, vid, **params): | |
49 gui.Widget.__init__(self, **params) | |
50 self.gameboard = gameboard | |
39
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
51 vid.bounds = pygame.Rect((0, 0), vid.tile_to_view(vid.size)) |
35 | 52 self.vid = vid |
53 self.width = params.get('width', 0) | |
54 self.height = params.get('height', 0) | |
55 | |
56 def paint(self, surface): | |
57 self.vid.paint(surface) | |
58 | |
59 def update(self, surface): | |
36
5569430fd82e
Display cleanup and rationalisation.
Jeremy Thurgood <firxen@gmail.com>
parents:
35
diff
changeset
|
60 return self.vid.update(surface) |
35 | 61 |
62 def resize(self, width=0, height=0): | |
63 if width is not None: | |
64 self.width = width | |
65 if height is not None: | |
66 self.height = height | |
67 return self.width, self.height | |
68 | |
39
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
69 def move_view(self, x, y): |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
70 self.vid.view.move_ip((x, y)) |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
71 |
35 | 72 def event(self, e): |
73 if e.type == MOUSEBUTTONDOWN: | |
74 self.gameboard.use_tool(e) | |
75 | |
76 | |
9 | 77 class GameBoard(object): |
78 TILE_DIMENSIONS = (20, 20) | |
35 | 79 TOOLBAR_WIDTH = 140 |
9 | 80 |
81 def __init__(self): | |
24
7584453f4944
Add support for PNG tiles.
Simon Cross <hodgestar@gmail.com>
parents:
17
diff
changeset
|
82 self.tv = tiles.FarmVid() |
9 | 83 self.tv.tga_load_tiles(data.filepath('tiles.tga'), self.TILE_DIMENSIONS) |
24
7584453f4944
Add support for PNG tiles.
Simon Cross <hodgestar@gmail.com>
parents:
17
diff
changeset
|
84 self.tv.png_folder_load_tiles(data.filepath('tiles')) |
9 | 85 self.tv.tga_load_level(data.filepath('level1.tga')) |
40
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
86 self.create_disp() |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
87 |
35 | 88 self.selected_tool = None |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
89 self.chickens = [] |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
90 self.foxes = [] |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
60
diff
changeset
|
91 self.buildings = [] |
40
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
92 self.cash = 0 |
52
0d4799866bcf
Sell chickens and buy fences.
Jeremy Thurgood <firxen@gmail.com>
parents:
40
diff
changeset
|
93 self.add_cash(constants.STARTING_CASH) |
17
cbbc5da7708a
Interaction with the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
14
diff
changeset
|
94 |
35 | 95 def create_disp(self): |
96 width, height = pygame.display.get_surface().get_size() | |
36
5569430fd82e
Display cleanup and rationalisation.
Jeremy Thurgood <firxen@gmail.com>
parents:
35
diff
changeset
|
97 tbl = gui.Table() |
5569430fd82e
Display cleanup and rationalisation.
Jeremy Thurgood <firxen@gmail.com>
parents:
35
diff
changeset
|
98 tbl.tr() |
40
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
99 self.toolbar = ToolBar(self) |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
100 tbl.td(self.toolbar, width=self.TOOLBAR_WIDTH) |
37
497b53b69280
Always update the vidwidget.
Jeremy Thurgood <firxen@gmail.com>
parents:
36
diff
changeset
|
101 self.tvw = VidWidget(self, self.tv, width=width-self.TOOLBAR_WIDTH, height=height) |
497b53b69280
Always update the vidwidget.
Jeremy Thurgood <firxen@gmail.com>
parents:
36
diff
changeset
|
102 tbl.td(self.tvw) |
35 | 103 self.disp = gui.App() |
36
5569430fd82e
Display cleanup and rationalisation.
Jeremy Thurgood <firxen@gmail.com>
parents:
35
diff
changeset
|
104 self.disp.init(tbl) |
14 | 105 |
12
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
106 def paint(self, screen): |
35 | 107 self.disp.paint(screen) |
14 | 108 |
9 | 109 def update(self, screen): |
37
497b53b69280
Always update the vidwidget.
Jeremy Thurgood <firxen@gmail.com>
parents:
36
diff
changeset
|
110 self.tvw.reupdate() |
35 | 111 return self.disp.update(screen) |
9 | 112 |
113 def loop(self): | |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
114 self.tv.loop() |
9 | 115 |
35 | 116 def set_selected_tool(self, tool): |
117 self.selected_tool = tool | |
17
cbbc5da7708a
Interaction with the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
14
diff
changeset
|
118 |
cbbc5da7708a
Interaction with the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
14
diff
changeset
|
119 def use_tool(self, e): |
52
0d4799866bcf
Sell chickens and buy fences.
Jeremy Thurgood <firxen@gmail.com>
parents:
40
diff
changeset
|
120 if self.selected_tool == constants.TOOL_SELL_CHICKEN: |
54
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
121 self.sell_chicken(e.pos) |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
122 elif self.selected_tool == constants.TOOL_SELL_EGG: |
52
0d4799866bcf
Sell chickens and buy fences.
Jeremy Thurgood <firxen@gmail.com>
parents:
40
diff
changeset
|
123 pass |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
124 elif self.selected_tool == constants.TOOL_BUY_FENCE: |
54
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
125 self.buy_fence(self.tv.screen_to_tile(e.pos)) |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
60
diff
changeset
|
126 elif buildings.is_building(self.selected_tool): |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
60
diff
changeset
|
127 building_cls = self.selected_tool |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
60
diff
changeset
|
128 tile_pos = self.tv.screen_to_tile(e.pos) |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
60
diff
changeset
|
129 building = building_cls(tile_pos) |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
60
diff
changeset
|
130 self.buy_building(building) |
17
cbbc5da7708a
Interaction with the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
14
diff
changeset
|
131 |
54
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
132 def get_chicken(self, pos): |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
133 for chick in self.chickens: |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
134 if chick.rect.collidepoint(pos): |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
135 return chick |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
136 return None |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
137 |
54
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
138 def sell_chicken(self, pos): |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
139 chick = self.get_chicken(pos) |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
140 if chick is None: |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
141 return |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
142 if len(self.chickens) == 1: |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
143 print "You can't sell your last chicken!" |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
144 return |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
145 self.add_cash(constants.SELL_PRICE_CHICKEN) |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
146 self.remove_chicken(chick) |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
147 |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
148 def buy_fence(self, tile_pos): |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
149 if self.tv.get(tile_pos) != tiles.REVERSE_TILE_MAP['grassland']: |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
150 return |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
151 if self.cash < constants.BUY_PRICE_FENCE: |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
152 print "You can't afford a fence." |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
153 return |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
154 self.add_cash(-constants.BUY_PRICE_FENCE) |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
155 self.tv.set(tile_pos, tiles.REVERSE_TILE_MAP['fence']) |
b8f64db0d39e
Cleaned up buying and selling a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
52
diff
changeset
|
156 |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
60
diff
changeset
|
157 def buy_building(self, building): |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
60
diff
changeset
|
158 if self.cash < building.buy_price(): |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
54
diff
changeset
|
159 return |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
60
diff
changeset
|
160 if building.place(self.tv): |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
60
diff
changeset
|
161 self.add_cash(-building.buy_price()) |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
60
diff
changeset
|
162 self.add_building(building) |
60
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
163 |
14 | 164 def event(self, e): |
39
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
165 if e.type == KEYDOWN: |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
166 if e.key == K_UP: |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
167 self.tvw.move_view(0, -self.TILE_DIMENSIONS[1]) |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
168 if e.key == K_DOWN: |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
169 self.tvw.move_view(0, self.TILE_DIMENSIONS[1]) |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
170 if e.key == K_LEFT: |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
171 self.tvw.move_view(-self.TILE_DIMENSIONS[0], 0) |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
172 if e.key == K_RIGHT: |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
173 self.tvw.move_view(self.TILE_DIMENSIONS[0], 0) |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
174 else: |
ec79aabe2bf1
Scroll game window with arrow keys.
Jeremy Thurgood <firxen@gmail.com>
parents:
37
diff
changeset
|
175 self.disp.event(e) |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
176 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
177 def clear_foxes(self): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
178 for fox in self.foxes: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
179 self.tv.sprites.remove(fox) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
180 self.foxes = [] # Remove all the foxes |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
181 |
29 | 182 def move_foxes(self): |
183 for fox in self.foxes: | |
184 fox.move(self) | |
185 | |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
186 def add_chicken(self, chicken): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
187 self.chickens.append(chicken) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
188 self.tv.sprites.append(chicken) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
189 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
190 def add_fox(self, fox): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
191 self.foxes.append(fox) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
24
diff
changeset
|
192 self.tv.sprites.append(fox) |
29 | 193 |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
60
diff
changeset
|
194 def add_building(self, building): |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
60
diff
changeset
|
195 self.buildings.append(building) |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
60
diff
changeset
|
196 self.tv.sprites.append(building) |
60
e2631c8e2cd6
Implement guard towers (with temporary sprite PNG).
Simon Cross <hodgestar@gmail.com>
parents:
57
diff
changeset
|
197 |
29 | 198 def remove_fox(self, fox): |
199 if fox in self.foxes: | |
200 self.foxes.remove(fox) | |
201 self.tv.sprites.remove(fox) | |
202 | |
203 def remove_chicken(self, chick): | |
204 if chick in self.chickens: | |
205 self.chickens.remove(chick) | |
206 self.tv.sprites.remove(chick) | |
40
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
207 |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
208 def add_cash(self, amount): |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
209 self.cash += amount |
678421bd58ee
Money counter with very ugly display hack.
Jeremy Thurgood <firxen@gmail.com>
parents:
39
diff
changeset
|
210 self.toolbar.update_cash_counter(self.cash) |