-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
160 lines (135 loc) · 3.84 KB
/
game.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
import sys
import os
sys.path.append('./src')
import get_input
import village
import king
from map import printMap, showKingHealth, update_map
from characters import spawnBarbarian, move_barbarians, spawnArcher, move_archers, spawnDragon, move_dragons, spawnBalloon, move_balloons, clearTroops
from buildings import shoot_cannons, shoot_wizard_towers
from spells import rage_spell, heal_spell
import points as pt
getch = get_input.Get()
cnt = 0
level = 1
V = village.createVillage(level)
def Phealth(health_bar):
if(King.health > 0):
print()
character = ""
if(pt.hero == 0):
character = "King's"
elif(pt.hero == 1):
character = "Queen's"
print(character+ ' Health: ', end='')
for i in range(len(health_bar)):
print(health_bar[i], end='')
print('')
os.system('clear')
print("Choose your Movement:\n1. Break walls\n2. Don't break walls if possible")
ch = int(input("Enter Choice: "))
if ch == 1:
pt.movement = 2
elif ch == 2:
pt.movement = 1
os.system('clear')
print("Choose your Hero:\n1. Barbarian King\n2. Archer Queen")
ch = int(input("Enter Choice: "))
if ch == 1:
pt.hero = 0
elif ch == 2:
pt.hero = 1
King = king.getHero(pt.hero)
os.system('clear')
printMap(V)
Phealth(showKingHealth(King.health))
def init_level(level):
global V,King,cnt
cnt = 0
V = village.createVillage(level)
os.system('clear')
print("Choose your Hero:\n1. Barbarian King\n2. Archer Queen")
ch = int(input("Enter Choice: "))
if ch == 1:
pt.hero = 0
elif ch == 2:
pt.hero = 1
King = king.getHero(pt.hero)
os.system('clear')
clearTroops()
printMap(V)
Phealth(showKingHealth(King.health))
# clear terminal
# #reposition cursor to top left
# print("\033[%d;%dH" % (0, 0), end='')
# while True:
# pass
while(True):
cnt += 1
ch = get_input.input_to(getch)
if ch == 'w':
King.move('up', V)
elif ch == 's':
King.move('down', V)
elif ch == 'a':
King.move('left', V)
elif ch == 'd':
King.move('right', V)
elif ch == '1':
King.specialAttack(V)
elif ch == ' ':
King.normalAttack(V)
elif ch == 'r':
rage_spell(King)
elif ch == 'h':
heal_spell(King)
elif ch == 'z':
spawnBarbarian(V.spawn_points[0])
elif ch == 'x':
spawnBarbarian(V.spawn_points[1])
elif ch == 'c':
spawnBarbarian(V.spawn_points[2])
elif ch == 'v':
spawnDragon(V.spawn_points[0])
elif ch == 'b':
spawnDragon(V.spawn_points[1])
elif ch == 'n':
spawnDragon(V.spawn_points[2])
elif ch == 'j':
spawnBalloon(V.spawn_points[0])
elif ch == 'k':
spawnBalloon(V.spawn_points[1])
elif ch == 'l':
spawnBalloon(V.spawn_points[2])
elif ch == 'i':
spawnArcher(V.spawn_points[0])
elif ch == 'o':
spawnArcher(V.spawn_points[1])
elif ch == 'p':
spawnArcher(V.spawn_points[2])
elif ch == 'q':
print('quit')
break
# os.system('clear')
move_barbarians(V,pt.movement)
move_archers(V,pt.movement)
move_dragons(V)
move_balloons(V)
shoot_cannons(King, V)
shoot_wizard_towers(King, V)
if(cnt % 20 == 0):
os.system('clear')
print("\033[%d;%dH" % (0, 0), end='')
printMap(V)
Phealth(showKingHealth(King.health))
if(V.check_if_game_over(King) == 1): # next level
level += 1
init_level(level)
elif(V.check_if_game_over(King) == 2): # Victory
os.system('clear')
print('Victory')
break
elif(V.check_if_game_over(King) == 3):
os.system('clear')
print('Defeat')
break