-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgame2048.kv
321 lines (272 loc) · 7.94 KB
/
game2048.kv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#:kivy 1.7.2
#:import rgb kivy.utils.get_color_from_hex
<BoxButton@ButtonBehavior+BoxLayout>:
source: ''
orientation: 'vertical'
padding: '8dp'
canvas.before:
Color:
rgb: 0xbb / 255., 0xad / 255., 0xa0 / 255.
BorderImage:
pos: self.pos
size: self.size
source: 'data/round.png'
Image:
source: root.source
<TextButton@Button>:
color: 1, 1, 1, 1
background_color: 0xbb / 255., 0xad / 255., 0xa0 / 255., 1.
background_normal: 'data/round.png'
background_down: 'data/round.png'
size_hint_y: None
height: '48dp'
font_size: '20dp'
bold: True
<ToggleButton>:
color: 1, 1, 1, 1
background_color: 0x77 / 255., 0x6e / 255., 0x65 / 255., 1.
background_normal: 'data/round.png'
#background_down: 'data/round.png'
size_hint_y: None
height: '48dp'
font_size: '20dp'
bold: True
<Number>:
canvas.before:
PushMatrix
Translate:
xy: self.center_x, self.center_y
Scale:
xyz: root.scale, root.scale, 0
Translate:
xy: -self.center_x, -self.center_y
canvas.after:
PopMatrix
canvas:
Color:
rgb: self.colors.get(self.number, self.colors.get(2))
BorderImage:
pos: self.pos
size: self.size
source: 'data/round.png'
Label:
text: str(root.number)
font_size: min(self.height, self.width) / 2.5
color: rgb('#f9f6f2') if root.number >= 8 else rgb('#776e65')
bold: True
size: root.size
center: root.center
BoxLayout:
padding: '10dp'
spacing: '10dp'
orientation: 'vertical' if self.height > self.width else 'horizontal'
canvas:
Color:
rgb: 0xfa / 255., 0xf8 / 255., 0xef / 255.
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
orientation: 'vertical' if root.height > root.width else 'horizontal'
size_hint_y: .15 if root.height > root.width else 1
BoxLayout:
spacing: '10dp'
padding: '10dp'
orientation: 'vertical' if root.height < root.width else 'horizontal'
BoxLayout:
orientation: 'vertical'
spacing: '10dp'
Label:
text: '2048'
font_size: min(self.height, self.width) / 2.
color: 0x77 / 255., 0x6e / 255., 0x65 / 255., 1.
#size_hint_y: .5
bold: True
BoxLayout:
orientation: 'vertical'
spacing: '10dp'
BoxLayout:
orientation: 'vertical'
size_hint_y: .4
canvas.before:
#Color:
# rgb: 0xbb / 255., 0xad / 255., 0xa0 / 255.
#BorderImage:
# pos: self.pos
# size: self.size
# source: 'data/round.png'
Label:
text: 'AI CONTROL'
font_size: self.height / 2
color: 0x77 / 255., 0x6e / 255., 0x65 / 255., 1.
bold: True
GridLayout:
orientation: 'horizontal'
spacing: '10dp'
padding: ['0dp','10dp'] # horizontal, vertical
pos_hint: {'center_x': .5, 'center_y': .5}
rows: 2
cols: 2
TextButton:
pos_hint: {'center_x': .5, 'center_y': .5}
text: 'Mover'
on_press: app.ai_move()
ToggleButton:
id: play_but
pos_hint: {'center_x': .5, 'center_y': .5}
text: 'Jogar'
on_press: app.ai_play(play_but)
Label:
BoxLayout:
id: tempo_controls
anchor_y: 'top'
spacing: '5dp'
#padding: '5dp'
TextButton:
pos_hint: {'center_x': .5, 'center_y': .5}
background_color: 0x77 / 255., 0x6e / 255., 0x65 / 255., 1.
text: '-'
font_size: self.height
valign: 'middle'
on_press: app.ai_increase_tempo() if tempo_controls.opacity == 1. else None
TextButton:
pos_hint: {'center_x': .5, 'center_y': .5}
background_color: 0x77 / 255., 0x6e / 255., 0x65 / 255., 1.
text: '+'
font_size: self.height
on_press: app.ai_decrease_tempo() if tempo_controls.opacity == 1. else None
BoxLayout:
orientation: 'vertical'
spacing: '10dp'
BoxLayout:
orientation: 'vertical'
canvas.before:
Color:
rgb: 0xbb / 255., 0xad / 255., 0xa0 / 255.
BorderImage:
pos: self.pos
size: self.size
source: 'data/round.png'
Label:
text: 'SCORE'
color: 0xee / 255., 0xe4 / 255., 0xda / 255., 1.
font_size: self.height / 1.5
size_hint_y: .5
bold: True
Label:
text: str(game.score)
font_size: self.height / 1.5
bold: True
BoxLayout:
id: scoring
spacing: '10dp'
BoxButton:
source: 'data/icon-leaderboard.png'
on_press: app.gs_show_leaderboard()
BoxButton:
source: 'data/icon-achievements.png'
on_press: app.gs_show_achievements()
AnchorLayout:
id: anchor
Game2048:
id: game
size_hint: None, None
size: [min(anchor.width, anchor.height)] * 2
on_size: self.reposition()
on_pos: self.reposition()
<Game2048>:
AnchorLayout:
id: end
pos: root.pos
size: root.size
opacity: 0
canvas:
Color:
rgba: 0xfa / 255., 0xf8 / 255., 0xef / 255., self.opacity - 0.2
BorderImage:
pos: self.pos
size: self.size
source: 'data/round.png'
BoxLayout:
orientation: 'vertical'
padding: '10dp'
spacing: '20dp'
Label:
id: end_label
font_size: min(self.height, self.width) / 3.
color: 0x77 / 255., 0x6e / 255., 0x65 / 255., 1.
bold: True
text: 'Game\nover!'
halign: 'center'
TextButton:
text: 'Restart'
on_press: root.restart() if end.opacity == 1. else None
font_size: '20dp'
# still using 1.7.2 for android, and i want the title color
# ModalView widget
<-Popup>:
_container: container
canvas:
Color:
rgba: root.background_color[:3] + [root.background_color[-1] * self._anim_alpha]
Rectangle:
size: self._window.size if self._window else (0, 0)
Color:
rgb: 1, 1, 1
BorderImage:
source: root.background
border: root.border
pos: self.pos
size: self.size
GridLayout:
padding: 12
cols: 1
size_hint: None, None
pos: root.pos
size: root.size
Label:
text: root.title
color: 0x77 / 255., 0x6e / 255., 0x65 / 255., 1.
size_hint_y: None
height: self.texture_size[1] + 16
text_size: self.width - 16, None
font_size: root.title_size
Widget:
size_hint_y: None
height: 4
canvas:
Color:
rgba: root.separator_color
Rectangle:
pos: self.x, self.y + root.separator_height / 2.
size: self.width, root.separator_height
BoxLayout:
id: container
<GooglePlayPopup>:
size_hint: None, None
title: 'Connect to Google Play'
size: '300dp', '300dp'
background: 'data/popup.png'
separate_color: 0x77 / 255., 0x6e / 255., 0x65 / 255., 1.
title_size: '20sp'
BoxLayout:
orientation: 'vertical'
spacing: '10dp'
padding: '10dp'
Label:
font_size: '20sp'
color: 0x77 / 255., 0x6e / 255., 0x65 / 255., 1.
bold: True
text: 'Do you want to connect to Google Play for the Leaderboard and Achievements ?'
text_size: self.width - dp(20), None
halign: 'center'
BoxLayout:
size_hint_y: None
height: '68dp'
spacing: '10dp'
TextButton:
text: 'No'
on_press: root.dismiss()
TextButton:
text: 'Yes'
on_press: app.activate_google_play(); root.dismiss()