{}
CODE VISUALIZER
Learn DSA the way it should be — with step-by-step code visualization.
Try now!
CODE VISUALIZER
Learn DSA with step-by-step code visualization.
Try now!
run-icon
main.py
character_class = "" location = "" character_dex = 0 character_mag = 0 character_str = 0 character_hp = 100 first_enemy = "" attack_run = "" slime_hp = 3 wolf_hp = 3 giant_snake_hp = 3 ################################################################################ print("Welcome adventurer!") print("Choose your class.") character_class = input("Ranger (+1 Dexterity), Mage (+1 Magic), or Fighter (+1 Strength): ") def get_weapon(character_class, character_dex, character_mag, character_str): character_class = character_class.lower() if character_class == "ranger": weapon_statement = "You have obtained a bow and arrows!" character_dex += 1 elif character_class == "mage": weapon_statement = "You have obtained a staff and robes!" character_mag += 1 elif character_class == "fighter": weapon_statement = "You have obtained a sword and shield!" character_str += 1 else: raise Exception("Hold on there, young adventurer!") return weapon_statement, character_dex, character_mag, character_str while True: try: weapon_statement, character_dex, character_mag, character_str = get_weapon( character_class, character_dex, character_mag, character_str) break except Exception as e: print(e) print("I'm afraid that's not a class. Please try again!") character_class = input("Ranger (+1 Dexterity), Mage (+1 Magic), or Fighter (+1 Strength): ") print(weapon_statement) print("") print(f"Dexterity: {character_dex}") print(f"Magic: {character_mag}") print(f"Strength: {character_str}") print("") print("Now that you have chosen your role mighty adventurer, please choose where you would like to start your grand adventure!") location = input("You may go to the Forgotten Forest, Crystalline Caves, or the Stagnant Springs: ") def new_journey(location): location = location.lower() if location == "forgotten forest": location_statement = "You arrive at the edge of whistling forest. There are far too many sounds to decipher." elif location == "crystalline caves": location_statement = "You arrive at the mouth of a towering cave. You see tiny sparkles in the distance." elif location == "stagnant springs": location_statement = "You arrive at the bank of a still pond. It smells like death" else: raise Exception("Hold on there, young adventurer!") return location_statement while True: try: location_statement = new_journey(location) break except Exception as e: print(e) print("I'm afraid that's not a location. Please try again!") location = input("You may go to the Forgotten Forest, Crystalline Caves, or the Stagnant Springs: ") print(location_statement) enter = input("Do you proceed? ") def first_steps(enter): enter = enter.lower() if enter == "yes": print("Excellent! Let us proceed with caution") elif enter == "no": print("That's okay, adventuring isn't for everyone!") print("END GAME") exit() else: raise Exception("This is an important decision, adventurer! Will you continue or end your journey here?") while True: try: first_steps(enter) break except Exception as e: print(e) print("Hint: yes or no?") enter = input("Do you proceed? ") print("") print("You only make it a few steps before you hear a noise to your right...") def first_enemy_get(location, first_enemy): location = location.lower() if location == "forgotten forest": first_enemy_statement = "It's a soft growl. You have an encountered a wolf!" first_enemy = "Wolf" elif location == "crystalline caves": first_enemy_statement = "It sounds like something gelatinous bouncing across the cave. You have an encountered a slime!" first_enemy = "Slime" elif location == "stagnant springs": first_enemy_statement = "It's something raising from the water. You have encountered a giant snake!" first_enemy = "Giant Snake" return first_enemy_statement, first_enemy first_enemy_statement, first_enemy = first_enemy_get(location, first_enemy) print(first_enemy_statement) print(f"The {first_enemy} readies itself for an attack!") def fight_wolf(action, character_class, wolf_hp): action = action.lower() character_class = character_class.lower() if action == "attack" and character_class == "ranger": wolf_hp -= 2 result = "You are able to pierce the large creature right in the eye. It does a large amount of damage!" elif action == "attack" and character_class == "mage": wolf_hp -= 1 result = "You cast a thunder bolt that rolls through the wolf's body. It appears to do a normal amount of damage!" elif action == "attack" and character_class == "fighter": wolf_hp -= 1 result = "Your sword comes down and slashes its furry body. It appears to do a normal amount of damage!" elif action == "run": result = "You get away safely! But you gained no valuable experience..." return wolf_hp, result def fight_slime(action, character_class, slime_hp): action = action.lower() character_class = character_class.lower() if action == "attack" and character_class == "ranger": slime_hp -= 1 result = "You pierce it's body with one of your arrows! It appears to do a normal amount of damage." elif action == "attack" and character_class == "mage": slime_hp -= 2 result = "You cast a firebolt that explodes on impact. It appears to do a great amount of damage!" elif action == "attack" and character_class == "fighter": slime_hp -= 1 result = "Your sword comes down and slashes its squishy body. It appears to do a normal amount of damage." elif action == "run": result = "You get away safely! But you gained no valuable experience..." return slime_hp, result def fight_giant_snake(action, character_class, giant_snake_hp): action = action.lower() character_class = character_class.lower() if action == "attack" and character_class == "ranger": giant_snake_hp -= 1 result = "You pierce it's scaley body with one of your arrows! It appears to do a normal amount of damage." elif action == "attack" and character_class == "mage": giant_snake_hp -= 1 result = "You cast a ice bolt that doesn't quite pierce its scales. It appears to do a normal amount of damage!" elif action == "attack" and character_class == "fighter": giant_snake_hp -= 2 result = "Your sword comes down and slashes its thin body. It appears to do a great amount of damage!" elif action == "run": result = "You get away safely! But you gained no valuable experience..." return giant_snake_hp, result while True: try: first_enemy = first_enemy.lower() if first_enemy == "wolf": while wolf_hp > 0: action = input("Do you want to 'attack' or 'run'? ") wolf_hp, result = fight_wolf(action, character_class, wolf_hp) if action.lower() == "attack": print(result) if action.lower() == "run": break if wolf_hp <= 0: print ("The wolf has been defeated!") character_str += 1 print("You have gained a point of strength experience from defeating a monstrous creature!") if action.lower() not in ["attack", "run"]: raise Exception("That's not a valid option, adventurer! Either flee or attack!") elif first_enemy == "slime": while slime_hp > 0: action = input("Do you want to 'attack' or 'run'? ") slime_hp, result = fight_slime(action, character_class, slime_hp) print(result) if action.lower() == "run": break if slime_hp <= 0: print("The slime has been defeated!") character_mag += 1 print ("You have gained a point of magic experience from defeating a magical creature") if action.lower() not in ["attack", "run"]: raise Exception("That's not a valid option, adventurer! Either run or attack!") elif first_enemy == "giant snake": while giant_snake_hp > 0: action = input("Do you want to 'attack' or 'run'? ") giant_snake_hp, result = fight_giant_snake(action, character_class, giant_snake_hp) print(result) if action.lower() == "run": break if giant_snake_hp <= 0: print("The giant snake has been defeated!") character_dex += 1 print ("You have gained a point of dexterity experience from defeating a nimble creature") if action.lower() not in ["attack", "run"]: raise Exception("That's not a valid option, adventurer! Either run or attack!") except Exception as e: print(e) print("") print(f"Dexterity: {character_dex}") print(f"Magic: {character_mag}") print(f"Strength: {character_str}") print("")
Output