Text Based RPG
Thu Jul 25 2024 15:07:56 GMT+0000 (Coordinated Universal Time)
Saved by @Ibib
#Chance
import random
# Welcome message
print("Hello, Traveler! What is your name?")
# Get username
username = input("Enter username: ")
# Greet the user
print(f"Hello, {username}!")
# Introduce the quest
print("You are on your way to get the legendary cookie.")
# Present weapon choices
print("What weapon will you start with?")
print("A: Blade of Power ( 50 DMG, 25% CRIT RATE = 75 DMG)")
print("B: Katana of Wisdom (35 DMG, 50% CRIT RATE = 52.5 DMG)")
# Get user's choice
while True:
choice = input("Choose your weapon (A/B): ").strip().upper()
if choice not in ["A", "B"]:
print("Invalid choice. Please choose A or B.")
else:
break
# Process user's choice
if choice == "A":
print("You chose Blade of Power!")
weapon = "Blade of Power"
damage = 50
crit_rate = 0.25
elif choice == "B":
print("You chose Katana of Wisdom!")
weapon = "Katana of Wisdom"
damage = 35
crit_rate = 0.5
#Variables
gremlin_hp = 70
monster = "gremlin"
damage2 = 40
crit_rate2 = 0.5
player_HP = 100
gremlindead = 0
# Encounter a gremlin
print("You encounter a gremlin that eats people's socks! (it has {} HP)".format(gremlin_hp))
print("What do you do?")
# Present choices
print("A: Kill it")
print("B: Befriend it (50% chance) (+30 ATK)")
# Get user's choice
while True:
choice = input("Choose your action (A/B): ").strip().upper()
if choice not in ["A", "B"]:
print("Invalid choice. Please choose A or B.")
else:
break
# Process user's choice
if choice == "A":
# Kill the gremlin
print("You attack the gremlin with your {}!".format(weapon))
# Roll for crit
if random.random() < crit_rate:
damage *= 1.5
print("Critical hit!")
print("You deal {} damage to the gremlin!".format(damage))
gremlin_hp -= damage
if gremlin_hp <= 0:
print("The gremlin is defeated!")
gremlindead = 1
else:
print("But the gremlin isn't dead yet!")
print("The gremlin has {} HP remaining!".format(gremlin_hp))
print("You're attacked by the {}!".format(monster))
print("You have {} HP left!".format(player_HP - damage2))
print("What will you do?")
# Present choices
print("A: Attack it")
print("B: Befriend it (30% chance) (+40 ATK)")
print("C: Flee")
#Get user's choice A
choice = input("Choose your action (A/B/C): ").strip().upper()
if choice not in ["A", "B", "C"]:
print("Invalid choice. Please choose between A, B, or C.")
if choice == "A":
# Kill the gremlin
print("You attack the gremlin with your {}!".format(weapon))
# Roll for crit
if random.random() < crit_rate:
damage *= 1.5
print("Critical hit!")
print("You deal {} damage to the gremlin!".format(damage))
gremlin_hp -= damage
if gremlin_hp <= 0:
print("The gremlin is defeated!")
print("Your attack power increases by {}!".format(damage2))
if choice == "B":
# Befriend the gremlin
if random.random() < 0.5:
print("You successfully befriend the gremlin!")
print("Your attack power increases by {}!".format(damage2))
if choice == "C":
#Flee
print("You ran away!, but, you fell into a pit of lava and died. Gme Over :(((")
exit()
Programiz
https://www.programiz.com/python-programming/online-compiler/


Comments