changeset 60:e2631c8e2cd6

Implement guard towers (with temporary sprite PNG).
author Simon Cross <hodgestar@gmail.com>
date Mon, 31 Aug 2009 19:10:31 +0000
parents efbaedd0fdfe
children 67f0346e5435
files data/sprites/guardtower.png gamelib/constants.py gamelib/gameboard.py
diffstat 3 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
Binary file data/sprites/guardtower.png has changed
--- a/gamelib/constants.py	Mon Aug 31 19:04:00 2009 +0000
+++ b/gamelib/constants.py	Mon Aug 31 19:10:31 2009 +0000
@@ -23,8 +23,10 @@
 SELL_PRICE_CHICKEN = 10
 BUY_PRICE_FENCE = 50
 BUY_PRICE_HENHOUSE = 100
+BUY_PRICE_GUARDTOWER = 200
 
 TOOL_SELL_CHICKEN = 1
 TOOL_SELL_EGG = 2
 TOOL_BUY_FENCE = 3
 TOOL_BUY_HENHOUSE = 4
+TOOL_BUY_GUARDTOWER = 5
--- a/gamelib/gameboard.py	Mon Aug 31 19:04:00 2009 +0000
+++ b/gamelib/gameboard.py	Mon Aug 31 19:10:31 2009 +0000
@@ -30,6 +30,7 @@
         self.add_tool_button("Sell egg", constants.TOOL_SELL_EGG)
         self.add_tool_button("Buy fence", constants.TOOL_BUY_FENCE)
         self.add_tool_button("Buy henhouse", constants.TOOL_BUY_HENHOUSE)
+        self.add_tool_button("Buy guard tower", constants.TOOL_BUY_GUARDTOWER)
 
     def update_cash_counter(self, amount):
         self.cash_counter.update_value("Groats: %s" % amount)
@@ -87,6 +88,7 @@
         self.chickens = []
         self.foxes = []
         self.henhouses = []
+        self.guardtowers = []
         self.cash = 0
         self.add_cash(constants.STARTING_CASH)
 
@@ -123,6 +125,8 @@
             self.buy_fence(self.tv.screen_to_tile(e.pos))
         elif self.selected_tool == constants.TOOL_BUY_HENHOUSE:
             self.buy_henhouse(self.tv.screen_to_tile(e.pos))
+        elif self.selected_tool == constants.TOOL_BUY_GUARDTOWER:
+            self.buy_guardtower(self.tv.screen_to_tile(e.pos))
 
     def get_chicken(self, pos):
         for chick in self.chickens:
@@ -157,6 +161,14 @@
             self.add_cash(-constants.BUY_PRICE_HENHOUSE)
             self.add_henhouse(henhouse)
 
+    def buy_guardtower(self, tile_pos):
+        if self.cash < constants.BUY_PRICE_GUARDTOWER:
+            return
+        guardtower = buildings.GuardTower(tile_pos)
+        if guardtower.place(self.tv):
+            self.add_cash(-constants.BUY_PRICE_GUARDTOWER)
+            self.add_guardtower(guardtower)
+
     def event(self, e):
         if e.type == KEYDOWN:
             if e.key == K_UP:
@@ -191,6 +203,10 @@
         self.henhouses.append(henhouse)
         self.tv.sprites.append(henhouse)
 
+    def add_guardtower(self, guardtower):
+        self.guardtowers.append(guardtower)
+        self.tv.sprites.append(guardtower)
+
     def remove_fox(self, fox):
         if fox in self.foxes:
             self.foxes.remove(fox)