-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·77 lines (61 loc) · 2.13 KB
/
main.py
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
# this must be first
from kivy import Config
Config.set('kivy', 'log_level', 'info') # info, debug, or warning
Config.set('graphics', 'width', '320')
Config.set('graphics', 'height', '480')
Config.set('graphics', 'resizable', '0')
from kivy.app import App, platform
from kivy.lang import Builder
from kivy.core.window import Window
from screen import GameScreen
from util import scale
__version__ = '0.1'
class Twenty48(App):
def build(self):
Builder.load_file('./screen.kv')
Builder.load_file('./board.kv')
Builder.load_file('./block.kv')
self.set_screen_size()
return GameScreen()
@staticmethod
def get_color_value(value):
return {
2: (.929, .891, .852, 1),
4: (.925, .875, .781, 1),
8: (.945, .691, .472, 1),
16: (.957, .582, .386, 1),
32: (.960, .484, .371, 1),
64: (.960, .367, .230, 1),
128: (.926, .808, .445, 1),
256: (.926, .796, .379, 1),
512: (.925, .781, .313, 1),
1024: (1.0, .746, 0.00, 1),
2048: (1.0, 0.00, 0.00, 1)
}.get(value, (1, 1, 1, 1))
@staticmethod
def get_text_color(value):
return {
2: (.074, .429, .394, 1),
4: (.074, .429, .394, 1),
8: (.972, .960, .945, 1),
16: (.972, .960, .945, 1),
32: (.972, .960, .945, 1),
64: (.972, .960, .945, 1),
128: (.972, .960, .945, 1),
256: (.972, .960, .945, 1),
512: (.972, .960, .945, 1),
1024: (.972, .960, .945, 1),
2048: (.972, .960, .945, 1)
}.get(value, (0, 0, 0, 1))
@staticmethod
def set_screen_size():
w = Config.getint('graphics', 'width')
h = Config.getint('graphics', 'height')
dim = Window.size
if platform not in ('ios', 'android'):
Window.size = (w, h)
scalex = dim[0]/float(w)
scaley = dim[1]/float(h)
scale.set_scale(scalex, scaley)
if __name__ == '__main__':
Twenty48().run()