-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path30. Text-Based RPG Game.py
More file actions
40 lines (32 loc) · 1.36 KB
/
30. Text-Based RPG Game.py
File metadata and controls
40 lines (32 loc) · 1.36 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
import random
def main():
print("Welcome to the Text-Based RPG Game!")
player_name = input("Enter your name: ")
print(f"Hello, {player_name}! Let's begin your adventure.")
player_health = 100
enemy_health = random.randint(50, 100)
print("You encountered an enemy!")
while player_health > 0 and enemy_health > 0:
print(f"\nYour Health: {player_health}")
print(f"Enemy's Health: {enemy_health}")
action = input("\nChoose your action (attack/heal): ").lower()
if action == "attack":
damage = random.randint(5, 20)
enemy_health -= damage
print(f"You attacked the enemy and dealt {damage} damage!")
elif action == "heal":
heal_amount = random.randint(10, 25)
player_health = min(100, player_health + heal_amount)
print(f"You healed yourself and restored {heal_amount} health!")
else:
print("Invalid action! Choose 'attack' or 'heal'.")
if enemy_health > 0:
enemy_damage = random.randint(5, 15)
player_health = max(0, player_health - enemy_damage)
print(f"The enemy attacked you and dealt {enemy_damage} damage!")
if player_health <= 0:
print("You lost! Game over.")
else:
print("Congratulations! You defeated the enemy!")
if __name__ == "__main__":
main()