-
Notifications
You must be signed in to change notification settings - Fork 0
/
setting.py
531 lines (430 loc) · 16.2 KB
/
setting.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
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
# -*- coding: utf-8 -*-
"""
@author: zx013
"""
import os
from kivy.storage.dictstore import DictStore
class classproperty(property):
def __get__(self, cls, owner):
return classmethod(self.fget).__get__(None, owner)()
class Store:
store_name = 'setting.store'
store = DictStore(store_name)
@classmethod
def save(self):
self.store.put('setting',
base=Setting.base,
size=Setting.size,
difficult_type=Setting.difficult_type,
montecarlo=Setting.montecarlo,
show_health=Setting.show_health,
show_attack=Setting.show_attack,
show_defence=Setting.show_defence,
show_damage=Setting.show_damage,
touch=Setting.touch,
speed=Setting.speed,
keyboard_wasd=Setting.keyboard_wasd,
sound_back=Setting.sound_back,
sound_back_volume=Setting.sound_back_volume,
sound_effect=Setting.sound_effect,
sound_effect_volume=Setting.sound_effect_volume
)
@classmethod
def load(self, name, default=None):
if 'setting' not in self.store:
return default
return self.store.get('setting').get(name, default)
#全局设置
class Setting:
#标题
title = '无尽的魔塔'
#标题宽度
title_width = 24
#标题所在的圆的半径,越小越突出
title_radius = 28
#版本号
version = '2.0'
#图标路径
icon_path = os.path.join('data', 'icon.ico')
#字体路径
font_path_01 = os.path.join('data', 'font', 'font-01.ttf')
font_path_02 = os.path.join('data', 'font', 'font-02.ttf')
font_path = font_path_01
#难度,very-hard, hard, normal, easy, very-easy
#难度决定了蒙特卡洛模拟的次数,剩余的血量和初始的钥匙
difficult_config = {
'very-hard': {'montecarlo': 1000, 'remain_potion': 100, 'key': {}},
'hard': {'montecarlo': 500, 'remain_potion': 200, 'key': {}},
'normal': {'montecarlo': 100, 'remain_potion': 500, 'key': {'yellow': 1}},
'easy': {'montecarlo': 10, 'remain_potion': 1000, 'key': {'yellow': 1, 'blue': 1}},
'very-easy': {'montecarlo': 1, 'remain_potion': 3000, 'key': {'yellow': 1, 'blue': 1, 'red': 1}}
}
difficult_type = Store.load('difficult_type', 'normal')
difficult = difficult_config[difficult_type]
#状态栏初始显示
status_text = '欢迎来到无尽的魔塔,联系及反馈: [email protected]'
#状态栏高度
status_size = 0.05
#状态栏移动速度
status_speed = 50
#长按判定间隔
touch_step = 0.01
#到达时间后判定为长按
touch_time = 0.5
#旋转角度,0, 90, 180, 270
rotation = 0
#地图显示的偏移
offset = 0
#每个单元多少层
base = 10 #Store.load('base', 10)
#迷宫的大小,最小为3,最大不限,正常11,太大影响性能,最好为奇数
size = 11 #Store.load('size', 11)
#放缩倍数
multiple = 1.0
#每走多少步保存一次
step = 10
#每个点的大小(像素)
pos_size = 32
#较小的图片
pos_small = pos_size / 2
#转换rgb格式
@staticmethod
def rgb(*rgb):
return tuple(map(lambda x: x / 255, rgb))
#最终大小
@classproperty
def pos_real(self):
return int(self.pos_size * self.multiple)
#将pos_real按size放大
@classproperty
def pos_realx(self):
return self.pos_real * self.size / 11
#行数,从左上开始往下
@classproperty
def rows(self):
return self.size
#显示的行数,包括外面一圈墙
@classproperty
def row_show(self):
return self.rows + 2
#列数,从左上开始往右
@classproperty
def cols(self):
return self.size
#显示的列数,包括外面一圈墙
@classproperty
def col_show(self):
return self.cols + 2
#高度
@classproperty
def row_size(self):
return int(self.pos_size * self.row_show * self.multiple)
#宽度
@classproperty
def col_size(self):
return int(self.pos_size * self.col_show * self.multiple)
#转换x为绝对坐标
@classmethod
def pos_x(self, x):
return (x + 0.5 * self.pos_size) * self.row_show * self.multiple
#转换y为绝对坐标
@classmethod
def pos_y(self, y):
return (y + 0.5 * self.pos_size) * self.col_show * self.multiple
#蒙特卡洛模拟的次数,根据设备性能尽可能的增加,不小于难度的数值
montecarlo = Store.load('montecarlo', 1)
#击败boss后剩余血量不超过该值加100
remain_potion = 100
#是否显示怪物血量
show_health = Store.load('show_health', False)
#是否显示怪物攻击
show_attack = Store.load('show_attack', False)
#是否显示怪物防御
show_defence = Store.load('show_defence', False)
#是否在怪物上显示对应伤害
show_damage = Store.load('show_damage', True)
#触控还是虚拟按键
touch = Store.load('touch', True)
#移动速度(触控或鼠标操作时)
speed = Store.load('speed', 10)
#是否是wasd操作
keyboard_wasd = Store.load('keyboard_wasd', False)
#背景音乐
sound_back = Store.load('sound_back', True)
#背景音量
sound_back_volume = Store.load('sound_back_volume', 15)
#音效
sound_effect = Store.load('sound_back', True)
#音效音量
sound_effect_volume = Store.load('sound_effect_volume', 20)
#注意,出现random的属性,每次获取时值将不同
#迷宫设置
class MazeSetting:
#行
@classproperty
def rows(self):
return Setting.rows
#列
@classproperty
def cols(self):
return Setting.cols
#保存的目录
save_dir = 'save'
#保存的文件后缀
save_ext = 'save'
@staticmethod
def save_file(num):
return '{save_dir}/{num}.{save_ext}'.format(save_dir=MazeSetting.save_dir, num=num, save_ext=MazeSetting.save_ext)
#保存的层数,10时占用20M左右内存,100时占用50M左右内存
@classproperty
def save_floor(self):
return Setting.base
#每几层一个单元
@classproperty
def base_floor(self):
return Setting.base
#每个宝石增加的属性值(总属性百分比)
attribute_value = 0.01
#第一个怪物造成的最低伤害
damage_min = 500
#第一个怪物造成的最高伤害
damage_max = 1000
#精英怪物造成的最低伤害
elite_min = 1000
#精英怪物造成的最高伤害
elite_max = 2000
#boss造成的最低伤害
boss_min = 2000
#boss造成的最高伤害
boss_max = 5000
#某一类怪物不超过damage_total_num的数量低于damage_total_min
damage_total_num = 3
damage_total_min = 100
#蒙特卡洛模拟的次数,该值越大,越接近最优解,同时增加运行时间
@classproperty
def montecarlo(self):
return max(Setting.montecarlo, Setting.difficult['montecarlo'])
#使用近似最优解通关后至少剩余的额外的血量,可以用该参数调节难度
@classproperty
def remain_potion(self):
return max(Setting.remain_potion, Setting.difficult['remain_potion'])
@classproperty
def start_key(self):
return Setting.difficult['key']
#迷宫的基础属性
class MazeBase:
class Type:
class Static:
init = 11
ground = 12
wall = 13
shop = 14
stair = 15
door = 16
class Active:
monster = 21
npc = 22
class Item:
key = 31
potion = 32
attack = 33
defence = 34
sword = 35
shield = 36
holy = 37
other = 38
unknown = 99
class Value:
class Special:
boss = 1
trigger = 2
item = 3
shop = 4
branch = 5
class Wall:
rock = 1
earth = 2
stone = 3
magma = 4
star = 5
static = (rock, earth, stone)
dynamic = (magma, star)
total = (rock, earth, stone, magma, star)
class Shop:
gold = 1
experience = 2
class Stair:
up = 1
down = 2
#key和door的颜色
class Color:
none = 0
yellow = 1
blue = 2
red = 3
green = 4
prison = 5
trap = 6
total = (yellow, blue, red, green)
#起始时对应攻防平均属性的1%
class Gem:
small = 1
big = 3
large = 10
total = (small, big, large)
class Weapon:
iron = 8
silver = 10
stone = 12
gem = 14
sacred = 16
total = (iron, silver, stone, gem, sacred)
#起始时对应攻防平均属性的1%,设置太低会导致空间不够的情况,按初始默认的配置,总需求在30000左右
class Potion:
red = 50
blue = 200
yellow = 600
green = 1200
total = (red, blue, yellow, green)
class NodeType:
none = 0
area_normal = 1
area_corner = 2
Area = (area_normal, area_corner)
road_normal = 3
road_corner = 4
Road = (road_normal, road_corner)
@staticmethod
def get_key(pos_data):
pos_type, pos_value = pos_data
if pos_type == MazeBase.Type.Static.init:
pos_key = 'ground'
elif pos_type == MazeBase.Type.Static.ground:
pos_key = 'ground'
elif pos_type == MazeBase.Type.Static.wall:
pos_key = 'wall-{:0>2}'.format(pos_value)
elif pos_type == MazeBase.Type.Static.stair:
if pos_value == MazeBase.Value.Stair.down:
pos_key = 'stair-down'
elif pos_value == MazeBase.Value.Stair.up:
pos_key = 'stair-up'
elif pos_type == MazeBase.Type.Static.door:
if pos_value == MazeBase.Value.Color.yellow:
pos_key = 'door-yellow'
elif pos_value == MazeBase.Value.Color.blue:
pos_key = 'door-blue'
elif pos_value == MazeBase.Value.Color.red:
pos_key = 'door-red'
elif pos_value == MazeBase.Value.Color.green:
pos_key = 'door-green'
elif pos_type == MazeBase.Type.Item.key:
if pos_value == MazeBase.Value.Color.yellow:
pos_key = 'key-yellow'
elif pos_value == MazeBase.Value.Color.blue:
pos_key = 'key-blue'
elif pos_value == MazeBase.Value.Color.red:
pos_key = 'key-red'
elif pos_value == MazeBase.Value.Color.green:
pos_key = 'key-green'
elif pos_type == MazeBase.Type.Item.attack:
if pos_value == MazeBase.Value.Gem.small:
pos_key = 'gem-attack-small'
elif pos_value == MazeBase.Value.Gem.big:
pos_key = 'gem-attack-big'
elif pos_type == MazeBase.Type.Item.defence:
if pos_value == MazeBase.Value.Gem.small:
pos_key = 'gem-defence-small'
elif pos_value == MazeBase.Value.Gem.big:
pos_key = 'gem-defence-big'
elif pos_type == MazeBase.Type.Item.sword:
if pos_value == MazeBase.Value.Weapon.iron:
pos_key = 'sword-iron'
elif pos_value == MazeBase.Value.Weapon.silver:
pos_key = 'sword-silver'
elif pos_value == MazeBase.Value.Weapon.stone:
pos_key = 'sword-stone'
elif pos_value == MazeBase.Value.Weapon.gem:
pos_key = 'sword-gem'
elif pos_value == MazeBase.Value.Weapon.sacred:
pos_key = 'sword-sacred'
elif pos_type == MazeBase.Type.Item.shield:
if pos_value == MazeBase.Value.Weapon.iron:
pos_key = 'shield-iron'
elif pos_value == MazeBase.Value.Weapon.silver:
pos_key = 'shield-silver'
elif pos_value == MazeBase.Value.Weapon.stone:
pos_key = 'shield-stone'
elif pos_value == MazeBase.Value.Weapon.gem:
pos_key = 'shield-gem'
elif pos_value == MazeBase.Value.Weapon.sacred:
pos_key = 'shield-sacred'
elif pos_type == MazeBase.Type.Item.potion:
if pos_value == MazeBase.Value.Potion.red:
pos_key = 'potion-red'
elif pos_value == MazeBase.Value.Potion.blue:
pos_key = 'potion-blue'
elif pos_value == MazeBase.Value.Potion.yellow:
pos_key = 'potion-yellow'
elif pos_value == MazeBase.Value.Potion.green:
pos_key = 'potion-green'
elif pos_type == MazeBase.Type.Item.holy:
pos_key = 'holy'
elif pos_type == MazeBase.Type.Item.other:
pos_key = 'item-{}'.format(pos_value)
elif pos_type == MazeBase.Type.Active.monster:
pos_key = '-'.join(pos_value)
elif pos_type == MazeBase.Type.Active.npc:
pos_key = 'npc-{}'.format(pos_value)
return pos_key
@staticmethod
def get_attribute(pos_key):
attribute = {'key': {}}
if pos_key == 'key-yellow':
attribute['key'][MazeBase.Value.Color.yellow] = 1
elif pos_key == 'key-blue':
attribute['key'][MazeBase.Value.Color.blue] = 1
elif pos_key == 'key-red':
attribute['key'][MazeBase.Value.Color.red] = 1
elif pos_key == 'key-green':
attribute['key'][MazeBase.Value.Color.green] = 1
elif pos_key == 'gem-attack-small':
attribute['attack'] = MazeBase.Value.Gem.small
elif pos_key == 'gem-attack-big':
attribute['attack'] = MazeBase.Value.Gem.big
elif pos_key == 'gem-defence-small':
attribute['defence'] = MazeBase.Value.Gem.small
elif pos_key == 'gem-defence-big':
attribute['defence'] = MazeBase.Value.Gem.big
elif pos_key == 'sword-iron':
attribute['attack'] = MazeBase.Value.Weapon.iron
elif pos_key == 'sword-silver':
attribute['attack'] = MazeBase.Value.Weapon.silver
elif pos_key == 'sword-stone':
attribute['attack'] = MazeBase.Value.Weapon.stone
elif pos_key == 'sword-gem':
attribute['attack'] = MazeBase.Value.Weapon.gem
elif pos_key == 'sword-sacred':
attribute['attack'] = MazeBase.Value.Weapon.sacred
elif pos_key == 'shield-iron':
attribute['defence'] = MazeBase.Value.Weapon.iron
elif pos_key == 'shield-silver':
attribute['defence'] = MazeBase.Value.Weapon.silver
elif pos_key == 'shield-stone':
attribute['defence'] = MazeBase.Value.Weapon.stone
elif pos_key == 'shield-gem':
attribute['defence'] = MazeBase.Value.Weapon.gem
elif pos_key == 'shield-sacred':
attribute['defence'] = MazeBase.Value.Weapon.sacred
elif pos_key == 'potion-red':
attribute['health'] = MazeBase.Value.Potion.red
elif pos_key == 'potion-blue':
attribute['health'] = MazeBase.Value.Potion.blue
elif pos_key == 'potion-yellow':
attribute['health'] = MazeBase.Value.Potion.yellow
elif pos_key == 'potion-green':
attribute['health'] = MazeBase.Value.Potion.green
elif pos_key == 'holy':
attribute['health'] = 2000
elif pos_key.startswith('item-'):
attribute['item'] = pos_key.split('-')[1]
return attribute