comparison gamelib/gamegui.py @ 56:78dfd429b9a6

Start adding science buttons
author Neil Muller <drnlmuller@gmail.com>
date Mon, 07 May 2012 22:54:15 +0200
parents 655a6912e0ae
children 9aa0252fb6e4
comparison
equal deleted inserted replaced
55:86d83dcb7d42 56:78dfd429b9a6
5 5
6 from gamelib.gui_base import Window 6 from gamelib.gui_base import Window
7 from gamelib.gui import BigButton 7 from gamelib.gui import BigButton
8 from gamelib.engine import PopWindow 8 from gamelib.engine import PopWindow
9 from gamelib.constants import WIDTH 9 from gamelib.constants import WIDTH
10 from gamelib.gamestate import Game
10 11
11 12
12 class ExitGameButton(BigButton): 13 class ExitGameButton(BigButton):
13 14
14 def __init__(self): 15 def __init__(self):
16 17
17 def on_click(self): 18 def on_click(self):
18 PopWindow.post() 19 PopWindow.post()
19 20
20 21
22 class EndTurnButton(BigButton):
23
24 def __init__(self, parent):
25 super(EndTurnButton, self).__init__(((WIDTH - 256), 10), 'End Turn')
26 self.parent = parent
27
28 def on_click(self):
29 self.parent.end_turn()
30
31
32 class ResetButton(BigButton):
33
34 def __init__(self, parent):
35 super(ResetButton, self).__init__((10, 10), 'Reset points')
36 self.parent = parent
37
38 def on_click(self):
39 self.parent.reset()
40
41
42 class ScienceWidget(BigButton):
43
44 def __init__(self, science, pos, parent):
45 self.science = science
46 self.points = 0
47 self.parent = parent
48 super(ScienceWidget, self).__init__(pos, '%s: %d' % (science.NAME,
49 science.points))
50
51 def on_click(self):
52 if self.parent.available_points > 0:
53 self.points += 1
54 self.text = '%s: %d' % (self.science.NAME,
55 self.science.points + self.points)
56 self.parent.available_points -= 1
57 self._draw_text()
58
59 def reset(self):
60 self.parent.available_points += self.points
61 self.points = 0
62 self.text = '%s: %d' % (self.science.NAME, self.science.points)
63 self._draw_text()
64
65
21 class GameWindow(Window): 66 class GameWindow(Window):
22 """Main window for the game""" 67 """Main window for the game"""
23 68
24 def __init__(self, screen): 69 def __init__(self, screen):
25 super(GameWindow, self).__init__(screen) 70 super(GameWindow, self).__init__(screen)
71 self.game = Game()
26 exit = ExitGameButton() 72 exit = ExitGameButton()
27 self.add_child(exit) 73 self.add_child(exit)
74 end_turn = EndTurnButton(self)
75 self.add_child(end_turn)
76 reset = ResetButton(self)
77 self.add_child(reset)
78
79 self.game.start_turn()
80
81 self.available_points = self.game.points
82
83 self._sciences = []
84
85 x = 0
86 y = 200
87
88 for science in self.game.lab.science:
89 widget = ScienceWidget(science, (x, y), self)
90 self.add_child(widget)
91 self._sciences.append(widget)
92 x += 100
93
94 def end_turn(self):
95 pass
96
97 def reset(self):
98 for widget in self._sciences:
99 widget.reset()