erkennt jetzt ob das spiel fertig ist
[darcs-mirror-ozeanien.git] / grasstheme.py
1 #!/usr/bin/python
2 # encoding:utf8
3
4 import pygtk
5 pygtk.require('2.0')
6 import gtk
7 import cairo
8 import math
9 import random
10
11 from cairoboard import *
12 import engine
13
14
15 class GrassBoard(CairoBoard):
16     def draw_base(self,cr):
17         cr.translate(GRIDPAD, GRIDPAD)
18         cr.scale(GRIDWIDTH, GRIDWIDTH)
19
20         # Earth Background
21
22         # Unten
23         pat = cairo.LinearGradient (0, 5, 0, 5.5)
24         pat.add_color_stop_rgba(0.3, 0.6, 0.4, 0.4,1)
25         pat.add_color_stop_rgba(1, 0.6, 0.4, 0.4,0)
26         cr.rectangle(1, 5, 7, 0.5)
27         cr.set_source(pat)
28         cr.fill()
29
30         # Oben
31         pat = cairo.LinearGradient (0, 0, 0, -0.5)
32         pat.add_color_stop_rgba(0.3, 0.6, 0.4, 0.4,1)
33         pat.add_color_stop_rgba(1, 0.6, 0.4, 0.4,0)
34         cr.rectangle(1, -0.5, 7, 0.5)
35         cr.set_source(pat)
36         cr.fill()
37
38         # Links
39         pat = cairo.LinearGradient (1, 0, 0.5, 0)
40         pat.add_color_stop_rgba(0.3, 0.6, 0.4, 0.4,1)
41         pat.add_color_stop_rgba(1, 0.6, 0.4, 0.4,0)
42         cr.rectangle(0.5, 0, 0.5, 5)
43         cr.set_source(pat)
44         cr.fill()
45
46         # Rechts
47         pat = cairo.LinearGradient (8, 0, 8.5, 0)
48         pat.add_color_stop_rgba(0.3, 0.6, 0.4, 0.4,1)
49         pat.add_color_stop_rgba(1, 0.6, 0.4, 0.4,0)
50         cr.rectangle(8, 0, 0.5, 5)
51         cr.set_source(pat)
52         cr.fill()
53
54         # Oben Links
55         pat = cairo.RadialGradient(1,0,0, 1,0, 0.5)
56         pat.add_color_stop_rgba(0.3, 0.6, 0.4, 0.4, 1)
57         pat.add_color_stop_rgba(1, 0.6, 0.4, 0.4, 0)
58         cr.rectangle(0.5, -0.5, 0.5, 0.5)
59         cr.set_source(pat)
60         cr.fill()
61
62         # Oben Rechts
63         pat = cairo.RadialGradient(8,0,0, 8,0, 0.5)
64         pat.add_color_stop_rgba(0.3, 0.6, 0.4, 0.4, 1)
65         pat.add_color_stop_rgba(1, 0.6, 0.4, 0.4, 0)
66         cr.rectangle(8, -0.5, 8.5, 0.5)
67         cr.set_source(pat)
68         cr.fill()
69
70         # Unten Rechts
71         pat = cairo.RadialGradient(8,5,0, 8,5, 0.5)
72         pat.add_color_stop_rgba(0.3, 0.6, 0.4, 0.4, 1)
73         pat.add_color_stop_rgba(1, 0.6, 0.4, 0.4, 0)
74         cr.rectangle(8, 5, 8.5, 5.5)
75         cr.set_source(pat)
76         cr.fill()
77
78         # Unten Links
79         pat = cairo.RadialGradient(1,5,0, 1,5, 0.5)
80         pat.add_color_stop_rgba(0.3, 0.6, 0.4, 0.4, 1)
81         pat.add_color_stop_rgba(1, 0.6, 0.4, 0.4, 0)
82         cr.rectangle(0.5, 5, 0.5, 5.5)
83         cr.set_source(pat)
84         cr.fill()
85
86
87         # Frame
88         cr.set_source_rgb(1,1,1)
89         cr.set_line_width(0.05)
90         cr.set_line_cap(cairo.LINE_CAP_ROUND)
91         for x in range(0,8):
92             cr.move_to(1+x, 0)
93             cr.line_to(1+x, 5.5)
94             cr.stroke()
95         for y in range(0,6):
96             cr.move_to(0.5, y)
97             cr.line_to(8.5, y)
98             cr.stroke()
99
100 class GrassSlot(CairoSlot):
101     def __init__(self, fabric, slot):
102         CairoSlot.__init__(self, fabric, slot)
103
104 class GrassBoardSlot(CairoBoardSlot, GrassSlot):
105     def __init__(self, fabric, slot):
106         GrassSlot.__init__(self, fabric, slot)
107
108 class GrassShip(CairoShip):
109     def __init__(self, fabric, ship):
110         CairoShip.__init__(self, fabric, ship)
111     
112     def draw_cache(self, cr):
113         # Grundkörper (noch abzurunden)
114         cr.move_to(-0.5, -0.75)
115         cr.line_to(0.5, -0.75)
116         cr.line_to(0.5, 0.5)
117         cr.line_to(-0.5, 0.5)
118         cr.close_path()
119         cr.set_source_rgb(1, 0.2, 0.2)
120         cr.fill_preserve()
121         cr.set_source_rgb(0, 0, 0)
122         cr.set_line_width(0.05)
123         cr.stroke()
124
125         # Griff
126         cr.move_to(-0.25, 0.25)
127         cr.line_to(-0.55,  0.75)
128         cr.line_to( 0.55,  0.75)
129         cr.line_to( 0.25, 0.25)
130         cr.set_line_width(0.1)
131         cr.set_line_join(cairo.LINE_JOIN_ROUND)
132         cr.stroke()
133         
134         # Motor
135         cr.arc(0, -0.1 , 0.3, 0, 2*math.pi)
136         cr.set_source_rgb(0, 0, 0)
137         cr.fill()
138
139         # Augen
140         for _ in range(2):
141             cr.scale(-1,1)
142             cr.arc(0.3, -0.55 , 0.15, 0, 2*math.pi)
143             cr.set_source_rgb(1, 1, 1)
144             cr.fill_preserve()
145             cr.set_source_rgb(0, 0, 0)
146             cr.set_line_width(0.05)
147             cr.stroke()
148             cr.arc(0.25, -0.6 , 0.05, 0, 2*math.pi)
149             cr.set_source_rgb(0, 0, 0)
150             cr.fill()
151
152
153 class GrassHandSlot(CairoHandSlot, GrassSlot):
154     def __init__(self, fabric, slot):
155         GrassSlot.__init__(self, fabric, slot)
156         CairoHandSlot.__init__(self)
157
158 class GrassPile(CairoPile, GrassSlot):
159     def __init__(self, fabric, slot):
160         GrassSlot.__init__(self, fabric, slot)
161         CairoPile.__init__(self, fabric, slot)
162         self.super = GrassSlot
163
164 class GrassCard(CairoCard):
165     def __init__(self, fabric, card):
166         CairoCard.__init__(self, fabric, card)
167
168     #Karte füllen
169     def draw_cache(self, cr):
170         orientation=0;
171         cr.set_source_rgb(0.6, 0.4, 0.3)
172         cr.rectangle(-1, -1, 2, 2)
173         cr.fill()
174         p2c = [ (0.7,0), (0,-0.7), (-0.7,0), (0,0.7) ]
175         between_p2c = [ (0.6,-0.6), (-0.6,-0.6), (-0.6,0.6), (0.6,0.6) ]
176         matrix=cr.get_matrix()
177         for c in [
178                     (-0.7,-0.6), 
179                     (0,-0.65),
180                     (-0.5,-0.6),
181                     (0.4,-0.55),
182                     (0.8,-0.6),
183                     (-0.3,-0.4),
184                     (0.6,-0.35),
185                     (-0.85,-0.3),
186                     (0.3,-0.3),
187                     (0,-0.25),
188                     (-0.6,-0.2),
189                     (0.75,-0.2),
190                     (0.5,-0.1),
191                     (-0.5,0),
192                     (0.3,0.1),
193                     (-0.1,0.1),
194                     (-0.8,0.2),
195                     (0.7,0.2),
196                     (-0.4,0.3),
197                     (0.85,0.3),
198                     (-0.1,0.35),
199                     (0.25,0.4),
200                     (-0.75,0.4),
201                     (0.6,0.45),
202                     (-0.45,0.5),
203                     (0,0.6),
204                     (-0.8,0.7),
205                     (0.75,0.7),
206                     (-0.4,0.75),
207                     (0.5,0.75),
208                     (0.15,0.8),
209                     (-0.2,0.85),
210                     (-0.85,0.9),
211                     (0.85,0.9),
212                     (0,0.95),
213                     (-0.5,1),
214                     (0.45,1),
215                     
216                 ]:
217             cr.translate(*c)
218             self.draw_gras(cr, 0)
219             self.draw_gras(cr, 1)
220             cr.set_matrix(matrix)
221
222         for island in self.card.islands:
223             for dir in island:
224                 cr.translate(*p2c[dir])
225                 self.draw_flower(cr)
226                 cr.set_matrix(matrix)
227             for dir in island:
228                 if (dir+1)%4 in island:
229                     cr.translate(*between_p2c[dir])
230                     self.draw_flower(cr)
231                     cr.set_matrix(matrix)
232             if len(island) == 4:
233                 self.draw_flower(cr)
234
235     #Einen Grashalm malen
236     def draw_gras(self, cr, orientation):
237         x=random.uniform(0.1,0.2)
238         y=random.uniform(0.2,0.3)
239         matrix=cr.get_matrix()
240         if orientation == 0: 
241             cr.scale(x, y)
242         else:
243             cr.scale(-x, y)
244         cr.translate(-1,-1)
245         cr.set_source_rgb(0, 1, 0)
246         cr.move_to(-1,-1)
247         cr.curve_to(0,-1,1,0,1,1)
248         cr.curve_to(0,1,0,-1,-1,-1)
249         cr.fill_preserve()
250         cr.set_source_rgb(0, 0, 0)
251         cr.set_line_width(0.1)
252         cr.stroke()
253         cr.set_matrix(matrix)
254             
255     def choose_flower_color(self):
256         return (1,random.random(),random.random())
257
258     #Eine Blume malen
259     def draw_flower(self, cr):
260         cr.rotate(random.uniform(0,2*math.pi))
261         matrix=cr.get_matrix()
262         cr.scale(0.25, 0.25)
263         color = self.choose_flower_color()
264         for n in range(5):
265             cr.set_source_rgb(*color)
266             cr.move_to(0,0)
267             cr.curve_to(0,-0.8,-0.2,-1,-1,-1)
268             cr.curve_to(-1,-0.2,-0.8,0.2,0,0)
269             cr.fill_preserve()
270             cr.set_source_rgb(0, 0, 0)
271             cr.set_line_width(0.1)
272             cr.stroke()
273             cr.rotate(2* math.pi / 5)
274         cr.set_matrix(matrix)
275     
276 class GrassBlackHole(CairoBlackHole):
277     def __init__(self, fabric, bh):
278         CairoBlackHole.__init__(self, fabric, bh)
279
280 class GrassFabric(CairoFabric):
281     classes = [ 
282             (engine.Board,      GrassBoard),
283             (engine.BoardSlot,  GrassBoardSlot),
284             (engine.BlackHole,  GrassBlackHole),
285             (engine.HandSlot,   GrassHandSlot),
286             (engine.Pile,       GrassPile),
287             (engine.Slot,       GrassSlot),
288             (engine.Ship,       GrassShip),
289             (engine.Card,       GrassCard),
290     ]
291
292
293 # vim:ts=4:sw=4:sts=4:et