Amazing-Python-Scripts
141 строка · 4.3 Кб
1import random
2
3# Enemy types with varying attack capabilities
4ENEMY_TYPES = [
5{"name": "Goblin", "damage": 20, "chance_to_evade": 0.1},
6{"name": "Orc", "damage": 30, "chance_to_evade": 0.15},
7{"name": "Troll", "damage": 40, "chance_to_evade": 0.2},
8]
9
10# Special attacks with cooldown periods
11SPECIAL_ATTACKS = [
12{"name": "Fireball", "damage": 50, "cooldown": 3},
13{"name": "Lightning Strike", "damage": 60, "cooldown": 5},
14{"name": "Ice Nova", "damage": 45, "cooldown": 4},
15{"name": "Poison Dart", "damage": 40, "cooldown": 3},
16]
17
18# Initialize game variables
19level = 1
20total_points = 0
21enemy_type = ENEMY_TYPES[0]
22special_attack_cooldown = 0
23
24
25def setup_defenses():
26defenses = []
27for i in range(5):
28defense_strength = random.randint(50 + 10*level, 100 + 10*level)
29defenses.append(defense_strength)
30return defenses
31
32
33def choose_enemy_type():
34global enemy_type
35enemy_type = random.choice(ENEMY_TYPES)
36
37
38def use_special_attack():
39global special_attack_cooldown
40if special_attack_cooldown == 0:
41special_attack = random.choice(SPECIAL_ATTACKS)
42special_attack_cooldown = special_attack["cooldown"]
43print(
44f"Used {special_attack['name']}! It deals {special_attack['damage']} damage!")
45return special_attack["damage"]
46else:
47print("Special attack is on cooldown. Keep attacking the defenses!")
48return 0
49
50
51def upgrade_enemy():
52global enemy_type
53enemy_type_index = ENEMY_TYPES.index(enemy_type)
54if enemy_type_index < len(ENEMY_TYPES) - 1:
55enemy_type = ENEMY_TYPES[enemy_type_index + 1]
56print(
57f"You upgraded to {enemy_type['name']}. They deal more damage now!")
58
59
60def attack(defenses):
61global special_attack_cooldown, total_points
62total_defense_strength = sum(defenses)
63print(f"Current defenses: {defenses}")
64print(f"Total defense strength: {total_defense_strength}")
65
66if total_defense_strength <= 0:
67print("Congratulations! You breached the defenses!")
68total_points += 100 + 20 * level
69return True
70else:
71while True:
72print("\nChoose your action:")
73print("1. Normal Attack")
74print("2. Use Special Attack")
75print("3. Upgrade Enemy Type")
76action = input("Enter the number of your action: ")
77
78if action == "1":
79damage = enemy_type["damage"]
80if random.random() < enemy_type["chance_to_evade"]:
81print(f"{enemy_type['name']} evaded your attack!")
82damage = 0
83else:
84print(
85f"You attacked the defenses and caused {damage} damage!")
86defenses[random.randint(0, len(defenses) - 1)] -= damage
87return False
88
89elif action == "2":
90damage = use_special_attack()
91defenses[random.randint(0, len(defenses) - 1)] -= damage
92return False
93
94elif action == "3":
95upgrade_enemy()
96return False
97
98else:
99print("Invalid input. Please enter a valid action number.")
100
101
102def main():
103global level, total_points, special_attack_cooldown
104
105print("Welcome to the Reverse Tower Defense Game!")
106print("You are controlling the enemy horde trying to breach the AI's defenses.")
107
108while True:
109print(f"\n--- Level {level} ---")
110
111defenses = setup_defenses()
112points = 0
113special_attack_cooldown = 0
114
115while True:
116if attack(defenses):
117level += 1
118total_points += points
119break
120
121if special_attack_cooldown > 0:
122special_attack_cooldown -= 1
123
124print("\nChoose the defense you want to attack:")
125for i in range(len(defenses)):
126print(f"{i+1}. Defense {i+1} - Strength: {defenses[i]}")
127
128print(f"\nLevel {level-1} completed!")
129print(f"Points earned in Level {level-1}: {points}")
130print(f"Total points: {total_points}")
131
132play_again = input(
133"Do you want to play the next level? (yes/no): ").lower()
134if play_again != "yes":
135break
136
137print("Thanks for playing! Game Over!")
138
139
140if __name__ == "__main__":
141main()
142