-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
2327 lines (2257 loc) · 105 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
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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from kivy import app
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.core.window import Window
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.properties import ObjectProperty, StringProperty, NumericProperty, BooleanProperty, ListProperty
from kivy.uix.checkbox import CheckBox
from kivy.uix.spinner import Spinner
from kivy.uix.recycleview import RecycleView
from kivy.config import Config
from kivy.clock import Clock
from kivy.metrics import dp, sp
from kivy.storage.jsonstore import JsonStore
from settings_json import settings_json
import datetime
import random
import math
import json
import datetime
import os
import data # this louds our variables from data.py
Config.set('graphics', 'resizable', True)
class PhaseScreen(Screen):
I = BooleanProperty(True)
II = BooleanProperty(False)
III = BooleanProperty(False)
stagecheck = BooleanProperty(True)
blighted = BooleanProperty(False)
prevM = StringProperty()
prevP = StringProperty()
nextP = StringProperty()
phaseEmpty = BooleanProperty()
currentP = StringProperty('Main')
title = StringProperty('Spirit Island Phase Tracker')
next_button_value = StringProperty('')
time = StringProperty('')
setupScreens = BooleanProperty(True)
ehealth = StringProperty('1')
edamage = StringProperty('1')
thealth = StringProperty('2')
tdamage = StringProperty('2')
chealth = StringProperty('3')
cdamage = StringProperty('3')
dhealth = StringProperty('2')
ddamage = StringProperty('2')
def on_enter(self):
app = App.get_running_app()
app.currentPhase = 'Main'
self.next_button_value = 'Start'
if app.use_timer:
self.seconds = app.timer_seconds
self.time = ''
self.time = ':'.join(str(datetime.timedelta(seconds=self.seconds)).split(':')[1:])
self.clock = Clock.schedule_interval(self.timer, 1)
else:
self.time = ''
self.calc_health_damage()
def on_leave(self):
Clock.unschedule(self.clock)
def __init__(self, **kwargs):
super(PhaseScreen, self).__init__(**kwargs)
Window.bind(on_key_down=self._on_keyboard_down)
def _on_keyboard_down(self, instance, keyboard, keycode, other, other1):
if keycode == 40 or keycode == 128: # 40 - Enter key pressed
phase = App.get_running_app().root.get_screen('Phase').ids.PhaseManager #.get_screen(app.currentPhase).ids.RV
phase.current = self.on_next_Phase()
def on_next_Phase(self):
app = App.get_running_app()
self.calc_health_damage()
if app.currentPhase == 'Main':
app.previousPhase.append(app.currentPhase)
elif app.previousPhase[-1] != app.currentPhase:
app.previousPhase.append(app.currentPhase)
if app.currentPhase == 'Main':
nextP = 'SpiritSelect'
if app.currentPhase == 'SpiritSelect':
nextP = 'MapLayout'
if app.currentPhase == 'MapLayout':
nextP = 'BoardSetup'
if app.currentPhase == 'BoardSetup':
nextP = 'SpiritSetup'
if app.currentPhase == 'SpiritSetup':
nextP = 'FirstExplore'
if app.currentPhase == 'FirstExplore':
nextP = 'Growth'
if app.currentPhase == 'Growth':
nextP = 'Energy'
if app.currentPhase == 'Energy':
nextP = 'PowerCards'
if app.currentPhase == 'PowerCards':
nextP = 'FastPower'
if app.currentPhase == 'FastPower':
if app.blight != 'Healthy' and app.blightscreeninactive == False:
nextP = 'BlightedIsland'
elif app.expansion == 'None':
nextP = 'Fear'
else:
nextP = 'Event'
if app.currentPhase == 'BlightedIsland':
if app.expansion == 'None':
nextP = 'Fear'
else:
nextP = 'Event'
if app.currentPhase == 'Event':
nextP = 'Fear'
if app.currentPhase == 'Fear':
England3 = False
England4 = False
for x in range(len(app.opponents)):
if app.opponents[x] == 'England' and int(app.levels[x]) == 3:
England3 = True
elif app.opponents[x] == 'England' and int(app.levels[x]) >=4:
England4 = True
if England3 == True and app.stage != "III" and app.turn > 2:
nextP = 'HighImmigration'
elif England4 == True and app.turn > 2:
nextP = 'HighImmigration'
elif app.turn > 1:
nextP = 'Ravage'
else:
nextP = 'Build'
if app.currentPhase == 'HighImmigration':
if app.turn > 1:
nextP = 'Ravage'
else:
nextP = 'Build'
if app.currentPhase == 'Ravage':
nextP = 'Build'
if app.currentPhase == 'Build':
nextP = 'Explore'
if app.currentPhase == 'Explore':
nextP = 'AdvanceCards'
if app.currentPhase == 'AdvanceCards':
nextP = 'SlowPower'
if app.currentPhase == 'SlowPower':
nextP = 'TimePasses'
if app.currentPhase == 'TimePasses':
nextP = 'Growth'
self.title = app.screenTitles[nextP]
self.currentP = nextP
self.start_clock()
if nextP == 'Main':
self.next_button_value = 'Start'
self.setupScreens = True
elif nextP == 'SpiritSelect':
self.next_button_value = 'Next'
self.setupScreens = True
elif nextP == 'MapLayout':
self.next_button_value = 'Next'
self.setupScreens = True
elif nextP == 'BoardSetup':
self.next_button_value = 'Next'
self.setupScreens = True
elif nextP == 'SpiritSetup':
self.next_button_value = 'Begin Game'
self.setupScreens = True
else:
self.next_button_value = 'Next Phase'
self.setupScreens = False
return nextP
def start_clock(self):
app = App.get_running_app()
if app.use_timer:
Clock.unschedule(self.clock)
self.seconds = app.timer_seconds
self.time = ':'.join(str(datetime.timedelta(seconds=self.seconds)).split(':')[1:])
self.clock = Clock.schedule_interval(self.timer, 1)
else:
self.time = ''
def on_back(self):
app = App.get_running_app()
if app.currentPhase == 'Growth':
app.turn = app.turn - 1
self.start_clock()
prev = app.previousPhase[-1]
self.title = app.screenTitles[prev]
if prev != 'Main':
app.previousPhase.pop()
self.currentP = prev
if prev == 'Main':
self.next_button_value = 'Start'
self.setupScreens = True
elif prev == 'SpiritSelect':
self.next_button_value = 'Next'
self.setupScreens = True
elif prev == 'MapLayout':
self.next_button_value = 'Next'
self.setupScreens = True
elif prev == 'BoardSetup':
self.next_button_value = 'Next'
self.setupScreens = True
elif prev == 'SpiritSetup':
self.next_button_value = 'Begin Game'
self.setupScreens = True
else:
self.next_button_value = 'Next Phase'
self.setupScreens = False
return prev
def blight_checkbox(self, value):
app = App.get_running_app()
if value:
app.blight = 'Blighted'
self.blighted = True
write_state(self)
return True
else:
app.blight = 'Healthy'
self.blighted = False
write_state(self)
return False
def calc_health_damage(self):
app = App.get_running_app()
self.ehealth = '1'
self.edamage = '1'
self.thealth = '2'
self.tdamage = '2'
self.chealth = '3'
self.cdamage = '3'
self.dhealth = '2'
self.ddamage = '2'
for x in range(len(app.opponents)):
self.ehealth = str(int(self.ehealth) + app.opponentmod_rules[app.opponents[x]][int(app.levels[x])][0])
self.edamage = str(int(self.edamage) + app.opponentmod_rules[app.opponents[x]][int(app.levels[x])][4])
self.thealth = str(int(self.thealth) + app.opponentmod_rules[app.opponents[x]][int(app.levels[x])][1])
self.tdamage = str(int(self.tdamage) + app.opponentmod_rules[app.opponents[x]][int(app.levels[x])][5])
self.chealth = str(int(self.chealth) + app.opponentmod_rules[app.opponents[x]][int(app.levels[x])][2])
self.cdamage = str(int(self.cdamage) + app.opponentmod_rules[app.opponents[x]][int(app.levels[x])][6])
self.dhealth = str(int(self.dhealth) + app.opponentmod_rules[app.opponents[x]][int(app.levels[x])][3])
self.ddamage = str(int(self.ddamage) + app.opponentmod_rules[app.opponents[x]][int(app.levels[x])][7])
time = StringProperty()
def timer(self, *args):
app = App.get_running_app()
if app.use_timer:
if self.seconds == 0:
self.time = '0'
self.time_disp = "0"
Clock.unschedule(self.clock)
else:
self.seconds -= 1
self.time = ':'.join(str(datetime.timedelta(seconds=self.seconds)).split(':')[1:])
else:
self.time = ''
def on_stage_toggle(self, value):
app = App.get_running_app()
app.stage = value
if app.stage == 'I':
self.I = True
self.II = False
self.III = False
elif app.stage == 'II':
self.II = True
self.I = False
self.III = False
elif app.stage == 'III':
self.III = True
self.I = False
self.II = False
app.on_stage_toggle(app.stage)
write_state(self)
def read_state(self):
app = App.get_running_app()
store = get_data_store(self)
app.branchandclaw = (store.get('branchandclaw')['value'])
app.jaggedearth = (store.get('jaggedearth')['value'])
app.promopack1 = (store.get('promopack1')['value'])
app.promopack2 = (store.get('promopack2')['value'])
app.expansion = (store.get('expansion')['value'])
app.opponents = (store.get('opponents')['value'])
app.thematic = (store.get('thematic')['value'])
app.extraboard = (store.get('extraboard')['value'])
app.spirits = (store.get('spirits')['value'])
app.aspects = (store.get('aspects')['value'])
app.scenario = (store.get('scenario')['value'])
app.levels = (store.get('levels')['value'])
app.stage = (store.get('stage')['value'])
app.blight = (store.get('blight')['value'])
app.players = (store.get('players')['value'])
app.fear_tokens = (store.get('fear_tokens')['value'])
app.turn = (store.get('turn')['value'])
app.previousPhase = (store.get('previousPhase')['value'])
app.opponent_list = (store.get('opponent_list')['value'])
app.spirit_list = (store.get('spirit_list')['value'])
app.scenarios_list = (store.get('scenarios_list')['value'])
app.difficulty = (store.get('difficulty')['value'])
app.currentPhase = app.previousPhase[-1]
app.fromLoad = True
self.calc_health_damage()
app.stage2_flag['Scotland'] = 'If the invader card has a flag:\nOn the single board with the most coastal towns/cities add one town to the '+ str(app.players) +' lands with the fewest towns.\n'
app.loss_rules['Habsburg'] = 'Loss condition: Track how many blight come off the blight cards during ravages that do 8+ damage to the land. If that number ever exceeds ' + str(app.players) +' , the invaders win.\n'
if app.blight != 'Healthy':
self.blighted = True
else:
self.blighted = False
self.on_stage_toggle(app.stage)
if app.currentPhase == 'Main':
nextP = 'SpiritSelect'
if app.currentPhase == 'SpiritSelect':
nextP = 'MapLayout'
if app.currentPhase == 'MapLayout':
nextP = 'BoardSetup'
if app.currentPhase == 'BoardSetup':
nextP = 'SpiritSetup'
if app.currentPhase == 'SpiritSetup':
nextP = 'FirstExplore'
if app.currentPhase == 'FirstExplore':
nextP = 'Growth'
if app.currentPhase == 'Growth':
nextP = 'Energy'
if app.currentPhase == 'Energy':
nextP = 'PowerCards'
if app.currentPhase == 'PowerCards':
nextP = 'FastPower'
if app.currentPhase == 'FastPower':
if app.blight != 'Healthy' and app.blightscreeninactive == False:
nextP = 'BlightedIsland'
elif app.expansion == 'None':
nextP = 'Fear'
else:
nextP = 'Event'
if app.currentPhase == 'BlightedIsland':
if app.expansion == 'None':
nextP = 'Fear'
else:
nextP = 'Event'
if app.currentPhase == 'Event':
nextP = 'Fear'
if app.currentPhase == 'Fear':
England3 = False
England4 = False
for x in range(len(app.opponents)):
if app.opponents[x] == 'England' and int(app.levels[x]) == 3:
England3 = True
elif app.opponents[x] == 'England' and int(app.levels[x]) >=4:
England4 = True
if England3 == True and app.stage != "III" and app.turn > 2:
nextP = 'HighImmigration'
elif England4 == True and app.turn > 2:
nextP = 'HighImmigration'
elif app.turn > 1:
nextP = 'Ravage'
else:
nextP = 'Build'
if app.currentPhase == 'HighImmigration':
if app.turn > 1:
nextP = 'Ravage'
else:
nextP == 'Build'
if app.currentPhase == 'Ravage':
nextP = 'Build'
if app.currentPhase == 'Build':
nextP = 'Explore'
if app.currentPhase == 'Explore':
nextP = 'AdvanceCards'
if app.currentPhase == 'AdvanceCards':
nextP = 'SlowPower'
if app.currentPhase == 'SlowPower':
nextP = 'TimePasses'
if app.currentPhase == 'TimePasses':
nextP = 'Growth'
self.title = app.screenTitles[nextP]
self.currentP = nextP
self.start_clock()
if nextP == 'Main':
self.next_button_value = 'Start'
self.setupScreens = True
elif nextP == 'SpiritSelect':
self.next_button_value = 'Next'
self.setupScreens = True
elif nextP == 'MapLayout':
self.next_button_value = 'Next'
self.setupScreens = True
elif nextP == 'BoardSetup':
self.next_button_value = 'Next'
self.setupScreens = True
elif nextP == 'SpiritSetup':
self.next_button_value = 'Begin Game'
self.setupScreens = True
else:
self.next_button_value = 'Next Phase'
self.setupScreens = False
return nextP
class HistoryScreen(Screen):
jsondata = {}
def on_enter(self):
gameHistory = []
app = App.get_running_app()
rv = app.root.get_screen('History').ids.HISTORYRV
try:
historystore = os.path.join(app.user_data_dir, 'history.json')
with open(historystore, 'r+') as history:
try:
self.jsondata = json.load(history)
except:
self.jsondata = {}
history.close()
except:
self.jsondata = {}
for key in self.jsondata:
h_opponents = self.jsondata[key]['opponents']
h_levels = self.jsondata[key]['levels']
h_spirits = self.jsondata[key]['spirits']
h_scenario = self.jsondata[key]['scenario']
h_difficulty = self.jsondata[key]['difficulty']
h_winloss = self.jsondata[key]['winloss']
gameHistory.append({
'h_opp1': h_opponents[0],
'h_opp2': h_opponents[1],
'h_opp1_icon': app.icons[h_opponents[0]],
'h_opp2_icon': app.icons[h_opponents[1]],
'h_lvl1': h_levels[0],
'h_lvl2': h_levels[1],
'h_spirits1_icon': app.icons[h_spirits[0]],
'h_spirits2_icon': app.icons[h_spirits[1]],
'h_spirits3_icon': app.icons[h_spirits[2]],
'h_spirits4_icon': app.icons[h_spirits[3]],
'h_spirits5_icon': app.icons[h_spirits[4]],
'h_spirits6_icon': app.icons[h_spirits[5]],
'h_diff': str(h_difficulty),
'h_winloss': h_winloss,
'key': key
})
rv.data = gameHistory
def on_leave(self, *args):
app = App.get_running_app()
app.historykey = ''
def historytoggle(self, key):
app = App.get_running_app()
app.historykey = key
app.gamehistory = ''
app.gamehistory= app.gamehistory + self.jsondata[key]['reason'] + ' '
app.gamehistory= app.gamehistory + self.jsondata[key]['winloss']
app.gamehistory= app.gamehistory + ' in ' + str(self.jsondata[key]['turn']) + ' turns\n'
app.gamehistory= app.gamehistory + 'The island was ' + self.jsondata[key]['blight'] + '\n'
app.gamehistory= app.gamehistory + 'Difficulty: ' + self.jsondata[key]['difficulty'] + '\n\n'
if self.jsondata[key]['opponents'][0] != 'None':
app.gamehistory= app.gamehistory + 'Adversary: ' + self.jsondata[key]['opponents'][0]
app.gamehistory= app.gamehistory + ' Level ' + self.jsondata[key]['levels'][0] + '\n'
if self.jsondata[key]['opponents'][1] != 'None':
app.gamehistory= app.gamehistory + 'Adversary: ' + self.jsondata[key]['opponents'][1]
app.gamehistory= app.gamehistory + ' Level ' + self.jsondata[key]['levels'][1] + '\n'
if self.jsondata[key]['scenario'] != 'None':
app.gamehistory= app.gamehistory + 'Scenario: ' + self.jsondata[key]['scenario'] + '\n'
app.gamehistory= app.gamehistory + '\n'
app.gamehistory= app.gamehistory + 'Number of Players: ' + str(self.jsondata[key]['players']) + '\n'
for x in range(int(self.jsondata[key]['players'])):
if self.jsondata[key]['spirits'][x] != 'None':
app.gamehistory= app.gamehistory + 'Spirit: ' + self.jsondata[key]['spirits'][x]
if self.jsondata[key]['aspects'][x] != 'None':
app.gamehistory= app.gamehistory + ' with aspect ' + self.jsondata[key]['aspects'][x]
if self.jsondata[key]['playernames'][x] != '':
app.gamehistory= app.gamehistory + ' played by ' + self.jsondata[key]['playernames'][x]
app.gamehistory= app.gamehistory + '\n'
app.gamehistory= app.gamehistory + '\n'
app.gamehistory= app.gamehistory + 'Expansions:\n'
if self.jsondata[key]['branchandclaw'] == True:
app.gamehistory= app.gamehistory + " Branch and Claw\n"
if self.jsondata[key]['jaggedearth'] == True:
app.gamehistory= app.gamehistory + " Jagged Earth\n"
if self.jsondata[key]['promopack1'] == True:
app.gamehistory= app.gamehistory + " Promo Pack 1\n"
if self.jsondata[key]['promopack2'] == True:
app.gamehistory= app.gamehistory + " Promo Pack 2\n"
app.gamehistory= app.gamehistory + '\n'
app.gamehistory= app.gamehistory + 'Game Options:\n'
if self.jsondata[key]['extraboard'] == True:
app.gamehistory= app.gamehistory + " Extra Board\n"
if self.jsondata[key]['thematic'] == True:
app.gamehistory= app.gamehistory + "Thematic Map\n"
if self.jsondata[key]['notokens'] == True:
app.gamehistory= app.gamehistory + "No Tokens\n"
app.gamehistory= app.gamehistory + '\n\n'
app.gamehistory= app.gamehistory + 'Played on ' + key + '\n'
def replaygame(self, key):
app = App.get_running_app()
app.expansion = self.jsondata[key]['expansion']
app.branchandclaw = self.jsondata[key]['branchandclaw']
app.jaggedearth = self.jsondata[key]['jaggedearth']
app.promopack1 = self.jsondata[key]['promopack1']
app.promopack2 = self.jsondata[key]['promopack2']
app.spirits = self.jsondata[key]['spirits']
app.aspects = self.jsondata[key]['aspects']
app.players = self.jsondata[key]['players']
app.opponents = self.jsondata[key]['opponents']
app.levels = self.jsondata[key]['levels']
app.scenario = self.jsondata[key]['scenario']
app.thematic = self.jsondata[key]['thematic']
app.notokens = self.jsondata[key]['notokens']
app.extraboard = self.jsondata[key]['extraboard']
app.difficulty = self.jsondata[key]['difficulty']
app.root.get_screen('Phase').ids.PhaseManager.get_screen('Main').on_enter()
app.root.get_screen('Phase').ids.PhaseManager.get_screen('SpiritSelect').on_enter()
app.root.get_screen('Phase').ids.PhaseManager.get_screen('Main').on_enter()
app.root.current = 'Phase'
class ChallengeScreen(Screen):
pass
#mainscreen holder. all variables come from the MainApp
#corresponds to kivy Main
class MainScreen(Screen):
bc = BooleanProperty(False)
je = BooleanProperty(False)
pp1 = BooleanProperty(False)
pp2 = BooleanProperty(False)
theme = BooleanProperty(False)
extrab = BooleanProperty(False)
opp = ListProperty(['None', 'None'])
lvl = ListProperty(['',''])
play = StringProperty('1')
max_play = ListProperty(['1','2','3','4'])
max_levels = ListProperty([['0'],['0']])
next = StringProperty('BoardSetup')
opp_list = ListProperty()
scen_list = ListProperty()
diff = StringProperty('0')
notoke = BooleanProperty(False)
notoken_disabled = BooleanProperty(True)
scen = StringProperty('None')
def on_enter(self):
app = App.get_running_app()
self.scen_list = app.scenarios_list
app.currentPhase = 'Main'
if app.branchandclaw:
self.bc = True
self.je = app.jaggedearth
self.pp1 = app.promopack1
self.pp2 = app.promopack2
self.opp = app.opponents
self.play = str(app.players)
self.lvl = app.levels
self.theme = app.thematic
self.extrab = app.extraboard
self.opp_list = sorted(app.opponent_list)
self.opp_list.append(self.opp_list.pop(self.opp_list.index('None')))
self.opp_list.append(self.opp_list.pop(self.opp_list.index('Random')))
self.diff = app.difficulty
self.notoke = app.notokens
self.scen = app.scenario
def bc_clicked(self, value):
app = App.get_running_app()
if value == True:
app.branchandclaw = True
else:
app.branchandclaw = False
self.build_expansions()
self.build_spirits()
self.build_scenarios()
for x in range(len(self.opp)):
if self.opp[x] not in self.opp_list:
self.opponent_clicked(x, 'None')
self.eval_tokens()
def je_clicked(self, value):
app = App.get_running_app()
if value == True:
app.jaggedearth = True
else:
app.jaggedearth = False
self.build_expansions()
self.build_spirits()
self.build_scenarios()
for x in range(len(self.opp)):
if self.opp[x] not in self.opp_list:
self.opponent_clicked(x, 'None')
if self.play not in self.max_play:
self.players_clicked('0')
self.eval_tokens()
def promo1_clicked(self, value):
app = App.get_running_app()
if value == True:
app.promopack1 = True
else:
app.promopack1 = False
self.build_expansions()
self.build_spirits()
self.build_scenarios()
for x in range(len(self.opp)):
if self.opp[x] not in self.opp_list:
self.opponent_clicked(x, 'None')
def promo2_clicked(self, value):
app = App.get_running_app()
if value == True:
app.promopack2 = True
else:
app.promopack2 = False
self.build_expansions()
self.build_spirits()
self.build_scenarios()
for x in range(len(self.opp)):
if self.opp[x] not in self.opp_list:
self.opponent_clicked(x, 'None')
def thematic_clicked(self, value):
app = App.get_running_app()
if value == True:
app.thematic = True
else:
app.thematic = False
self.notoke = False
app.notoke = False
self.calculate_difficulty()
self.eval_tokens()
def eval_tokens(self):
app = App.get_running_app()
if app.thematic == True and (app.branchandclaw == True or app.jaggedearth == True):
self.notoken_disabled = False
else:
self.notoken_disabled = True
def notokens_clicked(self, value):
app = App.get_running_app()
self.notoke = value
app.notokens = value
self.calculate_difficulty()
def extraboard_clicked(self,value):
app = App.get_running_app()
if value == True:
app.extraboard = True
else:
app.extraboard = False
self.calculate_difficulty()
def opponent_clicked(self, num, value):
app = App.get_running_app()
if(value == 'Random'):
rlist = app.opponent_list[:]
rlist.remove('Random')
rlist.remove('None')
value = random.choice(rlist)
self.opp[num] = value
app.opponents[num] = value
self.opp[num] = value
self.build_levels(num)
self.lvl[num] = app.levels[num]
if self.opp[num] == 'None':
self.level_clicked(num, '0')
self.calculate_difficulty()
def scenario_clicked(self, value):
app = App.get_running_app()
self.scen = value
app.scenario = value
self.calculate_difficulty()
def level_clicked(self, num, value):
app = App.get_running_app()
app.levels[num] = value
self.lvl[num] = app.levels[num]
self.calculate_difficulty()
def players_clicked(self, value):
app = App.get_running_app()
app.players = value
self.play = app.players
app.stage2_flag['Scotland'] = 'If the invader card has a flag:\nOn the single board with the most coastal towns/cities add one town to the '+ str(app.players) +' lands with the fewest towns.\n'
app.loss_rules['Habsburg'] = 'Loss condition: Track how many blight come off the blight cards during ravages that do 8+ damage to the land. If that number ever exceeds ' + str(app.players) +' , the invaders win.\n'
def build_expansions(self):
app = App.get_running_app()
self.max_play = ['1','2','3','4']
app.opponent_list = app.base_opp
if app.branchandclaw:
app.opponent_list = app.opponent_list + app.bc_opp
if app.jaggedearth:
app.opponent_list = app.opponent_list + app.je_opp
self.max_play = ['1','2','3','4','5','6']
if app.promopack2:
app.opponent_list = app.opponent_list + app.pp2_opp
self.opp_list = sorted(app.opponent_list)
self.opp_list.append(self.opp_list.pop(self.opp_list.index('None')))
self.opp_list.append(self.opp_list.pop(self.opp_list.index('Random')))
if app.branchandclaw and app.jaggedearth:
app.expansion = "BC and JE"
elif app.branchandclaw and not app.jaggedearth:
app.expansion = "Branch and Claw"
elif app.jaggedearth and not app.branchandclaw:
app.expansion = "Jagged Earth"
else:
app.expansion = 'None'
def build_spirits(self):
app = App.get_running_app()
app.spirit_list = app.base_spirits
if app.branchandclaw:
app.spirit_list = app.spirit_list + app.bc_spirits
if app.jaggedearth:
app.spirit_list = app.spirit_list + app.je_spirits
if app.promopack1:
app.spirit_list = app.spirit_list + app.pp1_spirits
if app.promopack2:
app.spirit_list = app.spirit_list + app.pp2_spirits
app.spirit_list = sorted(app.spirit_list)
app.spirit_list.append(app.spirit_list.pop(app.spirit_list.index('None')))
app.spirit_list.append(app.spirit_list.pop(app.spirit_list.index('Random')))
def build_scenarios(self):
app = App.get_running_app()
scenario_list = app.base_scenarios
app.scenarios_list = app.base_scenarios
if app.branchandclaw:
app.scenarios_list = app.scenarios_list + app.bc_scenarios
if app.jaggedearth:
app.scenarios_list = app.scenarios_list + app.je_scenarios
if app.promopack1:
app.scenarios_list = app.scenarios_list + app.pp1_scenarios
if app.promopack2:
app.scenarios_list = app.scenarios_list + app.pp2_scenarios
self.scen_list = sorted(app.scenarios_list)
self.scen_list.append(self.scen_list.pop(self.scen_list.index('None')))
self.calculate_difficulty()
def build_levels(self, num):
app = App.get_running_app()
if app.opponents[num] == 'None':
self.max_levels[num] = ['0']
else:
self.max_levels[num] = ['0','1','2','3','4','5','6']
def calculate_difficulty(self):
app = App.get_running_app()
d1 = app.opponent_difficulty[app.opponents[0]][int(app.levels[0])]
d2 = app.opponent_difficulty[app.opponents[1]][int(app.levels[1])]
ds = app.scenario_difficulty[app.scenario]
dh = max(d1,d2)
dl = 0.5 * float(min(d1,d2))
dl = math.ceil(dl)
ad = float(dh) + dl
if app.thematic == True:
if app.branchandclaw == False and app.jaggedearth == False:
ad = ad + 3
else:
if self.notoke == True:
ad = ad + 3
else:
ad = ad + 1
if app.extraboard:
eb = ad/3
eb = math.ceil(eb)
ad = ad + eb + 2
self.diff = str(int(ad + ds))
app.difficulty = self.diff
class SpiritSelectScreen(Screen):
spirit_values = ListProperty([])
play = NumericProperty(1)
spirit1 = StringProperty('')
spirit2 = StringProperty('')
spirit3 = StringProperty('')
spirit4 = StringProperty('')
spirit5 = StringProperty('')
spirit6 = StringProperty('')
aspect1 = StringProperty('')
aspect2 = StringProperty('')
aspect3 = StringProperty('')
aspect4 = StringProperty('')
aspect5 = StringProperty('')
aspect6 = StringProperty('')
spirit1_aspects = ListProperty([])
spirit1_has_aspect = BooleanProperty(False)
spirit2_aspects = ListProperty([])
spirit2_has_aspect = BooleanProperty(False)
spirit3_aspects = ListProperty([])
spirit3_has_aspect = BooleanProperty(False)
spirit4_aspects = ListProperty([])
spirit4_has_aspect = BooleanProperty(False)
spirit5_aspects = ListProperty([])
spirit5_has_aspect = BooleanProperty(False)
spirit6_aspects = ListProperty([])
spirit6_has_aspect = BooleanProperty(False)
def on_enter(self):
app = App.get_running_app()
## Testing Deck Calculator. Uncomment one or two lines to see the invader and fear decks
#app.scotland_decks(4)
#app.russia_decks(4)
#app.england_decks(4)
#app.bp_decks(4)
#app.sweden_decks(4)
#app.france_decks(4)
#app.habsburg_decks(4)
self.spirit_values = sorted(app.spirit_list)
self.spirit_values.append(self.spirit_values.pop(self.spirit_values.index('None')))
self.spirit_values.append(self.spirit_values.pop(self.spirit_values.index('Random')))
app.currentPhase = 'SpiritSelect'
write_state(self)
self.play = int(app.players)
self.spirit1 = app.spirits[0]
self.spirit2 = app.spirits[1]
self.spirit3 = app.spirits[2]
self.spirit4 = app.spirits[3]
self.spirit5 = app.spirits[4]
self.spirit6 = app.spirits[5]
self.aspect1 = app.aspects[0]
self.aspect2 = app.aspects[1]
self.aspect3 = app.aspects[2]
self.aspect4 = app.aspects[3]
self.aspect5 = app.aspects[4]
self.aspect6 = app.aspects[5]
def on_select_spirit(self, player, value):
app = App.get_running_app()
rselect = False
if player == 1:
if(value == 'Random'):
rselect = True
rlist = app.spirit_list[:]
rlist.remove('Random')
rlist.remove('None')
value = random.choice(rlist)
if len(app.spirit_aspects[value]) == 0:
self.spirit1_has_aspect = False
else:
self.spirit1_aspects = []
for item in app.spirit_aspects[value]:
if app.branchandclaw:
if item.split(':')[0] == 'bc':
self.spirit1_aspects.append(item.split(':')[1])
if app.jaggedearth:
if item.split(':')[0] == 'je':
self.spirit1_aspects.append(item.split(':')[1])
if app.promopack1:
if item.split(':')[0] == 'pp1':
self.spirit1_aspects.append(item.split(':')[1])
if app.promopack2:
if item.split(':')[0] == 'pp2':
self.spirit1_aspects.append(item.split(':')[1])
if len(self.spirit1_aspects) == 0:
self.spirit1_has_aspect = False
else:
self.spirit1_has_aspect = True
self.spirit1_aspects = ['None'] + self.spirit1_aspects
if rselect == True:
alist = self.spirit1_aspects[:]
#alist.remove('None')
aspvalue = random.choice(alist)
self.aspect1 = aspvalue
app.aspects[0] = aspvalue
self.aspect1 = app.aspects[0]
self.spirit1 = value
app.spirits[0] = value
self.spirit1 = app.spirits[0]
if player == 2:
if(value == 'Random'):
rselect = True
rlist = app.spirit_list[:]
rlist.remove('Random')
rlist.remove('None')
value = random.choice(rlist)
if len(app.spirit_aspects[value]) == 0:
self.spirit2_has_aspect = False
else:
self.spirit2_aspects = []
for item in app.spirit_aspects[value]:
if app.branchandclaw:
if item.split(':')[0] == 'bc':
self.spirit2_aspects.append(item.split(':')[1])
if app.jaggedearth:
if item.split(':')[0] == 'je':
self.spirit2_aspects.append(item.split(':')[1])
if app.promopack1:
if item.split(':')[0] == 'pp1':
self.spirit2_aspects.append(item.split(':')[1])
if app.promopack2:
if item.split(':')[0] == 'pp2':
self.spirit2_aspects.append(item.split(':')[1])
if len(self.spirit2_aspects) == 0:
self.spirit2_has_aspect = False
else:
self.spirit2_has_aspect = True
self.spirit2_aspects = ['None'] + self.spirit2_aspects
if rselect == True:
alist = self.spirit2_aspects[:]
#alist.remove('None')
aspvalue = random.choice(alist)
self.aspect2 = aspvalue
app.aspects[1] = aspvalue
self.aspect2 = app.aspects[1]
self.spirit2 = value
app.spirits[1] = value
self.spirit2 = app.spirits[1]
if player == 3:
if(value == 'Random'):
rselect = True
rlist = app.spirit_list[:]
rlist.remove('Random')
rlist.remove('None')
value = random.choice(rlist)
if len(app.spirit_aspects[value]) == 0:
self.spirit3_has_aspect = False
else:
self.spirit3_aspects = []
for item in app.spirit_aspects[value]:
if app.branchandclaw:
if item.split(':')[0] == 'bc':
self.spirit3_aspects.append(item.split(':')[1])
if app.jaggedearth:
if item.split(':')[0] == 'je':
self.spirit3_aspects.append(item.split(':')[1])
if app.promopack1:
if item.split(':')[0] == 'pp1':
self.spirit3_aspects.append(item.split(':')[1])
if app.promopack2:
if item.split(':')[0] == 'pp2':
self.spirit3_aspects.append(item.split(':')[1])
if len(self.spirit3_aspects) == 0:
self.spirit3_has_aspect = False
else:
self.spirit3_has_aspect = True
self.spirit3_aspects = ['None'] + self.spirit3_aspects
if rselect == True:
alist = self.spirit3_aspects[:]
#alist.remove('None')
aspvalue = random.choice(alist)
self.aspect3 = aspvalue
app.aspects[2] = aspvalue
self.aspect3 = app.aspects[2]
self.spirit3 = value
app.spirits[2] = value
self.spirit3 = app.spirits[2]
if player == 4:
if(value == 'Random'):
rselect = True
rlist = app.spirit_list[:]
rlist.remove('Random')
rlist.remove('None')
value = random.choice(rlist)
if len(app.spirit_aspects[value]) == 0:
self.spirit4_has_aspect = False
else:
self.spirit4_aspects = []
for item in app.spirit_aspects[value]:
if app.branchandclaw:
if item.split(':')[0] == 'bc':
self.spirit4_aspects.append(item.split(':')[1])
if app.jaggedearth:
if item.split(':')[0] == 'je':
self.spirit4_aspects.append(item.split(':')[1])
if app.promopack1:
if item.split(':')[0] == 'pp1':
self.spirit4_aspects.append(item.split(':')[1])
if app.promopack2:
if item.split(':')[0] == 'pp2':
self.spirit4_aspects.append(item.split(':')[1])
if len(self.spirit4_aspects) == 0:
self.spirit4_has_aspect = False
else:
self.spirit4_has_aspect = True
self.spirit4_aspects = ['None'] + self.spirit4_aspects
if rselect == True:
alist = self.spirit4_aspects[:]
#alist.remove('None')
aspvalue = random.choice(alist)
self.aspect4 = aspvalue
app.aspects[3] = aspvalue
self.aspect4 = app.aspects[3]
self.spirit4 = value
app.spirits[3] = value
self.spirit4 = app.spirits[3]
if player == 5:
if(value == 'Random'):
rselect = True
rlist = app.spirit_list[:]
rlist.remove('Random')
rlist.remove('None')
value = random.choice(rlist)
if len(app.spirit_aspects[value]) == 0:
self.spirit5_has_aspect = False
else:
self.spirit5_aspects = []
for item in app.spirit_aspects[value]:
if app.branchandclaw:
if item.split(':')[0] == 'bc':
self.spirit5_aspects.append(item.split(':')[1])
if app.jaggedearth:
if item.split(':')[0] == 'je':
self.spirit5_aspects.append(item.split(':')[1])
if app.promopack1:
if item.split(':')[0] == 'pp1':
self.spirit5_aspects.append(item.split(':')[1])
if app.promopack2:
if item.split(':')[0] == 'pp2':
self.spirit5_aspects.append(item.split(':')[1])
if len(self.spirit5_aspects) == 0:
self.spirit5_has_aspect = False
else:
self.spirit5_has_aspect = True
self.spirit5_aspects = ['None'] + self.spirit5_aspects
if rselect == True:
alist = self.spirit5_aspects[:]
#alist.remove('None')
aspvalue = random.choice(alist)
self.aspect5 = aspvalue
app.aspects[4] = aspvalue
self.aspect5 = app.aspects[4]
self.spirit5 = value
app.spirits[4] = value
self.spirit5 = app.spirits[4]
if player == 6: