def visit_shrine(self): """Head to the Shrine of the Unknowable Gods to make offerings.""" self.gods = godgen(2) msg = "The Shrine is mostly deserted at this time of day. " \ "Two of the altars catch your eye: one (choice 1) to " \ + self.gods[0] + ", which offers Enlightenment on a sliding " \ "tithe scale; and one (choice 2) to " + self.gods[1] + ", " \ "which promises Materialism for a single lump sum of 30,000gp." print textwrap.fill(msg), "\nChoice# Offering, or Leave" choice = get_user_input("Shrine> ", character = self.character, \ options = ["leave", "sheet", "equip", "help"]).lower() while choice != "leave": choice = choice.split() if len(choice) < 2 or (choice[0] != "1" and choice[0] != "2"): print "You need to pick both an altar number (1 or 2) " \ "and an offering amount." choice = get_user_input("Shrine> ", \ character = self.character, \ options = ["leave", "sheet", "equip", "help"]).lower() continue try: offering = int(choice[1]) except ValueError: print "You need to pick both an altar number (1 or 2) and " \ "an offering amount." choice = get_user_input("Shrine> ", \ character = self.character, \ options = ["leave", "sheet", "equip", "help"]).lower() continue self.offering(choice[0], offering) save(self) choice = get_user_input("Shrine> ", \ character = self.character, \ options = ["leave", "sheet", "equip", "help"]).lower() print "You leave the shrine and head back into the town square.", '\n'
def main(): """Initialize and start the game session""" send_to_console(logo) send_to_console(textwrap.fill("Welcome to Percival's Quest! This is a solo random " \ "dungeoncrawl rpg written in python by the ever-resourceful (and " \ "extremely humble) sirpercival.")) player_name = get_user_input("Please enter your player name> ") msg = "Welcome, " + player_name + "!" rpg_instance = pqr.PQ_RPG(player_name) newgame = False temp_rpg = load(rpg_instance) if temp_rpg: msg += " You currently have a game saved. Would you like to load it?" send_to_console(msg) loadit = get_user_input("Load (y/n)> ", options=['Yes', 'No', 'Y', 'N', 'Load']) if loadit.lower() in ["y", "yes", "load"]: rpg_instance = temp_rpg del temp_rpg send_to_console("Game successfully loaded.") rpg_instance.character.tellchar() else: newgame = True else: send_to_console(msg + " You don't have a character saved...") newgame = True if newgame: rpg_instance = generate(rpg_instance) msg = "You begin in the town square. \n" msg += "(Please note that at almost any prompt, you can choose Sheet " \ "to look at your charsheet, Equip to change your equipment, Help " \ "to enter the help library, or Quit to quit.)" send_to_console(textwrap.fill(msg)) msg = "To the East is your humble abode and warm bed; " \ "to the North, the General Store where various and sundry goods " \ "may be purchased; to the West, the City-Hall where the mayor " \ "makes his office; to the Northwest, the local Temple to the " \ "Unknowable Gods; and to the South lie the gates of the city, " \ "leading out to the Dungeon." send_to_console(textwrap.fill(msg)) town(rpg_instance)
def main(): """Initialize and start the game session""" send_to_console(logo) send_to_console(textwrap.fill("Welcome to Percival's Quest! This is a solo random " \ "dungeoncrawl rpg written in python by the ever-resourceful (and " \ "extremely humble) sirpercival.")) player_name = get_user_input("Please enter your player name> ") msg = "Welcome, "+player_name+"!" rpg_instance = pqr.PQ_RPG(player_name) newgame = False temp_rpg = load(rpg_instance) if temp_rpg: msg += " You currently have a game saved. Would you like to load it?" send_to_console(msg) loadit = get_user_input("Load (y/n)> ", options = ['Yes','No','Y','N','Load']) if loadit.lower() in ["y", "yes", "load"]: rpg_instance = temp_rpg del temp_rpg send_to_console("Game successfully loaded.") rpg_instance.character.tellchar() else: newgame = True else: send_to_console(msg + " You don't have a character saved...") newgame = True if newgame: rpg_instance = generate(rpg_instance) msg = "You begin in the town square. \n" msg += "(Please note that at almost any prompt, you can choose Sheet " \ "to look at your charsheet, Equip to change your equipment, Help " \ "to enter the help library, or Quit to quit.)" send_to_console(textwrap.fill(msg)) msg = "To the East is your humble abode and warm bed; " \ "to the North, the General Store where various and sundry goods " \ "may be purchased; to the West, the Questhall where the mayor " \ "makes his office; to the Northwest, the local Shrine to the " \ "Unknowable Gods; and to the South lie the gates of the city, " \ "leading out to the Dungeon." send_to_console(textwrap.fill(msg)) town(rpg_instance)
def check_riddleguess(self): """Handle guesses of the riddle answer.""" while self.riddleguess > 0: guess = get_user_input("Guess> ", character=self.char, options=["sheet", "equip", "help"]) self.riddleguess -= 1 # check for a valid guess badguess = 0 import string if len(guess.split()) > 1: badguess = 1 for i in guess: if i not in string.letters: badguess = 2 break if badguess: badguess_message = ["your guess should be one word only.'", "what you said isn't even a word.'"][ badguess - 1 ] print "The " + self.thing + " frowns. 'I do not know why you " "would waste a guess on that... " + badguess_message, "\n" continue # are they right? if guess.upper() == self.answer: self.success() return # are they done? if self.riddleguess <= 0: break answer_length = len(self.answer) pl = "s" if self.riddleguess != 1 else "" msg = ( "You have guessed incorrectly, leaving you with " + str(self.riddleguess) + " chance" + pl + " remaining. " ) msg += ( "Here is a hint to help you: the answer to the riddle " "is a single word with " + str(answer_length) + " letters." ) print msg, "\n" self.failure() return
def check_riddleguess(self): """Handle guesses of the riddle answer.""" while self.riddleguess > 0: guess = get_user_input("Guess> ", character=self.char, \ options = ["sheet", "equip", "help"]) self.riddleguess -= 1 #check for a valid guess badguess = 0 import string if len(guess.split()) > 1: badguess = 1 for i in guess: if i not in string.letters: badguess = 2 break if badguess: badguess_message = ["your guess should be one word only.'", \ "what you said isn't even a word.'"][badguess - 1] send_to_console("The " + self.thing + " frowns. 'I do not know why you " \ "would waste a guess on that... " + badguess_message, '\n') continue #are they right? if guess.upper() == self.answer: self.success() return #are they done? if self.riddleguess <= 0: break answer_length = len(self.answer) pl = "s" if self.riddleguess != 1 else "" msg = "You have guessed incorrectly, leaving you with " + \ str(self.riddleguess) + " chance" + pl + " remaining. " msg += "Here is a hint to help you: the answer to the riddle " \ "is a single word with " + str(answer_length) + " letters." send_to_console(msg, '\n') self.failure() return
def check_numguess(self): """A numeric Mastermind game! Give feedback on the guesses.""" while self.numguess > 0: guess = get_user_input("Guess> ", character=self.char, \ options = ["sheet", "equip", "help"]) self.numguess -= 1 #check for a valid guess badguess = False if len(guess) != 4: badguess = True for i in guess: try: j = int(i) except ValueError: badguess = True if badguess: send_to_console("The " + self.thing + " frowns. 'I do not know why " \ "you would waste a guess on that.'", '\n') continue copy_answer = [i for i in self.numcode] copy_guess = [i for i in guess] correct = [] #first pass: check for correct positions progress = 0 for i in range(4): if copy_guess[i] == copy_answer[i]: correct.append('rectus') copy_answer[i] = '*' copy_guess[i] = '*' progress += 2 #did they get it right? if ''.join(copy_answer) == '****' or progress == 8: self.success() return #if not, are they done? if self.numguess <= 0: break #if not, let's check for correct digits, incorrect positions for i in range(4): if copy_guess[i] != '*' and copy_guess[i] in copy_answer: correct.append('proxime') progress += 1 #fill out the rest with evil BWHAHA ncorrect = len(correct) for i in range(4 - ncorrect): correct.append('malum') #concatenate results hint = [] nums = ['', 'singuli', 'bini', 'terni', 'quaterni'] for i in ['rectus', 'proxime', 'malum']: num = correct.count(i) if num > 0: hint.append(nums[num] + ' ' + i) hint = ', '.join(hint) + '.' progress = (progress + 1) / 2 progmsg = ("The " + self.thing + " sighs. " + color.BOLD + \ "'You are nearly as far from correct as it is possible to be."\ " Perhaps this hint will help:", "The " + self.thing + " nods slowly. " + color.BOLD + \ "'You have some small skill at this sort of thing, " \ "it would seem. A hint to aid your progress:", "The " + self.thing + " quirks an eyebrow. " + color.BOLD + \ "'Perhaps you do not even need this hint, but I will " \ "provide it anyway:", "The " + self.thing + " smiles, showing a little too many " \ "teeth. " + color.BOLD + "'I am impressed -- you are nearly " \ "there. Another hint:") if self.numguess > 1: nummsg = "You have " + str(self.numguess) + " guesses " \ "remaining. Use them wisely.'" + color.END else: nummsg = "You have one guess remaining. Use it wisely.'" \ + color.END send_to_console(textwrap.fill(" ".join([progmsg[progress], hint, \ nummsg])), '\n') self.failure() return