Amazing-Python-Scripts

Форк
0
141 строка · 4.3 Кб
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

25
def setup_defenses():
26
    defenses = []
27
    for i in range(5):
28
        defense_strength = random.randint(50 + 10*level, 100 + 10*level)
29
        defenses.append(defense_strength)
30
    return defenses
31

32

33
def choose_enemy_type():
34
    global enemy_type
35
    enemy_type = random.choice(ENEMY_TYPES)
36

37

38
def use_special_attack():
39
    global special_attack_cooldown
40
    if special_attack_cooldown == 0:
41
        special_attack = random.choice(SPECIAL_ATTACKS)
42
        special_attack_cooldown = special_attack["cooldown"]
43
        print(
44
            f"Used {special_attack['name']}! It deals {special_attack['damage']} damage!")
45
        return special_attack["damage"]
46
    else:
47
        print("Special attack is on cooldown. Keep attacking the defenses!")
48
        return 0
49

50

51
def upgrade_enemy():
52
    global enemy_type
53
    enemy_type_index = ENEMY_TYPES.index(enemy_type)
54
    if enemy_type_index < len(ENEMY_TYPES) - 1:
55
        enemy_type = ENEMY_TYPES[enemy_type_index + 1]
56
        print(
57
            f"You upgraded to {enemy_type['name']}. They deal more damage now!")
58

59

60
def attack(defenses):
61
    global special_attack_cooldown, total_points
62
    total_defense_strength = sum(defenses)
63
    print(f"Current defenses: {defenses}")
64
    print(f"Total defense strength: {total_defense_strength}")
65

66
    if total_defense_strength <= 0:
67
        print("Congratulations! You breached the defenses!")
68
        total_points += 100 + 20 * level
69
        return True
70
    else:
71
        while True:
72
            print("\nChoose your action:")
73
            print("1. Normal Attack")
74
            print("2. Use Special Attack")
75
            print("3. Upgrade Enemy Type")
76
            action = input("Enter the number of your action: ")
77

78
            if action == "1":
79
                damage = enemy_type["damage"]
80
                if random.random() < enemy_type["chance_to_evade"]:
81
                    print(f"{enemy_type['name']} evaded your attack!")
82
                    damage = 0
83
                else:
84
                    print(
85
                        f"You attacked the defenses and caused {damage} damage!")
86
                defenses[random.randint(0, len(defenses) - 1)] -= damage
87
                return False
88

89
            elif action == "2":
90
                damage = use_special_attack()
91
                defenses[random.randint(0, len(defenses) - 1)] -= damage
92
                return False
93

94
            elif action == "3":
95
                upgrade_enemy()
96
                return False
97

98
            else:
99
                print("Invalid input. Please enter a valid action number.")
100

101

102
def main():
103
    global level, total_points, special_attack_cooldown
104

105
    print("Welcome to the Reverse Tower Defense Game!")
106
    print("You are controlling the enemy horde trying to breach the AI's defenses.")
107

108
    while True:
109
        print(f"\n--- Level {level} ---")
110

111
        defenses = setup_defenses()
112
        points = 0
113
        special_attack_cooldown = 0
114

115
        while True:
116
            if attack(defenses):
117
                level += 1
118
                total_points += points
119
                break
120

121
            if special_attack_cooldown > 0:
122
                special_attack_cooldown -= 1
123

124
            print("\nChoose the defense you want to attack:")
125
            for i in range(len(defenses)):
126
                print(f"{i+1}. Defense {i+1} - Strength: {defenses[i]}")
127

128
        print(f"\nLevel {level-1} completed!")
129
        print(f"Points earned in Level {level-1}: {points}")
130
        print(f"Total points: {total_points}")
131

132
        play_again = input(
133
            "Do you want to play the next level? (yes/no): ").lower()
134
        if play_again != "yes":
135
            break
136

137
    print("Thanks for playing! Game Over!")
138

139

140
if __name__ == "__main__":
141
    main()
142

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.