import random import time def win(name): print "YOU WIN! You Saved the Village,", name, "! They Rewarded you with your own Cottage!" retry = raw_input("\n\nWant to try again? (yes or no)\n\n").lower() if retry == "yes": game() else: quit() def gameOver(): print "Game OVER!!! The Villages are locked up, I guess forever." retry = raw_input("\n\nWant to try again? (yes or no)\n\n").lower() if retry == "yes": game() else: quit() def game(): gold = 50 character_hp = 125 weapon_damage = 15 monster_damage = 25 monster_payout = 80 weapons = ["fists"] MONSTERS = { "Wolf":105, "Goblin":55, "Dragon":150, "Zombie":80 } name = raw_input("\nWhat is your name\n\n").title() while name == "": name = raw_input("What is your name\n\n").title() print "Destroy the Dragon to save the Village, can you do it", name,"?" while character_hp > 0 and "Dragon" in MONSTERS: WEAPONS_STORE = { "sword":140, "axe":120, "mace":85, "bat":45 } store = raw_input("\nDo you want to buy weapons? (yes or no)\n\n").lower() if store == "yes": print "\nWEAPON\t\tCOST\n" for items in WEAPONS_STORE: print items, "\t\t", WEAPONS_STORE[items], "\n" print "\nYou have", gold, "gold\n\n" weapon_purchase = raw_input("Which weapon would you like to buy?\n\n").lower() while weapon_purchase not in WEAPONS_STORE or weapon_purchase in weapons: weapon_purchase = raw_input("\nWhich weapon would you like to buy?\n\n").lower() if weapon_purchase in WEAPONS_STORE and weapon_purchase not in weapons: if gold >= WEAPONS_STORE[weapon_purchase]: print "you bought a(n)", weapon_purchase, "\n" gold -= WEAPONS_STORE[weapon_purchase] weapons.append(weapon_purchase) print "\nyou have", gold, "gold\n" print "\nWeapons(s) you own\n" for items in weapons: print items elif gold <= WEAPONS_STORE[weapon_purchase]: print "not enough gold" elif store == "no": print "\nLets destroy a monster from the village!\n" print "\nMONSTERS\tHEALTH\t\n" for monster in MONSTERS: print monster, "\t\t", MONSTERS[monster], "\n" monchoice = raw_input("Which Monster do you want to Destroy from the Village?\n\n").title() if monchoice in MONSTERS: print "\n Good Luck! Destroy the", monchoice, "from the village!\n" else: print "That monster is not in the village" while monchoice not in MONSTERS: monchoice = raw_input("Which Monster do you want to Destroy from the Village\n\n").title() print "\nWEAPONS YOU OWN\n" for weapon in weapons: print weapon, "\n" weapuse = raw_input("\nWhich weapon do you choose?\n\n").lower() if weapuse in weapons: print "\nWise choice", name, "You will use the", weapuse, "against the", monchoice, "\n" if weapuse == "fists" or weapuse == "bat": while character_hp > 0 and MONSTERS[monchoice] > 0: rand = random.randint(3, 7) pdmg = weapon_damage + rand mdmg = monster_damage print monchoice, "has", MONSTERS[monchoice], "health left\n\n" time.sleep(1.5) print "The", monchoice, "attacked YOU by", mdmg character_hp -= mdmg if character_hp <= 0: gameOver(); print name,", your health is now", character_hp time.sleep(1.5) print "\nYou attacked the", monchoice, "with the", weapuse, "for", pdmg, "damage!" MONSTERS[monchoice] -= pdmg time.sleep(1.5) elif weapuse == "mace" or weapuse == "axe": while character_hp > 0 and MONSTERS[monchoice] > 0: rand = random.randint(5, 20) pdmg = weapon_damage + rand mdmg = monster_damage print monchoice, "has", MONSTERS[monchoice], "health left\n\n" time.sleep(1.5) print "The", monchoice, "attacked YOU by", mdmg character_hp -= mdmg if character_hp <= 0: gameOver(); print name,", your health is now", character_hp time.sleep(1.5) print "\nYou attacked the", monchoice, "with the", weapuse, "for", pdmg, "damage!" MONSTERS[monchoice] -= pdmg time.sleep(1.5) elif weapuse == "sword": while character_hp > 0 and MONSTERS[monchoice] > 0: rand = random.randint(15, 35) pdmg = weapon_damage + rand mdmg = monster_damage print monchoice, "has", MONSTERS[monchoice], "health left\n\n" time.sleep(1.5) print "The", monchoice, "attacked YOU by", mdmg character_hp -= mdmg if character_hp <= 0: gameOver(); print name,", your health is now", character_hp time.sleep(1.5) print "\nYou attacked the", monchoice, "with the", weapuse, "for", pdmg, "damage!" MONSTERS[monchoice] -= pdmg time.sleep(1.5) else: print name, "\nYou don't own the", weapuse,"!" while weapuse not in weapons: weapuse = raw_input("\nWhat weapon will you use?\n\n").lower() print "\nWise choice", name, "You will use the", weapuse, "against the", monchoice, "\n\n" if MONSTERS[monchoice] <= 0: print "\nThe", monchoice, "Has been destroyed, good work", name,"!" character_hp = 125 gold += monster_payout print "\nYou Have", gold, "gold\n" if monchoice == "Dragon": win(name) del MONSTERS[monchoice] game()
PTYHON TEXT ADVENTURE
Click 'Run The Code!', bottom right of the editor, to start the game!
Enter Answers in box below the console (after click on 'Run The Code!')