/
display.py
1341 lines (1269 loc) · 48.2 KB
/
display.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
import curses
import pkmn_test
from pkmn_test import pokeStructs
import numpy as np
import save
from copy import deepcopy
import sys
import time
import random
import battle
import heapq
screen = curses.initscr()
screen.clear()
screen.refresh()
curses.noecho()
curses.curs_set(0)
screen.keypad(1)
curses.start_color()
dims = screen.getmaxyx()
def intro():
lines = [
'',
' ?:: MM ',
' M::::M ~~M :::: ',
' $N :::::::~~D:::::7 ',
' ~~~M::::::::::::::: ',
' :::::::7::::::7::::::::: ',
' ~:::::::::,D?O::::::::M ',
' 7~:::::::::II::::::::: ',
' N~~::::::N:::? :::~: D ',
' M+ $ ~::::O ',
' ~::D Z O~~:M M ',
' ~~~:: ',
' M~~~ IIIIIII MIIZ ',
' M:: I: I. I:::::M ',
' :~OZZ I+ 7 M:~~~~~: ',
' MOO:OZZ ?III :~~~~~~D ',
' M+::,OZ :O~~~~~~~ ',
' :::OOO::. III~~Z777?M ',
' 8O::::::::77Z~~~~~M ',
' M:::~8Z=~$M MM ',
' :::::~~~~~ ',
'',
'TogePy',
'2014 - Ross Kleiman'
]
for z, l in enumerate(lines):
screen.addstr((dims[0] - len(lines))/2 + z, (dims[1] - len(l))/2, l)
screen.refresh()
key = screen.getch()
if key == ord('q'):
screen.clear()
screen.refresh()
sys.exit()
else:
return
def menu():
screen.nodelay(0)
screen.clear()
selection = -1
option = 0
lines = ['Debug', 'Build', 'Train', 'Battle', 'Exit']
while selection < 0:
graphics = [0]*len(lines)
graphics[option] = curses.A_REVERSE
title = 'TogePy'
screen.addstr(0, (dims[1] - len(title))/2, title) #Show Title
for i, l in enumerate(lines):
screen.addstr((dims[0] - len(lines))/2 + i, (dims[1] - len(l))/2, l, graphics[i])
screen.refresh()
action = screen.getch()
if action == curses.KEY_UP:
option = (option - 1)%len(lines)
elif action == curses.KEY_DOWN:
option = (option + 1)%len(lines)
elif action == ord('\n'):
selection = option
elif action == ord('q'):
selection = action
screen.refresh()
screen.clear()
if selection == 0:
debug()
elif selection == 1:
build_menu()
elif selection == 2:
under_Construction()
menu()
elif selection == 3:
battle_menu()
else:
return
def debug():
screen.nodelay(0)
screen.clear()
selection = -1
option = 0
lines = ['Rand Team', 'Rand Poke', 'Rand Move', 'Rand Item', 'Rand Ability', 'Exit']
while selection < 0:
graphics = [0]*len(lines)
graphics[option] = curses.A_REVERSE
title = 'TogePy'
screen.addstr(0, (dims[1] - len(title))/2, title) #Show Title
for i, l in enumerate(lines):
screen.addstr((dims[0] - len(lines))/2 + i, (dims[1] - len(l))/2, l, graphics[i])
screen.refresh()
action = screen.getch()
if action == curses.KEY_UP:
option = (option - 1)%len(lines)
elif action == curses.KEY_DOWN:
option = (option + 1)%len(lines)
elif action == ord('\n'):
selection = option
elif action == ord('q'):
selection = action
screen.refresh()
screen.clear()
if selection == 0:
d_team(pkmn_test.random_Team())
debug()
elif selection == 1:
d_poke(pkmn_test.random_Poke())
debug()
elif 2 <= selection <= 4:
under_Construction()
debug()
else:
menu()
def d_team(team):
screen.nodelay(0)
screen.clear()
selection = -1
option = 0
while selection < 0:
screen.border()
tName = 'Team: '+team.Name
screen.addstr(1, (dims[1] - len(tName))/2, tName, curses.A_BOLD)
graphics = [0]*team.Nmems
graphics[option] = curses.A_BLINK
for i in xrange(1, team.Nmems + 1):
pk = team.get_Member(i)
Name = pk.Name
if len(Name) > 13:
d_Name = Name[0:10]+'...'
else:
d_Name = Name
screen.addstr(3*i+2, 1, d_Name, curses.A_BOLD | graphics[i - 1])
screen.addstr(3*i+2, 17, 'Lv. '+str(int(pk.Level)).rjust(3, ' '))
max_HP = pk.Stats['HP']
cur_HP = pk.CurHP
s_hp = 'HP: '+str(int(cur_HP)).rjust(3,' ')+'/'+str(int(max_HP)).ljust(3,' ')
x = np.ceil(cur_HP * 20. / max_HP)
screen.addstr(3*i+2, 27, s_hp)
screen.addstr(3*i+2, 39, '['+('X'*x).ljust(20, ' ')+']')
Item = str(pk.Item)
sts = str(pk.Status)
if sts == 'None':
sts = '---'
if len(Item) > 0:
hasItem = 1
else:
hasItem = 0
screen.addstr(3*i+2, 64, 'Item: ['+('X'*hasItem).ljust(1,' ')+']')
d_status = {'---':0, 'PSN':1, 'BRN':2, 'FZN':3, 'SLP':4, 'PAR':5}
curses.init_color(15, 500, 500, 500)
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_MAGENTA)
curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_RED)
curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_BLUE)
curses.init_pair(4, curses.COLOR_WHITE, 8)
curses.init_pair(5, curses.COLOR_WHITE, curses.COLOR_YELLOW)
screen.addstr(3*i+2, 76, sts, curses.color_pair(d_status[sts]))
screen.refresh()
action = screen.getch()
if action == curses.KEY_UP:
option = (option - 1)%team.Nmems
elif action == curses.KEY_DOWN:
option = (option + 1)%team.Nmems
elif action == ord('\n'):
selection = option
elif action == ord('q'):
selection = action
if selection == ord('q'):
return
else:
pk = team.get_Member(selection + 1)
d_poke(pk)
d_team(team)
screen.clear()
def d_poke(pk):
screen.nodelay(0)
screen.clear()
selection = -1
option = 0
while selection < 0:
screen.border()
screen.addstr(1, (dims[1] - len(pk.Name))/2, pk.Name, curses.A_BOLD)
screen.addstr(2, (dims[1] - 6)/2, 'Lv. '+str(int(pk.Level)).ljust(3, ' '))
max_HP = pk.Stats['HP']
cur_HP = pk.CurHP
s_hp = 'HP: '+str(int(cur_HP)).rjust(3,' ')+'/'+str(int(max_HP)).ljust(3,' ')
n = float(dims[1]-16)
x = np.ceil(cur_HP * n / max_HP)
screen.addstr(5, 1, s_hp)
screen.addstr(5, 13, '['+('X'*x).ljust(int(n), ' ')+']')
stats = {0:'HP', 1:'Atk', 2:'Def', 3:'SpA', 4:'SpD', 5:'Spe'}
vals = {0:' Stats ', 1:' EVs ', 2:' IVs '}
for i in xrange(6):
screen.vline(8, 6*i+9, 0, 7)
screen.addstr(8, 6*i+10, stats[i].center(5))
screen.addstr(10, 6*i+10, str(int(pk.Stats[stats[i]])).center(5))
screen.addstr(12, 6*i+10, str(int(pk.EVs[stats[i]])).center(5))
screen.addstr(14, 6*i+10, str(int(pk.IVs[stats[i]])).center(5))
for i in xrange(3):
screen.hline(2*i+9, 2, 0, 43)
screen.addstr(2*i+10, 2, vals[i])
t = ''
for x in pk.Type:
t += x.capitalize()+'/'
t = t[:-1]
screen.addstr(8, 50, 'Type: '+t)
screen.addstr(10, 50, 'Ability: '+pk.Ability.capitalize())
screen.addstr(12, 50, 'Nature: '+pk.NatureName)
screen.addstr(14, 50, 'Item: '+str(pk.Item))
for i in xrange(2):
for j in xrange(2):
m_Num = 2*j+i+1
move = pk.Moves.Moves[m_Num]
m_Name = move.Name
m_PP = str(move.CurPP)+'/'+str(move.PP)
m_Type = move.Type
m_Dmg = move.Damage.capitalize()
if move.Power == None:
m_Pwr = 'PWR: -'
else:
m_Pwr = 'PWR: '+str(int(move.Power))
if move.Accuracy == None:
m_Acc = 'ACC: -'
else:
m_Acc = 'ACC: '+str(int(move.Accuracy))
r1 = m_Name+' - '+m_PP
r2 = m_Type+' - '+m_Dmg
r3 = m_Pwr+' - '+m_Acc
screen.addstr(16+4*j, (2*i+1)*dims[1]/4-len(r1)/2, r1)
screen.addstr(17+4*j, (2*i+1)*dims[1]/4-len(r2)/2, r2)
screen.addstr(18+4*j, (2*i+1)*dims[1]/4-len(r3)/2, r3)
screen.refresh()
selection = screen.getch()
screen.clear()
def build_menu():
screen.nodelay(0)
screen.clear()
selection = -1
option = 0
lines = ['Build Poke', 'Build Team', 'Exit']
while selection < 0:
graphics = [0]*len(lines)
graphics[option] = curses.A_REVERSE
title = 'TogePy'
screen.addstr(0, (dims[1] - len(title))/2, title) #Show Title
for i, l in enumerate(lines):
screen.addstr((dims[0] - len(lines))/2 + i, (dims[1] - len(l))/2, l, graphics[i])
screen.refresh()
action = screen.getch()
if action == curses.KEY_UP:
option = (option - 1)%len(lines)
elif action == curses.KEY_DOWN:
option = (option + 1)%len(lines)
elif action == ord('\n'):
selection = option
elif action == ord('q'):
selection = action
screen.refresh()
screen.clear()
if selection == 0:
"Build Poke"
build_poke()
elif selection == 1:
"Build Team"
build_team()
else:
menu()
def build_poke():
screen.nodelay(0)
screen.clear()
dex = pkmn_test.pokedex
pk = [(x, dex[x].Name) for x in dex.keys()]
pk.sort()
levels = dict(zip(range(100), range(1, 101)))
natures = dict(zip(range(25),pkmn_test.nature_list()))
items = pkmn_test.items.keys()
items.sort()
items = ['None'] + items
moves = pkmn_test.moves.keys()
moves.sort()
moves = ['None'] + moves
selection = -1
option = 0
ev_op = 0
iv_op = 0
lines = ['Pokemon', 'Level', 'Nature', 'Happiness', 'EVs', 'IVs', 'Ability', 'Item', 'Move_1', 'Move_2', 'Move_3', 'Move_4', 'Save']
#Create dictionaries needed to support selections
vals = dict(zip(range(len(lines)), [0]*len(lines)))
ev_vals = dict(zip(range(6), [0]*6))
iv_vals = dict(zip(range(6), [0]*6))
strvals = dict(zip(range(len(lines)), ['']*len(lines)))
maxval = dict(zip(range(len(lines)), [1]*len(lines)))
#Set max unique values for each option
maxval[0] = len(pk)
maxval[1] = 100
maxval[2] = len(natures)
maxval[3] = 256
maxval[4] = 256
maxval[5] = 32
maxval[7] = len(items)
maxval[8] = len(moves)
maxval[9] = len(moves)
maxval[10] = len(moves)
maxval[11] = len(moves)
#Display stuff
curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_BLUE, curses.COLOR_BLACK)
while selection < 0:
graphics = [0]*len(lines)
graphics[option] = curses.A_REVERSE
ev_graphics = [0]*6
ev_graphics[ev_op] = curses.A_BOLD
iv_graphics = [0]*6
iv_graphics[iv_op] = curses.A_BOLD
screen.clear()
screen.border()
# Display Options
for i, l in enumerate(lines):
screen.addstr(i+1, 1, l, graphics[i])
# Update string values for each option
strvals[0] = '[' + str(pk[vals[0]][0]).rjust(3,'0') + '] ' + pk[vals[0]][1]
strvals[1] = str(levels[vals[1]])
strvals[2] = str(natures[vals[2]])
strvals[3] = str(vals[3])
abils = dex[vals[0]+1].Abilities
abils.sort()
maxval[6] = len(abils)
if (vals[6]+1) > maxval[6]:
vals[6] = 0
strvals[6] = abils[vals[6]]
strvals[7] = items[vals[7]]
strvals[8] = moves[vals[8]]
strvals[9] = moves[vals[9]]
strvals[10] = moves[vals[10]]
strvals[11] = moves[vals[11]]
# Display Values for each option
for i in range(len(lines)):
screen.addstr(i+1, len(lines[i])+2, strvals[i])
for i, s in enumerate([' HP: ', 'Atk: ', 'Def: ', 'SpA: ', 'SpD', 'Spe: ']):
screen.addstr(5, 9*i+4, s, ev_graphics[i])
screen.addstr(6, 9*i+4, s, iv_graphics[i])
screen.addstr(5, 9*i+9, str(ev_vals[i]).rjust(3,' '))
screen.addstr(6, 9*i+9, str(iv_vals[i]).rjust(3,' '))
# Create Pokemon
p_dex = dex[vals[0]+1]
lvl = levels[vals[1]]
EVs = pokeStructs.createEVs(ev_vals)
IVs = pokeStructs.createIVs(iv_vals)
Nature = natures[vals[2]]
Happiness = vals[3]
Ability = abils[vals[6]]
moveset = pokeStructs.Moveset()
for i in xrange(1, 5):
m = strvals[i + 7]
if m != 'None':
moveset.set_Move(i, pkmn_test.moves[m])
if strvals[7] != 'None':
Item = items[vals[7]]
else:
Item = False
poke = pokeStructs.Pokemon(p_dex, lvl, EVs, IVs, Nature, Happiness, Ability, moveset, Item)
# Display Pokemon Stats
for i, s in enumerate(['HP', 'Atk', 'Def', 'SpA', 'SpD', 'Spe']):
if poke.Nature[s] < 1.0:
col = curses.color_pair(2)
elif poke.Nature[s] > 1.0:
col = curses.color_pair(3)
else:
col = curses.color_pair(0)
screen.addstr(18, 9*i+11, s.rjust(3,' ')+': ')
screen.addstr(18, 9*i+16, str(int(poke.Stats[s])).rjust(3,' '), col)
# Handle user input selection
screen.refresh()
action = screen.getch()
if action == curses.KEY_LEFT:
if option == 4: #Special handling for EV
if ev_vals[ev_op] == 0 and sum(ev_vals.values()) + 255 <= 510:
ev_vals[ev_op] = (ev_vals[ev_op] - 1)%maxval[option]
elif ev_vals[ev_op] != 0:
ev_vals[ev_op] = (ev_vals[ev_op] - 1)%maxval[option]
else:
ev_vals[ev_op] = (510 - sum(ev_vals.values()))
elif option == 5: #Special handling for IV
iv_vals[iv_op] = (iv_vals[iv_op] - 1)%maxval[option]
else:
vals[option] = (vals[option]-1)%maxval[option]
elif action == curses.KEY_RIGHT:
if option == 4: #Special handling for EV
if sum(ev_vals.values()) < 510:
ev_vals[ev_op] = (ev_vals[ev_op] + 1)%maxval[option]
elif sum(ev_vals.values()) == 510 and ev_vals[ev_op] == 255:
ev_vals[ev_op] = (ev_vals[ev_op] + 1)%maxval[option]
else:
ev_vals[ev_op] = 0
elif option == 5: #Special handling for IV
iv_vals[iv_op] = (iv_vals[iv_op] + 1)%maxval[option]
else:
vals[option] = (vals[option]+1)%maxval[option]
elif action == curses.KEY_UP:
option = (option - 1)%len(lines)
elif action == curses.KEY_DOWN:
option = (option + 1)%len(lines)
elif action == 351: #SHIFT-TAB
if option == 4:
ev_op = (ev_op - 1)%6
elif option == 5:
iv_op = (iv_op - 1)%6
elif action == 9: #TAB
if option == 4:
ev_op = (ev_op + 1)%6
elif option == 5:
iv_op = (iv_op + 1)%6
elif action == ord('\n') and option == 12:
selection = 'save'
elif action == ord('q'):
selection = action
elif action == ord('d'):
d_poke(poke)
screen.refresh()
if selection == 'save':
save.save_Poke(poke)
screen.clear()
build_menu()
def build_team():
screen.nodelay(0)
screen.clear()
pk = ['None'] + save.get_Files('POKE')
selection = -1
option = 0
lines = ['Member_1', 'Member_2', 'Member_3', 'Member_4', 'Member_5', 'Member_6', 'Team Name', 'Save']
#Create dictionaries needed to support selections
vals = dict(zip(range(len(lines)), [0]*len(lines)))
strvals = dict(zip(range(len(lines)), ['']*len(lines)))
maxval = dict(zip(range(len(lines)), [1]*len(lines)))
#Set max unique values for each option
for i in range(6):
maxval[i] = len(pk)
while selection < 0:
# Display Static Information
graphics = [0]*len(lines)
graphics[option] = curses.A_REVERSE
screen.clear()
for i, l in enumerate(lines):
screen.addstr(i+1, 1, l, graphics[i])
screen.border()
# Update string values for each option
for i in range(6):
strvals[i] = pk[vals[i]]
# Display Current Choices
for i in range(len(lines)):
screen.addstr(i+1, len(lines[i])+2, strvals[i])
# Flush to Screne
screen.refresh()
# Create Pokemon and team
if strvals[6] == '':
tName = 'Unnamed Team'
else:
tName = strvals[6]
team = pokeStructs.Team(tName)
for i in range(6):
if strvals[i] != 'None':
poke = save.load_Poke(strvals[i])
team.set_Member(i+1, poke)
# Key Stuff
action = screen.getch()
if action == curses.KEY_UP:
option = (option - 1)%len(lines)
elif action == curses.KEY_DOWN:
option = (option + 1)%len(lines)
elif action == curses.KEY_LEFT:
vals[option] = (vals[option]-1)%maxval[option]
elif action == curses.KEY_RIGHT:
vals[option] = (vals[option]+1)%maxval[option]
elif action == ord('\n'):
if option in range(6):
poke = team.get_Member(option+1)
if poke != 'Position Empty':
d_poke(poke)
elif option == 6:
curses.echo()
screen.addstr(7, 11, '?')
strvals[6] = screen.getstr(7, 11)
curses.noecho()
screen.getch()
elif option == 7:
save.save_Team(team)
selection = action
elif action == ord('q'):
selection = action
elif action == ord('d'):
d_team(team)
screen.refresh()
screen.clear()
build_menu()
def battle_menu():
lines = ['Single', 'Double', 'Triple', 'Rotation', 'Exit']
selection = standard_menu(lines)
if selection in range(4): # Currently accounting for all 4 battle types
battle_opts = dict()
battle_opts['# Poke'] = [6, 1, 2, 3, 4, 5]
battle_opts['Items'] = [True, False]
battle_opts['Tier'] = ['Uber', 'Overused', 'Borderline', 'Underused', 'Borderline 2', 'Rarelyused', 'Neverused', 'Little Cup', 'Limbo', 'Not Fully Evolved']
battle_opts['Level'] = [50, 100, 'As Is']
battle_opts['Players'] = ['Human vs. CPU', 'CPU vs. CPU', 'Human vs. Human']
battle_vals = user_options(battle_opts, 'Battle Options')
if battle_vals['Players'] == 'Human vs. CPU':
p1_type = 'Human'
p2_type = 'CPU'
elif battle_vals['Players'] == 'CPU vs. CPU':
p1_type = 'CPU'
p2_type = 'CPU'
elif battle_vals['Players'] == 'Human vs. Human':
p1_type = 'Human'
p2_type = 'Human'
team1 = deepcopy(select_team('Player 1'))
team2 = deepcopy(select_team('Player 2'))
team1.init_battle(battle_vals)
team2.init_battle(battle_vals)
if int(battle_vals['# Poke']) == 6:
t1_members = dict(zip(range(6), [1]*6))
t2_members = dict(zip(range(6), [1]*6))
else:
t1_members = select_poke(team1, int(battle_vals['# Poke']))
t2_members = select_poke(team2, int(battle_vals['# Poke']))
team1_battle = pokeStructs.Team(team1.Name)
team1_battle.set_All([team1.get_Member(i+1) for i in t1_members.keys() if t1_members[i] == 1])
team2_battle = pokeStructs.Team(team2.Name)
team2_battle.set_All([team2.get_Member(i+1) for i in t2_members.keys() if t2_members[i] == 1])
player_1 = pokeStructs.Player(p1_type, team1_battle)
player_2 = pokeStructs.Player(p2_type, team2_battle)
left_field = pokeStructs.Field()
right_field = pokeStructs.Field()
main_field = pokeStructs.Field()
left = pokeStructs.Side(player_1, left_field)
right = pokeStructs.Side(player_2, right_field)
game = pokeStructs.Game(left, right, main_field)
battle_screen(game)
else:
menu()
def battle_screen(game):
def turn_setup():
screen.nodelay(0)
screen.clear()
box2.clear()
screen.border()
d_eevee(6, 6)
d_eevee(1, 55)
box1.box()
box2.box()
p1_box.box()
p2_box.box()
d_battle_pokes(player_1.poke, player_2.poke)
screen.refresh()
box1.refresh()
box2.refresh()
p1_box.refresh()
p2_box.refresh()
def turn_breakdown():
screen.refresh()
box1.refresh()
box2.refresh()
p1_box.refresh()
p2_box.refresh()
return
def pick_poke(player, can_quit=False):
team = player.team
fainted = team.battle_ready()
def human_choice():
poke_win = curses.newwin(25, 80, 0, 0)
selection = -1
option = 0
while selection < 0:
graphics = [0]*team.Nmems
graphics[option] = curses.A_BLINK
poke_win.clear()
poke_win.box()
tName = 'Team: '+team.Name
poke_win.addstr(1, (dims[1] - len(tName))/2, tName, curses.A_BOLD)
for i in xrange(1, team.Nmems + 1):
pk = team.get_Member(i)
Name = pk.Name
if len(Name) > 13:
d_Name = Name[0:10]+'...'
else:
d_Name = Name
poke_win.addstr(3*i+2, 1, d_Name, curses.A_BOLD | graphics[i - 1])
poke_win.addstr(3*i+2, 17, 'Lv. '+str(int(pk.Level)).rjust(3, ' '))
max_HP = pk.Stats['HP']
cur_HP = pk.CurHP
s_hp = 'HP: '+str(int(cur_HP)).rjust(3,' ')+'/'+str(int(max_HP)).ljust(3,' ')
x = np.ceil(cur_HP * 20. / max_HP)
poke_win.addstr(3*i+2, 27, s_hp)
poke_win.addstr(3*i+2, 39, '['+('X'*x).ljust(20, ' ')+']')
Item = str(pk.Item)
sts = str(pk.Status)
if sts == 'None':
sts = '---'
if len(Item) > 0:
hasItem = 1
else:
hasItem = 0
poke_win.addstr(3*i+2, 64, 'Item: ['+('X'*hasItem).ljust(1,' ')+']')
d_status = {'---':0, 'PSN':1, 'BRN':2, 'FZN':3, 'SLP':4, 'PAR':5}
curses.init_color(15, 500, 500, 500)
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_MAGENTA)
curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_RED)
curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_BLUE)
curses.init_pair(4, curses.COLOR_WHITE, 8)
curses.init_pair(5, curses.COLOR_WHITE, curses.COLOR_YELLOW)
poke_win.addstr(3*i+2, 76, sts, curses.color_pair(d_status[sts]))
screen.refresh()
poke_win.refresh()
action = screen.getch()
if action == curses.KEY_UP:
option = (option - 1)%team.Nmems
elif action == curses.KEY_DOWN:
option = (option + 1)%team.Nmems
elif action == ord('d'):
d_poke(team.get_Member(option+1))
poke_win.touchwin()
poke_win.refresh()
elif action == ord('\n'):
if fainted[option+1] == 'F':
invalid_option()
poke_win.touchwin()
poke_win.refresh()
else:
selection = option
elif action in [ord('q'), ord('b')]:
if can_quit:
selection = 'b'
else:
invalid_option()
poke_win.touchwin()
poke_win.refresh()
if selection == 'b':
poke_win.clear()
poke_win.refresh()
del poke_win
screen.refresh()
return 'b'
elif selection == ord('d'):
pk = team.get_Member(selection + 1)
d_poke(pk)
poke_win.clear()
del poke_win
return selection+1
def cpu_choice():
while True:
i = random.choice(fainted.keys())
if fainted[i] == 'A':
break
return i
if player.p_Type == 'Human':
return human_choice()
elif player.p_Type == 'CPU':
return cpu_choice()
def get_choices():
def human_choice(player):
q = False
Select = False
while Select == False:
act_1 = get_action_1()
if act_1 in ['q', 3]:
choice = 'q'
q = True
elif act_1 == 1:
choice = 'b'
invalid_option()
elif act_1 == 0:
choice = get_move(player.poke)
elif act_1 == 2:
choice = ('switch', pick_poke(player, True))
if choice[1] == 'b':
choice = 'b'
if choice == 'b':
turn_setup()
continue
elif choice == 'q':
Select = True
q = True
else:
Select = True
return q, choice
def cpu_choice(user, receiver):
moves = user.poke.Moves.Moves
m_Num = random.choice(range(1, 5))
choice = ('move', m_Num)
atker = user.poke
recvr = receiver.poke
max_dmg = 0
for m in range(1, 5):
try:
dmg = battle.calc_Damage(atker, recvr, moves[m])
except:
dmg = int(recvr.Stats['HP']*0.25)
if dmg > max_dmg:
max_dmg = dmg
choice = ('move', m)
#choice = tls_aStar(game, 2)
return choice
q = False
game.curActor = 'left'
if player_1.p_Type == 'Human':
q, p1_choice = human_choice(player_1)
elif player_1.p_Type == 'CPU':
p1_choice = cpu_choice(player_1, player_2)
box2.clear()
box2.box()
box2.refresh()
game.curActor = 'right'
if player_2.p_Type == 'Human':
q, p2_choice = human_choice(player_2)
elif player_2.p_Type == 'CPU':
p2_choice = cpu_choice(player_2, player_1)
box2.clear()
box2.box()
box2.refresh()
return p1_choice, p2_choice, q
def get_action_1():
box1_row = 0
box1_col = 0
box1_lines = ['Fight', '---', 'Pokemon', 'Run']
selection = -1
while selection < 0:
box1_option = 2*box1_col + box1_row
box1_graphics = [0]*4
box1_graphics[box1_option] = curses.A_REVERSE
box1.clear()
box1.box()
box1.addstr(2, 2, box1_lines[0], box1_graphics[0])
box1.addstr(2, 12, box1_lines[1], box1_graphics[1])
box1.addstr(4, 2, box1_lines[2], box1_graphics[2])
box1.addstr(4, 12, box1_lines[3], box1_graphics[3])
box1.refresh()
action = screen.getch()
if action == curses.KEY_UP:
box1_col = (box1_col - 1)%2
elif action == curses.KEY_DOWN:
box1_col = (box1_col + 1)%2
elif action == curses.KEY_LEFT:
box1_row = (box1_row - 1)%2
elif action == curses.KEY_RIGHT:
box1_row = (box1_row + 1)%2
elif action == ord('q'):
selection = 'q'
elif action == ord('\n'):
selection = box1_option
elif action == curses.KEY_MOUSE:
box1_col = (box1_col - 1)%2
else:
continue
return selection
def get_move(poke):
box2_row = 0
box2_col = 0
r1 = {}
r2 = {}
selection = -1
moves = poke.Moves.Moves
for i in xrange(2):
for j in xrange(2):
m_Num = 2*j+i+1
move = moves[m_Num]
m_Name = move.Name
m_PP = str(move.CurPP)+'/'+str(move.PP)
m_Type = move.Type
m_Dmg = move.Damage.capitalize()
if move.Power == None:
m_Pwr = 'PWR: -'
else:
m_Pwr = 'PWR: '+str(int(move.Power))
if move.Accuracy == None:
m_Acc = 'ACC: -'
else:
m_Acc = 'ACC: '+str(int(move.Accuracy))
r1[m_Num-1] = m_Name+' - '+m_PP
r2[m_Num-1] = m_Type+' - '+m_Dmg
while selection < 0:
box2_option = 2*box2_col + box2_row
box2_graphics = [0]*4
box2_graphics[box2_option] = curses.A_REVERSE
box2.clear()
box2.box()
for m_Num in range(4):
i = m_Num%2
j = m_Num/2
s1 = r1[m_Num]
s2 = r2[m_Num]
box2.addstr(1+3*j, (2*i+1)*box2_dims[1]/4-len(s1)/2, s1, box2_graphics[m_Num])
box2.addstr(2+3*j, (2*i+1)*box2_dims[1]/4-len(s2)/2, s2, box2_graphics[m_Num])
box2.refresh()
action = screen.getch()
if action == curses.KEY_UP:
box2_col = (box2_col - 1)%2
elif action == curses.KEY_DOWN:
box2_col = (box2_col + 1)%2
elif action == curses.KEY_LEFT:
box2_row = (box2_row - 1)%2
elif action == curses.KEY_RIGHT:
box2_row = (box2_row + 1)%2
elif action == ord('q'):
return 'q'
elif action == ord('b'):
return 'b'
elif action == ord('\n'):
if moves[box2_option+1].CurPP == 0:
invalid_option()
else:
selection = box2_option
else:
continue
return ('move', selection+1)
def d_battle_pokes(pk1, pk2):
def pk_lines(pk):
name = pk.Name
lv = str(int(pk.Level))
cur_hp = int(pk.CurHP)
max_hp = int(pk.Stats['HP'])
ws_1 = 24 - (len(name) + len(lv) + 2)
line1 = name + ' '*ws_1 + 'Lv' + lv
n_x = np.ceil(15 * cur_hp / max_hp)
line2 = ' '*5 + 'HP[' + 'X'*n_x + ' '*(15-n_x) + ']'
line3 = str(cur_hp) + '/' + str(max_hp)
line3 = line3.rjust(24)
lines = [line1, line2, line3]
return lines
def print_poke(box, lines):
box.addstr(1, 1, lines[0])
box.addstr(2, 1, lines[1])
box.addstr(3, 1, lines[2])
lines_1 = pk_lines(pk1)
lines_2 = pk_lines(pk2)
print_poke(p1_box, lines_1)
print_poke(p2_box, lines_2)
return
def d_eevee(y, x):
eevee = [';-. ,',
' \ \'. .\'/',
' \ \ .---. .-\' / ',
' \'. \' `\_.\' ',
' |(),() | ,',
' ( __ / .\' \\',
' .\'\'.___.\'--,/\_,|',
' { / \ } |',
' \'.\ /_.\' /',
' |\'-.-\', `; _.\'',
' | | | |`',
' `""`""`"""` ']
for i in range(len(eevee)):
screen.addstr(y + i, x, eevee[i])
def invalid_option():
inv_win = curses.newwin(3, 20, 11, 30)
inv_win.box()
inv_win.addstr(1, 1, 'Invalid Selection')
screen.refresh()
inv_win.refresh()
inv_win.getch()
inv_win.clear()
screen.refresh()
inv_win.refresh()
def get_turn_order(choice_1, choice_2):
priority_1 = battle.turn_priority(choice_1)
priority_2 = battle.turn_priority(choice_2)
if priority_1 < priority_2:
return 1
elif priority_2 < priority_1:
return 2
else:
return battle.compare_speed(player_1.poke, player_2.poke)
return
def execute_choice(choice, user, receiver):
if choice[0] == 'switch':
old_name = user.poke.Name
user.poke = user.team.get_Member(choice[1])
new_name = user.poke.Name
turn_setup()
box2.box()
box2.addstr(1, 1, old_name + ' return!')
box2.addstr(2, 1, new_name + ' go!')
box2.refresh()
screen.getch()
box2.clear()
box2.box()
box2.refresh()
elif choice[0] == 'move':
atker = user.poke
recvr = receiver.poke
move = user.poke.Moves.Moves[choice[1]]
move.CurPP -= 1
try:
dmg = battle.calc_Damage(atker, recvr, move)
except:
dmg = int(recvr.Stats['HP']*0.25)
box2.addstr(1, 1, atker.Name + ' used ' + move.Name + '.')
if battle.acc_check(move):
box2.addstr(2, 1, recvr.Name + ' took ' + str(dmg) + ' damage.')
recvr.mod_HP(-1*dmg)
else:
box2.addstr(2, 1, 'The attack missed!')
box2.refresh()
screen.getch()
box2.clear()
box2.box()
box2.refresh()
return
def game_over():
f1 = player_1.team.battle_ready()
n1 = sum([1 if (f1[k] == 'A') else 0 for k in f1.keys()])
f2 = player_2.team.battle_ready()
n2 = sum([1 if (f2[k] == 'A') else 0 for k in f2.keys()])
if (n1 == 0) or (n2 == 0):
return True
else:
return False
def end_game():
return
box1 = curses.newwin(7, 17, 17, 61)
box2 = curses.newwin(7, 57, 17, 2)
p1_box = curses.newwin(5, 26, 12, 52)
p2_box = curses.newwin(5, 26, 1, 2)
box1_dims = box1.getmaxyx()
box2_dims = box2.getmaxyx()
player_1 = game.left.player
player_2 = game.right.player
game.curActor = 'left'
player_1.poke = player_1.team.get_Member(pick_poke(player_1, False))
game.curActor = 'right'
player_2.poke = player_2.team.get_Member(pick_poke(player_2, False))
quit = False