-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpygame_______.py
More file actions
53 lines (43 loc) · 1.43 KB
/
pygame_______.py
File metadata and controls
53 lines (43 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import sys
import time
import random
# -------- INITIAL SETUP --------
health = 100
print("Your health is", health)
round_number = 1
# -------- GAME LOOP --------
while True:
print(f"\n--- Round {round_number} ---")
# Player chooses an action
user_input = input("Type W, A, S, or D: ").upper()
# Player action effects
if user_input == "W":
health -= 50
print("You took a risky move! Health decreased to", health)
elif user_input == "A":
health += 10
print("Smart choice! Health increased to", health)
elif user_input == "S":
health += 5
print("Safe move! Health increased to", health)
elif user_input == "D":
health += 5
print("Defensive move! Health increased to", health)
else:
print("Invalid input! You will be kicked in 5 seconds.")
time.sleep(5)
sys.exit()
# -------- CHECK HEALTH --------
if health <= 0:
print("Your health dropped to 0. Game over!")
sys.exit()
# Enemy attack
enemy_damage = random.randint(5, 20)
health -= enemy_damage
print(f"An enemy attacks and deals {enemy_damage} damage! Your health is now {health}")
if health <= 0:
print("You were defeated by the enemy. Game over!")
sys.exit()
# Optional: wait before next round
time.sleep(2)
round_number += 1