Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 83ca877

Browse files
style: format code with autopep8
Format code with autopep8 This commit fixes the style issues introduced in b62da76 according to the output from Autopep8. Details: None
1 parent b55a2e1 commit 83ca877

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

‎Reverse Tower Defense Game/reverse_tower_defense.py‎

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,48 @@
2121
enemy_type = ENEMY_TYPES[0]
2222
special_attack_cooldown = 0
2323

24+
2425
def setup_defenses():
2526
defenses = []
2627
for i in range(5):
2728
defense_strength = random.randint(50 + 10*level, 100 + 10*level)
2829
defenses.append(defense_strength)
2930
return defenses
3031

32+
3133
def choose_enemy_type():
3234
global enemy_type
3335
enemy_type = random.choice(ENEMY_TYPES)
3436

37+
3538
def use_special_attack():
3639
global special_attack_cooldown
3740
if special_attack_cooldown == 0:
3841
special_attack = random.choice(SPECIAL_ATTACKS)
3942
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!")
4145
return special_attack["damage"]
4246
else:
4347
print("Special attack is on cooldown. Keep attacking the defenses!")
4448
return 0
4549

50+
4651
def upgrade_enemy():
4752
global enemy_type
4853
enemy_type_index = ENEMY_TYPES.index(enemy_type)
4954
if enemy_type_index < len(ENEMY_TYPES) - 1:
5055
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+
5259

5360
def attack(defenses):
5461
global special_attack_cooldown, total_points
5562
total_defense_strength = sum(defenses)
5663
print(f"Current defenses: {defenses}")
5764
print(f"Total defense strength: {total_defense_strength}")
58-
65+
5966
if total_defense_strength <= 0:
6067
print("Congratulations! You breached the defenses!")
6168
total_points += 100 + 20 * level
@@ -74,7 +81,8 @@ def attack(defenses):
7481
print(f"{enemy_type['name']} evaded your attack!")
7582
damage = 0
7683
else:
77-
print(f"You attacked the defenses and caused {damage} damage!")
84+
print(
85+
f"You attacked the defenses and caused {damage} damage!")
7886
defenses[random.randint(0, len(defenses) - 1)] -= damage
7987
return False
8088

@@ -90,15 +98,16 @@ def attack(defenses):
9098
else:
9199
print("Invalid input. Please enter a valid action number.")
92100

101+
93102
def main():
94103
global level, total_points, special_attack_cooldown
95104

96105
print("Welcome to the Reverse Tower Defense Game!")
97106
print("You are controlling the enemy horde trying to breach the AI's defenses.")
98-
107+
99108
while True:
100109
print(f"\n--- Level {level} ---")
101-
110+
102111
defenses = setup_defenses()
103112
points = 0
104113
special_attack_cooldown = 0
@@ -108,23 +117,25 @@ def main():
108117
level += 1
109118
total_points += points
110119
break
111-
120+
112121
if special_attack_cooldown > 0:
113122
special_attack_cooldown -= 1
114-
123+
115124
print("\nChoose the defense you want to attack:")
116125
for i in range(len(defenses)):
117126
print(f"{i+1}. Defense {i+1} - Strength: {defenses[i]}")
118-
127+
119128
print(f"\nLevel {level-1} completed!")
120129
print(f"Points earned in Level {level-1}: {points}")
121130
print(f"Total points: {total_points}")
122131

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()
124134
if play_again != "yes":
125135
break
126-
136+
127137
print("Thanks for playing! Game Over!")
128138

139+
129140
if __name__ == "__main__":
130141
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /