changeset 56:78dfd429b9a6

Start adding science buttons
author Neil Muller <drnlmuller@gmail.com>
date Mon, 07 May 2012 22:54:15 +0200
parents 86d83dcb7d42
children 9aa0252fb6e4
files gamelib/gamegui.py
diffstat 1 files changed, 72 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/gamegui.py	Mon May 07 22:53:18 2012 +0200
+++ b/gamelib/gamegui.py	Mon May 07 22:54:15 2012 +0200
@@ -7,6 +7,7 @@
 from gamelib.gui import BigButton
 from gamelib.engine import PopWindow
 from gamelib.constants import WIDTH
+from gamelib.gamestate import Game
 
 
 class ExitGameButton(BigButton):
@@ -18,10 +19,81 @@
         PopWindow.post()
 
 
+class EndTurnButton(BigButton):
+
+    def __init__(self, parent):
+        super(EndTurnButton, self).__init__(((WIDTH - 256), 10), 'End Turn')
+        self.parent = parent
+
+    def on_click(self):
+        self.parent.end_turn()
+
+
+class ResetButton(BigButton):
+
+    def __init__(self, parent):
+        super(ResetButton, self).__init__((10, 10), 'Reset points')
+        self.parent = parent
+
+    def on_click(self):
+        self.parent.reset()
+
+
+class ScienceWidget(BigButton):
+
+    def __init__(self, science, pos, parent):
+        self.science = science
+        self.points = 0
+        self.parent = parent
+        super(ScienceWidget, self).__init__(pos, '%s: %d' % (science.NAME,
+            science.points))
+
+    def on_click(self):
+        if self.parent.available_points > 0:
+            self.points += 1
+            self.text = '%s: %d' % (self.science.NAME,
+                    self.science.points + self.points)
+            self.parent.available_points -= 1
+            self._draw_text()
+
+    def reset(self):
+        self.parent.available_points += self.points
+        self.points = 0
+        self.text = '%s: %d' % (self.science.NAME, self.science.points)
+        self._draw_text()
+
+
 class GameWindow(Window):
     """Main window for the game"""
 
     def __init__(self, screen):
         super(GameWindow, self).__init__(screen)
+        self.game = Game()
         exit = ExitGameButton()
         self.add_child(exit)
+        end_turn = EndTurnButton(self)
+        self.add_child(end_turn)
+        reset = ResetButton(self)
+        self.add_child(reset)
+
+        self.game.start_turn()
+
+        self.available_points = self.game.points
+
+        self._sciences = []
+
+        x = 0
+        y = 200
+
+        for science in self.game.lab.science:
+            widget = ScienceWidget(science, (x, y), self)
+            self.add_child(widget)
+            self._sciences.append(widget)
+            x += 100
+
+    def end_turn(self):
+        pass
+
+    def reset(self):
+        for widget in self._sciences:
+            widget.reset()