Skip to content

Commit b62da76

Browse files
Merge pull request #2622 from andoriyaprashant/branch26
Reverse Tower Defense Game Script Added
2 parents b44427d + 6ba19d6 commit b62da76

File tree

3 files changed

+179
-0
lines changed

3 files changed

+179
-0
lines changed

Reverse Tower Defense Game/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Reverse Tower Defense Game
2+
3+
Welcome to the Reverse Tower Defense Game! In this text-based game, you control the enemy horde, trying to breach the AI's defenses. The game features multiple levels with increasing difficulty, different enemy types with varying attack capabilities, and a variety of special attacks to unleash upon the defenses.
4+
5+
## Features
6+
7+
- Multiple Levels: Each level comes with stronger defenses, increasing the challenge as you progress.
8+
9+
- Different Enemy Types: Encounter goblins, orcs, trolls, and more, each with unique attack capabilities.
10+
11+
- Special Attacks: Unleash powerful special attacks, such as Fireball, Lightning Strike, Ice Nova, and Poison Dart, to deal significant damage to a defense of your choice.
12+
13+
- Upgrade System: Earn points from successful attacks and upgrade the enemy horde's abilities, increasing damage output and other stats.
14+
15+
- Random Events: Experience occasional random events that can impact the game, such as temporary boosts in attack power for your horde or debuffs for the AI defenses.
16+
17+
- High Score System: Compete for the highest score across different levels and see how well you perform as the enemy horde.
18+
19+
## How to Play
20+
21+
1. Run the `reverse_tower_defense_game.py` script using Python 3.
22+
23+
2. Follow the on-screen instructions to choose your actions during attacks, use special attacks, and upgrade the enemy horde.
24+
25+
3. Keep breaching the AI's defenses and progress through multiple levels.
26+
27+
## Requirements
28+
29+
- python
30+
- random
31+
32+
## Installation
33+
34+
1. Clone or download this repository.
35+
36+
2. Navigate to the project directory.
37+
38+
3. Run the game script using Python:
39+
40+
```bash
41+
python reverse_tower_defense_game.py
42+
```
43+
44+
## Contributions
45+
46+
Contributions to this game are welcome! If you have any suggestions, bug fixes, or new features to add, please feel free to submit a pull request.
47+
48+
Enjoy the game and have fun breaching those defenses!
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
random
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import random
2+
3+
# Enemy types with varying attack capabilities
4+
ENEMY_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
11+
SPECIAL_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
19+
level = 1
20+
total_points = 0
21+
enemy_type = ENEMY_TYPES[0]
22+
special_attack_cooldown = 0
23+
24+
def setup_defenses():
25+
defenses = []
26+
for i in range(5):
27+
defense_strength = random.randint(50 + 10*level, 100 + 10*level)
28+
defenses.append(defense_strength)
29+
return defenses
30+
31+
def choose_enemy_type():
32+
global enemy_type
33+
enemy_type = random.choice(ENEMY_TYPES)
34+
35+
def use_special_attack():
36+
global special_attack_cooldown
37+
if special_attack_cooldown == 0:
38+
special_attack = random.choice(SPECIAL_ATTACKS)
39+
special_attack_cooldown = special_attack["cooldown"]
40+
print(f"Used {special_attack['name']}! It deals {special_attack['damage']} damage!")
41+
return special_attack["damage"]
42+
else:
43+
print("Special attack is on cooldown. Keep attacking the defenses!")
44+
return 0
45+
46+
def upgrade_enemy():
47+
global enemy_type
48+
enemy_type_index = ENEMY_TYPES.index(enemy_type)
49+
if enemy_type_index < len(ENEMY_TYPES) - 1:
50+
enemy_type = ENEMY_TYPES[enemy_type_index + 1]
51+
print(f"You upgraded to {enemy_type['name']}. They deal more damage now!")
52+
53+
def attack(defenses):
54+
global special_attack_cooldown, total_points
55+
total_defense_strength = sum(defenses)
56+
print(f"Current defenses: {defenses}")
57+
print(f"Total defense strength: {total_defense_strength}")
58+
59+
if total_defense_strength <= 0:
60+
print("Congratulations! You breached the defenses!")
61+
total_points += 100 + 20 * level
62+
return True
63+
else:
64+
while True:
65+
print("\nChoose your action:")
66+
print("1. Normal Attack")
67+
print("2. Use Special Attack")
68+
print("3. Upgrade Enemy Type")
69+
action = input("Enter the number of your action: ")
70+
71+
if action == "1":
72+
damage = enemy_type["damage"]
73+
if random.random() < enemy_type["chance_to_evade"]:
74+
print(f"{enemy_type['name']} evaded your attack!")
75+
damage = 0
76+
else:
77+
print(f"You attacked the defenses and caused {damage} damage!")
78+
defenses[random.randint(0, len(defenses) - 1)] -= damage
79+
return False
80+
81+
elif action == "2":
82+
damage = use_special_attack()
83+
defenses[random.randint(0, len(defenses) - 1)] -= damage
84+
return False
85+
86+
elif action == "3":
87+
upgrade_enemy()
88+
return False
89+
90+
else:
91+
print("Invalid input. Please enter a valid action number.")
92+
93+
def main():
94+
global level, total_points, special_attack_cooldown
95+
96+
print("Welcome to the Reverse Tower Defense Game!")
97+
print("You are controlling the enemy horde trying to breach the AI's defenses.")
98+
99+
while True:
100+
print(f"\n--- Level {level} ---")
101+
102+
defenses = setup_defenses()
103+
points = 0
104+
special_attack_cooldown = 0
105+
106+
while True:
107+
if attack(defenses):
108+
level += 1
109+
total_points += points
110+
break
111+
112+
if special_attack_cooldown > 0:
113+
special_attack_cooldown -= 1
114+
115+
print("\nChoose the defense you want to attack:")
116+
for i in range(len(defenses)):
117+
print(f"{i+1}. Defense {i+1} - Strength: {defenses[i]}")
118+
119+
print(f"\nLevel {level-1} completed!")
120+
print(f"Points earned in Level {level-1}: {points}")
121+
print(f"Total points: {total_points}")
122+
123+
play_again = input("Do you want to play the next level? (yes/no): ").lower()
124+
if play_again != "yes":
125+
break
126+
127+
print("Thanks for playing! Game Over!")
128+
129+
if __name__ == "__main__":
130+
main()

0 commit comments

Comments
 (0)