changeset 52:0d4799866bcf

Sell chickens and buy fences.
author Jeremy Thurgood <firxen@gmail.com>
date Mon, 31 Aug 2009 17:37:20 +0000
parents 32fb395cf71c
children f20dd3dcb118
files gamelib/constants.py gamelib/gameboard.py
diffstat 2 files changed, 37 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/constants.py	Mon Aug 31 17:18:03 2009 +0000
+++ b/gamelib/constants.py	Mon Aug 31 17:37:20 2009 +0000
@@ -6,7 +6,7 @@
 
 AUTHORS = [
     ("Adrianna Pinska", "adrianna.pinska@gmail.com"),
-    ("Jeremy Thurgood", ""),
+    ("Jeremy Thurgood", "firxen+rinkhals@gmail.com"),
     ("Neil Muller", ""),
     ("Simon Cross", "hodgestar+rinkhals@gmail.com"),
 ]
@@ -15,3 +15,15 @@
 
 SCREEN = (800, 600)
 FG_COLOR = (255, 255, 255)
+BG_COLOR = (0, 0, 0)
+
+# Game constants
+
+STARTING_CASH = 100
+SELL_PRICE_CHICKEN = 10
+BUY_PRICE_FENCE = 50
+
+TOOL_SELL_CHICKEN = 1
+TOOL_SELL_EGG = 2
+TOOL_BUY_FENCE = 3
+TOOL_BUY_HENHOUSE = 4
--- a/gamelib/gameboard.py	Mon Aug 31 17:18:03 2009 +0000
+++ b/gamelib/gameboard.py	Mon Aug 31 17:37:20 2009 +0000
@@ -6,12 +6,6 @@
 import tiles
 import constants
 
-# FIXME: These should probably be proper events of some kind.
-SELL_CHICKEN = None
-SELL_EGG = None
-BUY_FENCE = 2
-BUY_HENHOUSE = 3
-
 
 class OpaqueLabel(gui.Label):
     def paint(self, s):
@@ -31,10 +25,10 @@
         self.cash_counter = OpaqueLabel("Groats:                ", color=constants.FG_COLOR)
         self.tr()
         self.add(self.cash_counter)
-        self.add_tool_button("Sell chicken", SELL_CHICKEN)
-        self.add_tool_button("Sell egg", SELL_EGG)
-        self.add_tool_button("Buy fence", BUY_FENCE)
-        self.add_tool_button("Buy henhouse", BUY_HENHOUSE)
+        self.add_tool_button("Sell chicken", constants.TOOL_SELL_CHICKEN)
+        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)
 
     def update_cash_counter(self, amount):
         self.cash_counter.update_value("Groats: %s" % amount)
@@ -92,6 +86,7 @@
         self.chickens = []
         self.foxes = []
         self.cash = 0
+        self.add_cash(constants.STARTING_CASH)
 
     def create_disp(self):
         width, height = pygame.display.get_surface().get_size()
@@ -115,15 +110,28 @@
         self.tv.loop()
 
     def set_selected_tool(self, tool):
-        if tool is None:
-            self.add_cash(10)
         self.selected_tool = tool
 
     def use_tool(self, e):
-        if self.selected_tool is None:
-            return
-        pos = self.tv.screen_to_tile(e.pos)
-        self.tv.set(pos, self.selected_tool)
+        if self.selected_tool == constants.TOOL_SELL_CHICKEN:
+            for chick in self.chickens:
+                if chick.rect.collidepoint(e.pos):
+                    if len(self.chickens) == 1:
+                        print "Can't sell your last chicken!"
+                    else:
+                        self.add_cash(constants.SELL_PRICE_CHICKEN)
+                        self.remove_chicken(chick)
+                    break
+        if self.selected_tool == constants.TOOL_SELL_EGG:
+            pass
+        if self.selected_tool == constants.TOOL_BUY_FENCE:
+            tile_pos = self.tv.screen_to_tile(e.pos)
+            if (self.cash >= constants.BUY_PRICE_FENCE and
+                self.tv.get(tile_pos) == tiles.REVERSE_TILE_MAP['grassland']):
+                self.add_cash(-constants.BUY_PRICE_FENCE)
+                self.tv.set(tile_pos, tiles.REVERSE_TILE_MAP['fence'])
+        if self.selected_tool == constants.TOOL_BUY_HENHOUSE:
+            pass
 
     def event(self, e):
         if e.type == KEYDOWN: