Last active
March 17, 2017 03:39
-
-
Save ConorOBrien-Foxx/808fe6a23341a03ffeb3758ffc436999 to your computer and use it in GitHub Desktop.
compsci principles project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import time | |
import sys | |
# by Conor O'Brien | |
def small_sleep(): | |
time.sleep(0) | |
# simulate `a in b` | |
def has_member(str, e): | |
i = 0 | |
while i < len(str): | |
if str[i] == e: | |
return True | |
i += 1 | |
return False | |
def remove_from(str, a): | |
result = "" | |
i = 0 | |
while i < len(str): | |
if str[i] != a: | |
result += str[i] | |
i += 1 | |
return result | |
def quote_str(str): | |
return "“" + str + "”" | |
def loss(): | |
print("You lost!") | |
def fire_loss(): | |
print("You went out in a blaze of glory!") | |
small_sleep() | |
print("... but you died. Oh well.") | |
def old_fashioned_win(): | |
print("You won the old-fashioned way!") | |
def pacifist_win(): | |
print("You won the pacifist way!") | |
def mutual_acceptance(): | |
print("You won! Not much, but hey, at least you didn't die.") | |
def evangalistic_win(): | |
print("You won the evangalistic way!") | |
def todo_win(): | |
print("You won because the programmer was too lazy.") | |
# validate choice | |
def get_choice(prompt): | |
while True: | |
a = input("] ") | |
if has_member(prompt, a): | |
break | |
elif a == "exit": | |
sys.exit(1) | |
print("Invalid input, try again") | |
return a | |
def pause(): | |
input("{ press ENTER to continue }") | |
# suggestion: greek fire | |
# dis cord | |
# main program | |
print("====================") | |
print("[[[ DRAGON REALM ]]]") | |
print("====================") | |
print("This is a simple, alpha-stage game, designed to be relatively simplistic,") | |
small_sleep() | |
print("utilizing only the simplest of programatic features.") | |
small_sleep() | |
print("Throughout the game, you will encounter prompts, asking for your action.") | |
small_sleep() | |
print("These prompts will look something like this:") | |
small_sleep() | |
print("Choice?") | |
print(" 1> option 1") | |
print(" 2> option 2") | |
print(" 3> option 3") | |
print("] _") | |
small_sleep() | |
print("After the bracket, you will input your choice (in this case, a number from") | |
print("1 to 3) and press ENTER. You may instead enter \"exit\" at any time to quit the") | |
print(" game.") | |
pause() | |
print("[[[ BACKSTORY ]]]") | |
print("You are a young hero with aspirations of glory, fame, and treasure.") | |
small_sleep() | |
print("You decide to leave your abode for the realms of the unknown.") | |
pause() | |
while True: | |
dragon_hp = 100 | |
player_hp = 25 | |
player_defense = 0 | |
# damage multiplier | |
player_strength = 1.0 | |
# healing multiplier | |
player_dexterity = 1.0 | |
# player hits shots 80% of the time | |
player_accuracy = 80 | |
super_bonus = False | |
wizard_item = None | |
valid_options = "1234" | |
# various options | |
spear = "1" | |
bow = "2" | |
enchanted_cloak = "3" | |
healing_salve = "1" | |
arms_mastery = "2" | |
dragon_affinity = "3" | |
staff = "1" | |
chalice = "2" | |
bible = "3" | |
print("You wish to leave on a journey! You must now train.") | |
print("How would you like to train yourself?") | |
print(" 1> run laps around your house") | |
print(" 2> throw knives at the side of your house") | |
print(" 3> operate on training dummies") | |
training_method = get_choice("123") | |
if training_method == "1": | |
player_strength += 0.5 | |
print("Your training has made you stronger!") | |
elif training_method == "2": | |
player_accuracy += 10 | |
print("Your training has made you more accurate!") | |
elif training_method == "3": | |
player_dexterity += 1.0 | |
print("Your training has made you better at healing!") | |
print("You are nearly ready to begin your journey. Before leaving your home,") | |
print("you are able to select one of the following items:") | |
print(" 1> spear") | |
print(" 2> bow") | |
print(" 3> enchanted cloak") | |
special = get_choice("123") | |
print("Now, select a passive ability:") | |
print(" 1> eternal healing salve") | |
print(" 2> arms mastery") | |
print(" 3> dragon affinity") | |
passive = get_choice("123") | |
player_role = "" | |
# determine player role | |
if special == bow: | |
if training_method == "1": | |
player_role = "scout" | |
elif training_method == "2": | |
player_role = "grand archer" | |
elif training_method == "3": | |
player_role = "archer" | |
elif special == spear: | |
if training_method == "1": | |
player_role = "warrior" | |
elif training_method == "2": | |
player_role = "lancer" | |
elif training_method == "3": | |
player_role = "blacksmith" | |
elif special == enchanted_cloak: | |
if training_method == "1": | |
player_role = "spy" | |
elif training_method == "2": | |
player_role = "sniper" | |
elif training_method == "3": | |
player_role = "assassin" | |
if passive == dragon_affinity: | |
player_role = "half-dragon " + player_role | |
elif passive == arms_mastery: | |
player_role = "blood-thirsty " + player_role | |
elif passive == healing_salve: | |
if training_method == "1": | |
player_role = "doctor" | |
elif training_method == "2": | |
player_role = "medic" | |
elif training_method == "3": | |
player_role = "surgeon" | |
print("Oh, and what was your name, again?") | |
player_name = input() | |
if player_name == "": | |
player_name = "Hilbert Locke Demosthenes" | |
print("Well, " + str(player_name), "you truly are...") | |
print("...the " + player_role + "!") | |
print("You embark on your glorious quest!") | |
small_sleep() | |
small_sleep() | |
print("[[[ Day 1 - the journey begins ]]]") | |
print("You are walking along, when, all of a sudden, you are met by a wizard.") | |
print("WIZARD: Dear traveller! What brings you this way?") | |
ridiculous_responses = 0 | |
while True: | |
print(" 1> " + quote_str("None of your business, old man!")) | |
print(" 2> " + quote_str("I have come seeking glory, fame, and treasure!")) | |
print(" 3> " + quote_str("Oh, you know, just seeing the sights.")) | |
response_to_wizard = get_choice("123") | |
if response_to_wizard == "1" or ridiculous_responses >= 2: | |
print("The wizard scowls at you.") | |
print("WIZARD: Watch your tongue, whippersnapper.") | |
print("The wizard walks past you in a huff.") | |
break | |
elif response_to_wizard == "2": | |
print("The wizard smiles and shakes his head slightly.") | |
print("WIZARD: Foolish is the young one... Well, I suppose I must aid you:") | |
print(" not doing so would be child abuse.") | |
print(" Of my wares, which one would you like?") | |
print("YOU: I'd like your...") | |
print(" 1> staff") | |
print(" 2> most precious item") | |
print(" 3> wisdom") | |
wizard_item = get_choice("123") | |
valid_options += "5" | |
if wizard_item == staff: | |
print("WIZARD: An interesting decision...") | |
print("He hands you his wooden staff.") | |
elif wizard_item == chalice: | |
print("WIZARD: Tsk. I suppose that's how the young operate...") | |
print("He hands you a golden chalice.") | |
print("WIZARD: This was the Holy Chalice of Christ, I swear it.") | |
print("The wizard is visably crossing his fingers. Winking, he") | |
print("moves on.") | |
elif wizard_item == bible: | |
print("WIZARD: A wise young man! You shall surely do well.") | |
print("WIZARD: I shall give you what you asked for and more!") | |
# extended item | |
if special == spear: | |
item_name = "spear" | |
elif special == bow: | |
item_name = "bow" | |
elif special == enchanted_cloak: | |
item_name = "enchanted cloak" | |
arrows = 1337 | |
print("The wizard hands you a Bible. He notices your " + str(item_name) + ".") | |
print("WIZARD: I will surely make your " + str(item_name) + " more potent!") | |
print("He casts a spell with his staff, and your " + str(item_name)) | |
print("glows a brilliant yellow.") | |
super_bonus = True | |
print("WIZARD: Good luck, traveller.") | |
break | |
elif response_to_wizard == "3": | |
print("The wizard looks quizically at you.") | |
print("WIZARD: Here there be dragons. Surely this is not why you are here...") | |
print("WIZARD: What brings you this way?") | |
ridiculous_responses += 1 | |
small_sleep() | |
print("[[[ Day 2 - an encounter ]]]") | |
print("Hark! A dragon! What shall you do?") | |
print(" 1> flee") | |
print(" 2> fight") | |
choice = get_choice("12") | |
if choice == "1": | |
print("You begin to run...") | |
small_sleep() | |
if passive == dragon_affinity: | |
print("The dragon snatches you in its claws!") | |
small_sleep() | |
print("It smiles and sets you down atop its treasure.") | |
small_sleep() | |
outcome = pacifist_win | |
else: | |
print("You get chomped by the dragon!") | |
outcome = loss | |
small_sleep() | |
elif choice == "2": | |
print("[[[ PLAYER versus DRAGON ]]]") | |
print("You have a sword and shield, along with your chosen item.") | |
small_sleep() | |
turns_dot = 0 | |
arrows = 5 | |
times_bible_presented = 0 | |
heals_left = 10 | |
while dragon_hp > 0: | |
print("[[ Player's turn ]]") | |
if turns_dot > 0: | |
turns_dot -= 1 | |
if turns_dot == 0: | |
print("[i] You are no longer on fire.") | |
else: | |
print("[i] You are on fire.") | |
player_hp -= 3 | |
print("[-] You took 3 damage from the fire.") | |
if player_hp <= 0: | |
print("[!] You burned up!") | |
outcome = fire_loss | |
break | |
print("[i] You have " + str(player_hp) + " HP.") | |
print("[i] Your defense is " + str(player_defense) + ".") | |
print("[i] The dragon has " + str(dragon_hp) + " HP.") | |
damage = 0 | |
print("What shall you do?") | |
print(" 1> stab with your sword") | |
if has_member(valid_options, "2"): | |
super_msg = "" | |
if super_bonus: | |
super_msg = " (super)" | |
if special == spear: | |
print(" 2> throw your spear" + super_msg) | |
elif special == bow: | |
print(" 2> fire your bow (arrows remaining: " + str(arrows) + ")" + super_msg) | |
elif special == enchanted_cloak: | |
print(" 2> hide beneath your enchanted cloak" + super_msg) | |
else: | |
print() | |
else: | |
print() | |
print(" 3> raise your shield") | |
if passive == healing_salve: | |
print(" 4> heal") | |
elif has_member(valid_options, "4"): | |
print(" 4> heal (remaining: " + str(heals_left) + ")") | |
else: | |
print() | |
if wizard_item: | |
if wizard_item == staff: | |
print(" 5> cast a spell") | |
elif wizard_item == chalice: | |
print(" 5> present the chalice to the dragon") | |
elif wizard_item == bible: | |
print(" 5> present the bible to the dragon") | |
weapon_choice = get_choice(valid_options) | |
if weapon_choice == "1": | |
print("[>] You thrust your sword!") | |
damage = random.randint(6, 10) | |
elif weapon_choice == "2": | |
if special == spear: | |
if random.randint(1, 100) > player_accuracy: | |
# it missed! | |
print("[_] The spear misses!") | |
damage = 0 | |
else: | |
print("[>] The spear hits the dragon's flank!") | |
damage = random.randint(20, 30) + random.randint(10, 20) | |
if super_bonus: | |
print("[!] Your super spear regenerates!") | |
else: | |
valid_options = remove_from(valid_options, "2") | |
elif special == bow: | |
if arrows > 0: | |
arrows -= 1 | |
print("[ ] You fire off an arrow!") | |
if super_bonus: | |
print("[ ] An additional arrow appears from your super bow!") | |
# chance of missing: 10% | |
miss_bow_chance = random.randint(1, 100) | |
if super_bonus: | |
miss_bow_chance /= 2 | |
if miss_bow_chance > player_accuracy: | |
print("[_] It misses!") | |
if super_bonus: | |
print("[_] (The other arrow missed, too.)") | |
else: | |
damage = random.randint(10, 20) | |
if super_bonus: | |
damage += random.randint(10, 2) | |
print("[>] They embed themselves in the dragon!") | |
else: | |
print("[>] It embeds itself in the dragon!") | |
if arrows == 0: | |
valid_options = remove_from(valid_options, "2") | |
elif special == enchanted_cloak: | |
print("[d] You hide beneath the cloak!") | |
player_defense = 20 | |
if super_bonus: | |
print("[d] You're extra-sneaky under that cloak!") | |
player_defense *= 2 | |
elif weapon_choice == "3": | |
player_defense += 5 | |
print("[d] You heft your shield!") | |
damage = 0 | |
elif weapon_choice == "4": | |
to_heal = random.randint(2, 6) | |
# crit heal chance: 14% | |
if random.randint(1, 100) <= 14: | |
print("[!] Critical heal!") | |
to_heal *= 2 | |
if passive == healing_salve: | |
to_heal *= 2 | |
else: | |
heals_left -= 1 | |
if heals_left <= 0: | |
valid_options = valid_options.remove("4") | |
turns_dot = 0 | |
print("[+] You healed for " + str(to_heal) + " HP!") | |
player_hp += to_heal | |
elif weapon_choice == "5": | |
# cast a spell | |
if wizard_item == staff: | |
#todo: spells | |
print("[!] You wave your staff. It insta-kills the dragon.") | |
dragon_hp = 0 | |
outcome = todo_win() | |
break | |
elif wizard_item == chalice: | |
print("[ ] You present the chalice to the dragon.") | |
small_sleep() | |
if passive == dragon_affinity: | |
print("[!] The dragon accepts your gift. He lets you go.") | |
outcome = mutual_acceptance | |
break | |
else: | |
print("[?] The dragon takes your chalice. He gives you 1 HP.") | |
player_hp += 1 | |
small_sleep() | |
print("[?] Oh, and a bible.") | |
wizard_item = bible | |
elif wizard_item == bible: | |
print("[.] The dragon cocks its head at you.") | |
damage = -1 | |
times_bible_presented += 1 | |
small_sleep() | |
small_sleep() | |
print("[.] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [.]") | |
print(" 21 If your enemy is hungry, give him bread to eat,") | |
print(" and if he is thirsty, give him water to drink,") | |
print(" 22 for you will heap burning coals on his head,") | |
print(" and the Lord will reward you.") | |
print("[.] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [.]") | |
small_sleep() | |
small_sleep() | |
if damage != 0: | |
# critical chance: 7% | |
if random.randint(1, 100) <= 7: | |
damage *= 2 | |
print("[!] Critical hit!") | |
if passive == arms_mastery: | |
damage *= 2 | |
print("[+] Arms mastery doubled your damage!") | |
print("[>] You did " + str(damage) + " damage!") | |
dragon_hp -= damage | |
if dragon_hp <= 0: | |
print("[!] You have slain the dragon!") | |
outcome = old_fashioned_win | |
break | |
elif times_bible_presented >= 5: | |
print("[!] You have converted the dragon!") | |
outcome = evangalistic_win | |
break | |
pause() | |
# dragon's turn | |
print("[[ Dragon's turn ]]") | |
# print("~~~~~~~~~~" + str(player_defense)) | |
small_sleep() | |
# possible attacks: | |
# dragon breath (20%) | |
# chomp (30%) | |
# claw (50%) | |
enemy_attack = random.randint(1, 10) | |
# dragon breath | |
if 1 <= enemy_attack <= 2: | |
print("[<] The dragon spews its fiery breath towards you!") | |
enemy_damage = random.randint(1, 3) | |
# 50% chance of fire | |
if random.randint(1, 2) == 1: | |
turns_dot = 3 | |
print("[!] You're on fire!") | |
elif 3 <= enemy_attack <= 6: | |
print("[<] The dragon chomps on you!") | |
enemy_damage = random.randint(5, 10) | |
else: | |
enemy_damage = random.randint(1, 15) | |
print("[<] The dragon swipes at you!") | |
to_sub = player_defense | |
player_defense -= enemy_damage | |
enemy_damage -= to_sub | |
if enemy_damage < 0: | |
enemy_damage = 0 | |
if player_defense < 0: | |
player_defense = 0 | |
print("[-] You took " + str(enemy_damage) + " damage!") | |
player_hp -= enemy_damage | |
if player_defense < 0: | |
player_defense = 0 | |
if player_hp <= 0: | |
print("[!] You have succumbed to the might of the dragon!") | |
outcome = loss | |
break | |
pause() | |
outcome() | |
print("{ " + player_name + " the " + player_role + " }") | |
print("Play again?") | |
print(" y> yes") | |
print(" n> no") | |
play_again = get_choice("yn") | |
if play_again == "n": | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment