-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.py
180 lines (157 loc) · 5.79 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
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
#!/usr/bin/python
# encoding: utf-8
__author__ = 'oddBit'
import kivy
kivy.require('1.8.0')
from kivy.app import App
from kivy.lang import Builder
from MapCanvas import MapCanvas
from MainMenu import MainMenu
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock
from kivy.core.window import Window
from kivy.uix.image import Image
from SettingsJson import settings_json
from kivy.core.audio import SoundLoader
from HelpMenu import HelpMenu
from kivy.utils import platform
from data.gameData import *
try:
from revmob import RevMob as revmob
use_ads = True
except ImportError:
use_ads = False
Builder.load_file('gameScreen.kv')
Builder.load_file('mainMenu.kv')
if use_ads:
if platform() == 'android':
REVMOB_APP_ID = 'android_id'
elif platform() == 'ios':
REVMOB_APP_ID = 'ios_id'
else:
REVMOB_APP_ID = 'unknown platform for RevMob'
revmob.start_session(REVMOB_APP_ID)
class HexTap(App):
def __init__(self, **kwargs):
super(HexTap, self).__init__(**kwargs)
self.difficulty = 1
self.first_run = True
self.current_state = 'mainMenu'
self.content = BoxLayout()
self.main_menu = MainMenu()
self.help_menu = HelpMenu()
self.game_map = None
self.content.add_widget(self.main_menu)
self.music = SoundLoader.load('assets/audio/music.ogg')
self.soundsOption = True
self.musicOption = False
self.hardcoreOption = False
def safe_options_loading(self):
if type(self.soundsOption) == bool or type(self.soundsOption) == int:
pass
elif self.soundsOption == 'True' or '1' in self.soundsOption:
self.soundsOption = True
else:
self.soundsOption = False
if type(self.musicOption) == bool or type(self.musicOption) == int:
pass
elif self.musicOption == 'True' or '1' in self.musicOption:
self.musicOption = True
else:
self.musicOption = False
if type(self.hardcoreOption) == bool or type(self.hardcoreOption) == int:
pass
elif self.hardcoreOption == 'True' or '1' in self.hardcoreOption:
self.hardcoreOption = True
else:
self.hardcoreOption = False
def build(self):
self.use_kivy_settings = False
self.soundsOption = self.config.get('sound', 'soundsOption')
self.musicOption = self.config.get('sound', 'musicOption')
self.hardcoreOption = self.config.get('game', 'hardcoreOption')
self.safe_options_loading()
Clock.schedule_interval(self.update, 1. / 1.5)
return self.content
def show_help(self):
self.content.clear_widgets()
self.content.add_widget(self.help_menu)
def generate_main_menu(self):
self.content.clear_widgets()
self.content.add_widget(self.main_menu)
def new_game(self):
if use_ads:
revmob.show_popup()
self.content.clear_widgets()
self.content.add_widget(Image(source='assets/graphics/ui/loading.png', size=Window.size, allow_stretch=True))
Clock.schedule_once(self.post_splash)
def post_splash(self, dt):
rows, cols = map_sizes[self.difficulty-1]
self.game_map = MapCanvas(cols, rows, self.difficulty, self.hardcoreOption, self.soundsOption,
self.musicOption)
self.content.clear_widgets()
self.content.add_widget(self.game_map)
def update(self, dt):
if self.main_menu.start_game:
self.new_game()
self.main_menu.start_game = False
if self.main_menu.show_help:
self.show_help()
self.main_menu.show_help = False
if self.help_menu.back_to_main:
self.generate_main_menu()
self.help_menu.back_to_main = False
if self.game_map and self.game_map.return_to_menu:
self.generate_main_menu()
self.game_map.return_to_menu = False
if self.musicOption and self.music.state == 'stop':
self.music.play()
elif not self.musicOption and self.music.state == 'play':
self.music.stop()
def build_config(self, config):
try:
config.setdefaults('sound', {
'musicOption': '0',
'soundsOption': '1'
})
config.setdefaults('game', {
'hardcoreOption': '0'
})
except TypeError:
config.setdefaults('sound', {
'musicOption': False,
'soundsOption': True
})
config.setdefaults('game', {
'hardcoreOption': False
})
def build_settings(self, settings):
settings.add_json_panel('hexTap options', self.config, data=settings_json)
def on_config_change(self, config, section, key, value):
if key == 'musicOption':
if type(value) == bool or type(value) == int:
self.musicOption = value
elif value == 'True' or '1' in value:
self.musicOption = True
else:
self.musicOption = False
elif key == 'soundsOption':
if type(value) == bool or type(value) == int:
self.soundsOption = value
elif value == 'True' or '1' in value:
self.soundsOption = True
else:
self.soundsOption = False
elif key == 'hardcoreOption':
if type(value) == bool or type(value) == int:
self.hardcoreOption = value
elif value == 'True' or '1' in value:
self.hardcoreOption = True
else:
self.hardcoreOption = False
def on_pause(self):
return True
def on_resume(self):
pass
if __name__ == '__main__':
HexTap().run()