21
21
enemy_type = ENEMY_TYPES [0 ]
22
22
special_attack_cooldown = 0
23
23
24
+
24
25
def setup_defenses ():
25
26
defenses = []
26
27
for i in range (5 ):
27
28
defense_strength = random .randint (50 + 10 * level , 100 + 10 * level )
28
29
defenses .append (defense_strength )
29
30
return defenses
30
31
32
+
31
33
def choose_enemy_type ():
32
34
global enemy_type
33
35
enemy_type = random .choice (ENEMY_TYPES )
34
36
37
+
35
38
def use_special_attack ():
36
39
global special_attack_cooldown
37
40
if special_attack_cooldown == 0 :
38
41
special_attack = random .choice (SPECIAL_ATTACKS )
39
42
special_attack_cooldown = special_attack ["cooldown" ]
40
- print (f"Used { special_attack ['name' ]} ! It deals { special_attack ['damage' ]} damage!" )
43
+ print (
44
+ f"Used { special_attack ['name' ]} ! It deals { special_attack ['damage' ]} damage!" )
41
45
return special_attack ["damage" ]
42
46
else :
43
47
print ("Special attack is on cooldown. Keep attacking the defenses!" )
44
48
return 0
45
49
50
+
46
51
def upgrade_enemy ():
47
52
global enemy_type
48
53
enemy_type_index = ENEMY_TYPES .index (enemy_type )
49
54
if enemy_type_index < len (ENEMY_TYPES ) - 1 :
50
55
enemy_type = ENEMY_TYPES [enemy_type_index + 1 ]
51
- print (f"You upgraded to { enemy_type ['name' ]} . They deal more damage now!" )
56
+ print (
57
+ f"You upgraded to { enemy_type ['name' ]} . They deal more damage now!" )
58
+
52
59
53
60
def attack (defenses ):
54
61
global special_attack_cooldown , total_points
55
62
total_defense_strength = sum (defenses )
56
63
print (f"Current defenses: { defenses } " )
57
64
print (f"Total defense strength: { total_defense_strength } " )
58
-
65
+
59
66
if total_defense_strength <= 0 :
60
67
print ("Congratulations! You breached the defenses!" )
61
68
total_points += 100 + 20 * level
@@ -74,7 +81,8 @@ def attack(defenses):
74
81
print (f"{ enemy_type ['name' ]} evaded your attack!" )
75
82
damage = 0
76
83
else :
77
- print (f"You attacked the defenses and caused { damage } damage!" )
84
+ print (
85
+ f"You attacked the defenses and caused { damage } damage!" )
78
86
defenses [random .randint (0 , len (defenses ) - 1 )] -= damage
79
87
return False
80
88
@@ -90,15 +98,16 @@ def attack(defenses):
90
98
else :
91
99
print ("Invalid input. Please enter a valid action number." )
92
100
101
+
93
102
def main ():
94
103
global level , total_points , special_attack_cooldown
95
104
96
105
print ("Welcome to the Reverse Tower Defense Game!" )
97
106
print ("You are controlling the enemy horde trying to breach the AI's defenses." )
98
-
107
+
99
108
while True :
100
109
print (f"\n --- Level { level } ---" )
101
-
110
+
102
111
defenses = setup_defenses ()
103
112
points = 0
104
113
special_attack_cooldown = 0
@@ -108,23 +117,25 @@ def main():
108
117
level += 1
109
118
total_points += points
110
119
break
111
-
120
+
112
121
if special_attack_cooldown > 0 :
113
122
special_attack_cooldown -= 1
114
-
123
+
115
124
print ("\n Choose the defense you want to attack:" )
116
125
for i in range (len (defenses )):
117
126
print (f"{ i + 1 } . Defense { i + 1 } - Strength: { defenses [i ]} " )
118
-
127
+
119
128
print (f"\n Level { level - 1 } completed!" )
120
129
print (f"Points earned in Level { level - 1 } : { points } " )
121
130
print (f"Total points: { total_points } " )
122
131
123
- play_again = input ("Do you want to play the next level? (yes/no): " ).lower ()
132
+ play_again = input (
133
+ "Do you want to play the next level? (yes/no): " ).lower ()
124
134
if play_again != "yes" :
125
135
break
126
-
136
+
127
137
print ("Thanks for playing! Game Over!" )
128
138
139
+
129
140
if __name__ == "__main__" :
130
141
main ()
0 commit comments