-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilding.py
1008 lines (821 loc) · 34.9 KB
/
building.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 person import *
from headers import *
# from board import *
from king import *
townHall = [
list(" _ |~ _ "),
list("TOWN| |HALL"),
list("[_]--'--[_]"),
list("| | /^\ | |"),
list("|_|_|I|_|_|")
]
Hut_design = [
list("|-HUT-|"),
list("| |"),
list("_|_|_|_")
]
Cannon_design = [
list("^-__^"),
list("|CAN|")
]
Wizard_design = [
list("^-__^"),
list("|WIZ|")
]
# TOWNHALL HAS 150 VALUE WHICH IS DIVIDED IN 4 PARTS
# NORMAL HUT HAS 100 VALUE WHICH IS DIVIDED IN 3 PARTS
# Cannon has 80 value which is divided in 3 parts
# boundar coordinates of all buildings
BUILDING_REMAINING = 10
class TownHall(Person):
def __init__(self, x, y):
Person.__init__(self,x,y)
self.__lives=150
self.__destroy_flag = 0
self.__id = "T"
def set_destroy_flag(self):
self.__destroy_flag = 1
def get_destroy_flag(self):
return self.__destroy_flag
def reset_destroy_flag(self):
self.__destroy_flag = 0
def set_lives(self,x):
self.__lives=x
def get_lives(self):
return self.__lives
def hall_show(self, grid):
x = self.getx()
y = self.gety()
# print(x)
# print(y)
for i in range(y, y+len(townHall)):
row = []
for j in range(x, x+len(townHall[0])):
# print(i,j)
# print(i-y,j-x)
gridCopy[i][j] = 'T'
grid[i][j] = Fore.WHITE + Back.GREEN + Style.BRIGHT + townHall[i-y][j-x] + Style.RESET_ALL
def color_town(self,grid):
x = self.getx()
y = self.gety()
if(self.__lives<=100 and self.__lives>=50):
for i in range(y, y+len(townHall)):
for j in range(x, x+len(townHall[0])):
grid[i][j] = Fore.WHITE + Back.CYAN + Style.BRIGHT + townHall[i-y][j-x] + Style.RESET_ALL
# fuck.append(grid
if(self.__lives<50 and self.__lives>=20):
for i in range(y, y+len(townHall)):
for j in range(x, x+len(townHall[0])):
grid[i][j] = Fore.BLACK + Back.YELLOW + Style.BRIGHT + townHall[i-y][j-x] + Style.RESET_ALL
# fuck.append(grid[i][j])
if(self.__lives<20):
for i in range(y, y+len(townHall)):
for j in range(x, x+len(townHall[0])):
grid[i][j] = Fore.WHITE + Back.RED + Style.BRIGHT + townHall[i-y][j-x] + Style.RESET_ALL
def destroy(self, grid, arr):
x = self.getx()
y = self.gety()
global BUILDING_REMAINING
BUILDING_REMAINING = BUILDING_REMAINING-1
for i in range(y, y+len(arr)):
for j in range(x, x+len(arr[0])):
grid[i][j] = " "
def tabbah(self,grid,obj):
self.set_lives(self.get_lives() -
obj.show_damage_value())
os.system('aplay -q ./sounds/barbar_attack.wav&')
self.color_town(grid)
if(self.get_lives() <= 0):
self.destroy(grid,townHall)
clear_copy(ch=self.__id)
self.set_destroy_flag()
def balattck(self, grid, obj):
self.set_lives(self.get_lives()-obj.show_damage_value())
os.system('aplay -q ./sounds/bal_bomb.wav&')
self.color_town(grid)
if(self.get_lives() <= 0):
self.destroy(grid, townHall)
clear_copy(ch=self.__id)
self.set_destroy_flag()
def arrowattck(self, grid, obj):
self.set_lives(self.get_lives()-obj.show_damage_value())
os.system('aplay -q ./sounds/arrow.wav&')
self.color_town(grid)
if(self.get_lives() <= 0):
self.destroy(grid, townHall)
clear_copy(ch=self.__id)
self.set_destroy_flag()
class Huts(Person):
def __init__(self, x, y,id):
Person.__init__(self, x, y)
self.__lives = 100
self.__id = id
self.__destroy_flag = 0
def set_destroy_flag(self):
self.__destroy_flag = 1
def get_destroy_flag(self):
return self.__destroy_flag
def reset_destroy_flag(self):
self.__destroy_flag = 0
def get_id(self):
return self.__id
def set_lives(self, x):
self.__lives = x
def get_lives(self):
return self.__lives
def hut_show(self, grid):
x = self.getx()
y = self.gety()
# print(x)
# print(y)
for i in range(y, y+len(Hut_design)):
for j in range(x, x+len(Hut_design[0])):
# print(i, j)
# print(i-y, j-x)
gridCopy[i][j] = self.get_id()
grid[i][j] = Fore.WHITE + Back.GREEN + Style.BRIGHT + \
Hut_design[i-y][j-x] + Style.RESET_ALL
def color_hut(self,grid):
x = self.getx()
y = self.gety()
if(self.__lives<50 and self.__lives>=20):
for i in range(y, y+len(Hut_design)):
for j in range(x, x+len(Hut_design[0])):
grid[i][j] = Fore.BLACK + Back.YELLOW + Style.BRIGHT + \
Hut_design[i-y][j-x] + Style.RESET_ALL
if(self.__lives<20):
for i in range(y, y+len(Hut_design)):
for j in range(x, x+len(Hut_design[0])):
grid[i][j] = Fore.WHITE + Back.RED + Style.BRIGHT + \
Hut_design[i-y][j-x] + Style.RESET_ALL
# Polymorphism
def destroy(self,grid,arr):
x = self.getx()
y = self.gety()
global BUILDING_REMAINING
BUILDING_REMAINING = BUILDING_REMAINING-1
for i in range(y, y+len(arr)):
for j in range(x, x+len(arr[0])):
grid[i][j] = " "
def barbad(self,grid,obj):
self.set_lives(self.get_lives()-obj.show_damage_value())
os.system('aplay -q ./sounds/area_of_effect.wav&')
self.color_hut(grid)
if(self.get_lives() <= 0):
self.destroy(grid,Hut_design)
clear_copy(ch=self.__id)
self.set_destroy_flag()
def tabbah(self,grid,obj):
self.set_lives(self.get_lives() -
obj.show_damage_value())
os.system('aplay -q ./sounds/barbar_attack.wav&')
self.color_hut(grid)
if(self.get_lives() <= 0):
self.destroy(grid,Hut_design)
clear_copy(ch=self.__id)
self.set_destroy_flag()
def balattck(self, grid, obj):
self.set_lives(self.get_lives()-obj.show_damage_value())
os.system('aplay -q ./sounds/bal_bomb.wav&')
self.color_hut(grid)
if(self.get_lives() <= 0):
self.destroy(grid, Hut_design)
clear_copy(ch=self.__id)
self.set_destroy_flag()
def arrowattck(self, grid, obj):
self.set_lives(self.get_lives()-obj.show_damage_value())
os.system('aplay -q ./sounds/arrow.wav&')
self.color_hut(grid)
if(self.get_lives() <= 0):
self.destroy(grid, Hut_design)
clear_copy(ch=self.__id)
self.set_destroy_flag()
class cannon(Huts):
def __init__(self, x, y,id):
Huts.__init__(self, x, y,id)
self.__range = 8
self.__damageValue = 10
self.__lives = 80
self.__id = id
self.__destroy_flag = 0
def set_destroy_flag(self):
self.__destroy_flag = 1
def reset_destroy_flag(self):
self.__destroy_flag = 0
def get_destroy_flag(self):
return self.__destroy_flag
def set_lives(self, x):
self.__lives = x
def get_lives(self):
return self.__lives
def get_id(self):
return self.__id
def get_range(self):
return self.__range
def get_damageValue(self):
return self.__damageValue
def cannon_show(self, grid):
x = self.getx()
y = self.gety()
for i in range(y, y+len(Cannon_design)):
for j in range(x, x+len(Cannon_design[0])):
gridCopy[i][j] = self.get_id()
grid[i][j] = Fore.BLACK + Back.WHITE + Style.BRIGHT + \
Cannon_design[i-y][j-x] + Style.RESET_ALL
# def destroy(self,grid):
# x = self.getx()
# y = self.gety()
# global BUILDING_REMAINING
# BUILDING_REMAINING = BUILDING_REMAINING-1
# for i in range(y, y+len(Cannon_design)):
# for j in range(x, x+len(Cannon_design[0])):
# grid[i][j] = " "
def color_cannon(self,grid):
x = self.getx()
y = self.gety()
if(self.__lives<60 and self.__lives>=30):
for i in range(y, y+len(Cannon_design)):
for j in range(x, x+len(Cannon_design[0])):
grid[i][j] = Fore.BLACK + Back.YELLOW + Style.BRIGHT + \
Cannon_design[i-y][j-x] + Style.RESET_ALL
if(self.__lives<30):
for i in range(y, y+len(Cannon_design)):
for j in range(x, x+len(Cannon_design[0])):
grid[i][j] = Fore.WHITE + Back.RED + Style.BRIGHT + \
Cannon_design[i-y][j-x] + Style.RESET_ALL
def attack_can(self,grid,arr):
x = self.getx()
y = self.gety()
if(self.__lives>0):
dist = math.sqrt((x-arr.getx())**2 + (y-arr.gety())**2)
# fuck.append(dist)
if(dist<=self.__range):
if(arr.show_lives()>0):
os.system('aplay -q ./sounds/shoot.wav&')
arr.set_lives(arr.show_lives()-self.__damageValue)
if(arr.show_lives()<=0):
arr.set_destroy_flag()
grid[arr.gety()][arr.getx()] = " "
def barbad(self, grid, obj):
self.set_lives(self.get_lives()-obj.show_damage_value())
os.system('aplay -q ./sounds/area_of_effect.wav&')
self.color_cannon(grid)
if(self.get_lives() <= 0):
self.destroy(grid,Cannon_design)
clear_copy(ch=self.__id)
self.set_destroy_flag()
def tabbah(self, grid, obj):
self.set_lives(self.get_lives() -
obj.show_damage_value())
os.system('aplay -q ./sounds/barbar_attack.wav&')
self.color_cannon(grid)
if(self.get_lives() <= 0):
self.destroy(grid,Cannon_design)
clear_copy(ch=self.__id)
self.set_destroy_flag()
def balattck(self,grid,obj):
self.set_lives(self.get_lives()-obj.show_damage_value())
os.system('aplay -q ./sounds/bal_bomb.wav&')
self.color_cannon(grid)
if(self.get_lives() <= 0):
self.destroy(grid,Cannon_design)
clear_copy(ch=self.__id)
self.set_destroy_flag()
def arrowattck(self,grid,obj):
self.set_lives(self.get_lives()-obj.show_damage_value())
os.system('aplay -q ./sounds/arrow.wav&')
self.color_cannon(grid)
if(self.get_lives() <= 0):
self.destroy(grid,Cannon_design)
clear_copy(ch=self.__id)
self.set_destroy_flag()
class Barbarian(Person):
def __init__(self, x,y):
Person.__init__(self, x, y)
self.__health = 100
self.__body = np.array(['+'])
self.__damage_value = 10
self.__destroy_flag = 0
self.__mode = 0
self.__speed = 1
def set_destroy_flag(self):
self.__destroy_flag = 1
def get_destroy_flag(self):
return self.__destroy_flag
def get_speed(self):
return self.__speed
def set_speed(self):
self.__speed = 2*self.__speed
def show_lives(self):
return self.__health
def set_lives(self, x):
self.__health = x
def show_damage_value(self):
return self.__damage_value
def set_mode(self, x):
self.__mode = x
def show_mode(self):
return self.__mode
def bar_clear(self, grid):
x = self.getx()
y = self.gety()
# print(x)
grid[y][x] = " "
def bar_jump(self,grid,ch):
x = self.getx()
y = self.gety()
# print(x)
grid[y][x] = ch
def start_bar(self, grid):
x = self.getx()
y = self.gety()
for i in range(y, y+1):
for j in range(x, x+1):
grid[i][j] = self.__body[0][0]
def bar_show(self, grid, x, y):
# ch = grid[y][x]
self.bar_clear(grid)
self.setx(x)
self.sety(y)
# if(self.show_shield_flag() == 0):
for i in range(y, y+1):
for j in range(x, x+1):
grid[i][j] = self.__body[0][0]
def new_bar(self, grid):
# grid[self.getx()][self.gety()] = " "
self.sety(self.gety())
self.setx(self.getx())
self.bar_show(grid, self.getx(), self.gety(), self.show_mode())
def color_change(self,grid):
x = self.getx()
y = self.gety()
if(self.__health<=60 and self.__health>=30):
for i in range(y, y+1):
for j in range(x, x+1):
grid[i][j] = Fore.BLACK + Back.YELLOW + Style.BRIGHT + \
self.__body[0][0] + Style.RESET_ALL
if(self.__health<30):
for i in range(y, y+1):
for j in range(x, x+1):
grid[i][j] = Fore.WHITE + Back.RED + Style.BRIGHT + \
self.__body[0][0] + Style.RESET_ALL
if(self.__health<=0):
for i in range(y, y+1):
for j in range(x, x+1):
grid[i][j] = " "
def move(self, grid, array_cord, att):
ans = 100000
tarx = -1
tary = -1
x = self.getx()
y = self.gety()
# sx.append(Barb_arr[i].show_damage_value)
if(self.show_lives() > 0):
# array_cord = sorted(array_cord, key=lambda x: x[0]**2+x[1]**2)
for j in range(len(array_cord)):
dist = math.sqrt(
(y-array_cord[j][0])**2 + (x-array_cord[j][1])**2)
if dist < ans:
tarx = array_cord[j][0]
tary = array_cord[j][1]
ans = dist
# now barbaruan has min distance
if (abs(tarx-y) > abs(tary-x)):
# first remove the position of barbarian
# then set to new position tary (modified) tarx
self.bar_clear(grid)
if(tarx < y and y > 2 and y < 38):
if att == 0:
self.sety(y-self.get_speed())
# ch = grid[y-self.get_speed()][x]
self.bar_show(
grid, x, y-self.get_speed())
else:
self.bar_show(grid, x, y)
elif(tarx > y and y > 2 and y < 37):
if att == 0:
self.sety(y+self.get_speed())
self.bar_show(
grid, x, y+self.get_speed())
else:
self.bar_show(grid, x, y)
else:
# first remove the position of barbarian
# then set to new position tarx (modified) tary
self.bar_clear(grid)
if(tary > x and x > 1 and x < 197):
if att == 0:
self.setx(x+self.get_speed())
self.bar_show(
grid, x+self.get_speed(), y)
else:
self.bar_show(grid, x, y)
elif(tary < x and x > 1 and x < 198):
if att == 0:
self.setx(x-self.get_speed())
self.bar_show(
grid, x-self.get_speed(), y)
else:
self.bar_show(grid, x, y)
class Wizard(Huts):
def __init__(self,x,y,id):
Huts.__init__(self,x,y,id)
self.__range = 8
self.__damage_value = 10
self.__health = 80
self.__id = id
self.__destroy_flag = 0
def set_destroy_flag(self):
self.__destroy_flag = 1
def get_destroy_flag(self):
return self.__destroy_flag
def reset_destroy_flag(self):
self.__destroy_flag = 0
def set_lives(self, x):
self.__lives = x
def get_lives(self):
return self.__lives
def get_id(self):
return self.__id
def get_range(self):
return self.__range
def show_damage_value(self):
return self.__damage_value
def wizzard_show(self,grid):
x = self.getx()
y = self.gety()
for i in range(y, y+len(Wizard_design)):
for j in range(x, x+len(Wizard_design[0])):
gridCopy[i][j] = self.get_id()
grid[i][j] = Fore.WHITE + Back.MAGENTA + Style.BRIGHT + \
Wizard_design[i-y][j-x] + Style.RESET_ALL
def color_wizard(self, grid):
x = self.getx()
y = self.gety()
if(self.__lives < 60 and self.__lives >= 30):
for i in range(y, y+len(Wizard_design)):
for j in range(x, x+len(Wizard_design[0])):
grid[i][j] = Fore.BLACK + Back.YELLOW + Style.BRIGHT + \
Wizard_design[i-y][j-x] + Style.RESET_ALL
if(self.__lives < 30):
for i in range(y, y+len(Wizard_design)):
for j in range(x, x+len(Wizard_design[0])):
grid[i][j] = Fore.WHITE + Back.RED + Style.BRIGHT + \
Wizard_design[i-y][j-x] + Style.RESET_ALL
def attack_wiz(self, grid, arr):
x = self.getx()
y = self.gety()
flg = 0
if(arr.getx()>=x and arr.getx()<=x+len(Wizard_design[0]) and arr.gety()>=y and arr.gety()<=y+len(Wizard_design)):
flg = 1
if(self.__lives > 0 and flg == 0):
dist = math.sqrt((x-arr.getx())**2 + (y-arr.gety())**2)
trx = arr.getx()
tryy = arr.gety()
cnt =0;
if(dist <= self.__range):
for k in range(len(Barb_arr)):
if(Barb_arr[k].getx()==trx and Barb_arr[k].gety()==tryy):
cnt = cnt+1
for k in range(len(Arch_arr)):
if(Arch_arr[k].getx()==trx and Arch_arr[k].gety()==tryy):
cnt = cnt+1
if(cnt > 4):
for k in range(len(Barb_arr)):
if(Barb_arr[k].getx() == trx and Barb_arr[k].gety() == tryy):
Barb_arr[k].set_lives(0)
Barb_arr[k].set_destroy_flag()
for k in range(len(Arch_arr)):
if(Arch_arr[k].getx() == trx and Arch_arr[k].gety() == tryy):
Arch_arr[k].set_lives(0)
Arch_arr[k].set_destroy_flag()
# fuck.append(dist)
if(dist <= self.__range):
if(arr.show_lives() > 0):
os.system('aplay -q ./sounds/shoot.wav&')
arr.set_lives(arr.show_lives()-self.__damage_value)
if(arr.show_lives() <= 0):
arr.set_destroy_flag()
grid[arr.gety()][arr.getx()] = " "
def barbad(self, grid, obj):
self.set_lives(self.get_lives()-obj.show_damage_value())
os.system('aplay -q ./sounds/area_of_effect.wav&')
self.color_wizard(grid)
if(self.get_lives() <= 0):
self.destroy(grid, Wizard_design)
clear_copy(ch=self.__id)
self.set_destroy_flag()
def tabbah(self, grid, obj):
self.set_lives(self.get_lives() -
obj.show_damage_value())
os.system('aplay -q ./sounds/barbar_attack.wav&')
self.color_wizard(grid)
if(self.get_lives() <= 0):
self.destroy(grid, Wizard_design)
clear_copy(ch=self.__id)
self.set_destroy_flag()
def balattck(self, grid, obj):
self.set_lives(self.get_lives()-obj.show_damage_value())
os.system('aplay -q ./sounds/bal_bomb.wav&')
self.color_wizard(grid)
if(self.get_lives() <= 0):
self.destroy(grid, Wizard_design)
clear_copy(ch=self.__id)
self.set_destroy_flag()
def arrowattck(self, grid, obj):
self.set_lives(self.get_lives()-obj.show_damage_value())
os.system('aplay -q ./sounds/arrow.wav&')
self.color_wizard(grid)
if(self.get_lives() <= 0):
self.destroy(grid, Wizard_design)
clear_copy(ch=self.__id)
self.set_destroy_flag()
class Ballon(Person):
def __init__(self, x, y):
Person.__init__(self, x, y)
self.__health = 100
self.__body = np.array(['@'])
self.__damage_value = 20
self.__destroy_flag = 0
self.__mode = 0
self.__speed = 2
def set_destroy_flag(self):
self.__destroy_flag = 1
def get_destroy_flag(self):
return self.__destroy_flag
def get_speed(self):
return self.__speed
def set_speed(self):
self.__speed = 2*self.__speed
def show_lives(self):
return self.__health
def set_lives(self, x):
self.__health = x
def show_damage_value(self):
return self.__damage_value
def set_mode(self, x):
self.__mode = x
def show_mode(self):
return self.__mode
def bal_clear(self, grid):
x = self.getx()
y = self.gety()
# print(x)
grid[y][x] = " "
def start_bal(self, grid):
x = self.getx()
y = self.gety()
for i in range(y, y+1):
for j in range(x, x+1):
grid[i][j] = self.__body[0][0]
def bal_show(self, grid, x, y):
self.bal_clear(grid)
self.setx(x)
self.sety(y)
# if(self.show_shield_flag() == 0):
for i in range(y, y+1):
for j in range(x, x+1):
grid[i][j] = self.__body[0][0]
def new_bal(self, grid):
# grid[self.getx()][self.gety()] = " "
self.sety(self.gety())
self.setx(self.getx())
self.bal_show(grid, self.getx(), self.gety(), self.show_mode())
def color_change(self, grid):
x = self.getx()
y = self.gety()
if(self.__health <= 60 and self.__health >= 30):
for i in range(y, y+1):
for j in range(x, x+1):
grid[i][j] = Fore.BLACK + Back.CYAN + Style.BRIGHT + \
self.__body[0][0] + Style.RESET_ALL
if(self.__health < 30):
for i in range(y, y+1):
for j in range(x, x+1):
grid[i][j] = Fore.WHITE + Back.MAGENTA + Style.BRIGHT + \
self.__body[0][0] + Style.RESET_ALL
if(self.__health <= 0):
for i in range(y, y+1):
for j in range(x, x+1):
grid[i][j] = " "
def move(self, grid, array_cord, att):
ans = 100000
tarx = -1
tary = -1
x = self.getx()
y = self.gety()
array_cord = sorted(array_cord, key=lambda ar: (y-ar[0])**2 + (x-ar[1])**2)
# sx.append(Barb_arr[i].show_damage_value)
if(self.show_lives() > 0):
tarx = array_cord[0][0]
tary = array_cord[0][1]
if (abs(tarx-y) > abs(tary-x)):
# first remove the position of barbarian
# then set to new position tary (modified) tarx
self.bal_clear(grid)
if(tarx < y and y > 2 and y < 38):
if att == 0:
# self.sety(y-self.get_speed())
if(grid[y-3][x] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL and grid[y-2][x] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL and grid[y-1][x] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL):
self.bal_show(
grid, x-1, y)
elif(grid[y-1][x] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL):
self.bal_show(
grid, x, y-2)
elif(grid[y-2][x] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL):
self.bal_show(
grid, x, y-3)
else:
self.bal_show(grid, x, y-self.get_speed())
else:
self.bal_show(grid, x, y)
elif(tarx > y and y > 2 and y < 37):
if att == 0:
if(grid[y+3][x] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL and grid[y+2][x] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL and grid[y+1][x] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL):
self.bal_show(
grid, x+1, y)
elif(grid[y+1][x] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL):
self.bal_show(
grid, x, y+2)
elif(grid[y+2][x] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL):
self.bal_show(
grid, x, y+3)
else:
self.bal_show(grid, x, y+self.get_speed())
else:
self.bal_show(grid, x, y)
else:
# first remove the position of barbarian
# then set to new position tarx (modified) tary
self.bal_clear(grid)
if(tary > x and x > 1 and x < 197):
if att == 0:
if(grid[y][x+3] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL and grid[y][x+2] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL and grid[y][x+1] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL):
self.bal_show(
grid, x, y+1)
elif(grid[y][x+1] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL):
self.bal_show(
grid, x+2, y)
elif(grid[y][x+2] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL):
self.bal_show(
grid, x+3, y)
else:
self.bal_show(grid, x + self.get_speed(), y)
else:
self.bal_show(grid, x, y)
elif(tary < x and x > 1 and x < 198):
if att == 0:
if (grid[y][x-3] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL and grid[y][x-2] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL and grid[y][x-1] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL):
self.bal_show(
grid, x, y-1)
elif(grid[y][x-1] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL):
self.bal_show(
grid, x-2, y)
elif(grid[y][x-2] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL):
self.bal_show(
grid, x-3, y)
else:
self.bal_show(grid,x-self.get_speed(), y)
else:
self.bal_show(grid, x, y)
class Archer(Person):
def __init__(self, x, y):
Person.__init__(self, x, y)
self.__health = 50
self.__body = np.array(['*'])
self.__damage_value = 5
self.__destroy_flag = 0
self.__mode = 0
self.__speed = 2
def set_destroy_flag(self):
self.__destroy_flag = 1
def get_destroy_flag(self):
return self.__destroy_flag
def get_speed(self):
return self.__speed
def set_speed(self):
self.__speed = 2*self.__speed
def show_lives(self):
return self.__health
def set_lives(self, x):
self.__health = x
def show_damage_value(self):
return self.__damage_value
def set_mode(self, x):
self.__mode = x
def show_mode(self):
return self.__mode
def arch_clear(self, grid):
x = self.getx()
y = self.gety()
# print(x)
grid[y][x] = " "
def start_arch(self, grid):
x = self.getx()
y = self.gety()
for i in range(y, y+1):
for j in range(x, x+1):
grid[i][j] = self.__body[0][0]
def arch_show(self, grid, x, y):
# ch = grid[y][x]
self.arch_clear(grid)
self.setx(x)
self.sety(y)
# if(self.show_shield_flag() == 0):
for i in range(y, y+1):
for j in range(x, x+1):
grid[i][j] = self.__body[0][0]
def new_arch(self, grid):
# grid[self.getx()][self.gety()] = " "
self.sety(self.gety())
self.setx(self.getx())
self.arch_show(grid, self.getx(), self.gety(), self.show_mode())
def color_change(self, grid):
x = self.getx()
y = self.gety()
if(self.__health <= 30 and self.__health >= 15):
for i in range(y, y+1):
for j in range(x, x+1):
grid[i][j] = Fore.WHITE + Back.GREEN + Style.BRIGHT + \
self.__body[0][0] + Style.RESET_ALL
if(self.__health < 15):
for i in range(y, y+1):
for j in range(x, x+1):
grid[i][j] = Fore.WHITE + Back.RED + Style.BRIGHT + \
self.__body[0][0] + Style.RESET_ALL
if(self.__health <= 0):
for i in range(y, y+1):
for j in range(x, x+1):
grid[i][j] = " "
def move(self, grid, array_cord, att):
ans = 100000
tarx = -1
tary = -1
x = self.getx()
y = self.gety()
# sx.append(Barb_arr[i].show_damage_value)
if(self.show_lives() > 0):
for j in range(len(array_cord)):
dist = math.sqrt(
(y-array_cord[j][0])**2 + (x-array_cord[j][1])**2)
if dist < ans:
tarx = array_cord[j][0]
tary = array_cord[j][1]
ans = dist
# now barbaruan has min distance
if (abs(tarx-y) > abs(tary-x)):
# first remove the position of barbarian
# then set to new position tary (modified) tarx
self.arch_clear(grid)
if(tarx < y and y > 2 and y < 38):
if att == 0:
if(grid[y-3][x] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL and grid[y-2][x] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL and grid[y-1][x] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL):
self.arch_show(grid, x-1, y)
else:
grid[y-1][x] = " "
grid[y-2][x] = " "
self.arch_show(
grid, x, y-self.get_speed())
# ch = grid[y-self.get_speed()][x]
else:
self.arch_show(grid, x, y)
elif(tarx > y and y > 2 and y < 37):
if att == 0:
if(grid[y+3][x] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL and grid[y+2][x] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL and grid[y+1][x] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL):
self.arch_show(grid, x+1, y)
else:
grid[y+1][x] = " "
grid[y+2][x] = " "
self.sety(y+self.get_speed())
self.arch_show(
grid, x, y+self.get_speed())
else:
self.arch_show(grid, x, y)
else:
# first remove the position of barbarian
# then set to new position tarx (modified) tary
self.arch_clear(grid)
if(tary > x and x > 1 and x < 197):
if att == 0:
if(grid[y][x+3] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL and grid[y][x+2] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL and grid[y][x+1] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL):
self.arch_show(grid, x, y-1)
else:
grid[y][x+1] = " "
grid[y][x+2] = " "
self.setx(x+self.get_speed())
self.arch_show(
grid, x+self.get_speed(), y)
else:
self.arch_show(grid, x, y)
elif(tary < x and x > 1 and x < 198):
if att == 0:
if(grid[y][x-3] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL and grid[y][x-2] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL and grid[y][x-1] == Fore.WHITE + Back.RED + Style.BRIGHT + "#" + Style.RESET_ALL):
self.arch_show(grid, x, y+1)
else: