Skip to content

Instantly share code, notes, and snippets.

@tjhartline
Created June 7, 2022 17:42
Show Gist options
  • Save tjhartline/15a83aee12d53a51edbef7fc69aeaa8d to your computer and use it in GitHub Desktop.
Save tjhartline/15a83aee12d53a51edbef7fc69aeaa8d to your computer and use it in GitHub Desktop.
My codes and workspaces.
import pyinputplus
from pyinputplus import *
def intro():
pass
intro()
#--Room start: Snow Whites Chambers function
global user_direction, items, inventory, item
# noinspection PyRedeclaration
items = ['pie', 'crowbar', 'potion', 'uniform', 'keys', 'spellbook']
# noinspection PyRedeclaration
inventory = ['Inventory List:']
# noinspection PyRedeclaration
item = ""
# noinspection PyShadowingNames,PyUnusedLocal
def snows_chambers():
user_direction = ""
print('''
Hello Prince Charming! I am glad Snow gave you good directions to get you into her old chambers from
the underground passageway. I am here to help you, as I have been in the castle before, but it has been
many years. I can tell you what room you are in, and what items may be useful, but that is about as far
as my usefulness goes. Okay, lets get moving. I do not want to chance encountering the Evil Queen.
([1])Go South
([2])Go East
([0]) EXIT Game
''')
#user enters direction 2 goes south,
# 3 goes east or 0 exits game
# user_direction = pyinputplus.inputChoice([0, 2, 3], 'Enter 2 or 3 to Continue or 0 to exit:\n')
# noinspection PyShadowingNames
user_direction = pyinputplus.inputChoice(['south', 'east', '0'], 'Enter south or east to continue or 0 to exit:')
if user_direction == 'south':
kitchen()
elif user_direction == 'east':
tea_room()
elif user_direction == '0':
print('\nWe only just started...Please come back to rescue the dwarves soon!')
exit(0)
def kitchen():
global item, user_direction
print('Items:', items, '\n', inventory)
print('We are in the kitchen.')
if 'pie' in items:
print('I hear something! SHHHHH!!')
time.sleep(2)
print('AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH!!')
time.sleep(2)
print('Stupid rat!! I think it wants food!! Here, cheese! Now SHEW! What did you find Charming?')
time.sleep(1)
item = pyinputplus.inputChoice(['pie', 'null'], 'Enter Item Name: \n')
items.remove('pie')
inventory.append('pie')
print('Ah, a pie!! That will keep stomach growls away! \nSorry, I had not realized it was so loud. I '
'skipped breakfast.')
time.sleep(2)
print('''
That helped. Thank you Prince. Now, I think we should try another room. Which way would like to go next?
([1]) Go South
([2]) Go East
([0]) EXIT Game
''')
user_direction = pyinputplus.inputChoice(['south', 'east', '0'], 'Enter south or east to continue '
'or 0 to exit:\n')
if user_direction == 'south':
library()
elif user_direction == 'east':
ballroom()
elif user_direction == '0':
print('Oh no!! Please hurry back before the Evil Queen kills the dwarves!')
time.sleep(2)
exit(0)
elif 'pie' not in items:
print('''Nothing else here is useful. I think we should try another room.Which way would like to go next?
([1]) Go South
([2]) Go East
([0]) EXIT Game
''')
user_direction = pyinputplus.inputChoice(['south', 'east', '0'], 'Enter south or east to continue '
'or 0 to exit:\n')
if user_direction == 'south':
library()
elif user_direction == 'east':
ballroom()
elif user_direction == '0':
print('Oh no!! Please hurry back before the Evil Queen kills the dwarves!')
time.sleep(2)
exit(0)
# noinspection PyShadowingNames
def tea_room():
print('You are in the Tea Room. Although, it looks like the evil queen makes her witches brew in here,\n '
'not tea. You go that way and I will go this way. Surely there is something useful in here.')
time.sleep(2)
print('Items:', items, '\n', inventory)
if 'potion' in items:
item = pyinputplus.inputChoice(['potion', 'none'], 'Enter item name:\n')
if item in 'potion':
items.remove('potion')
inventory.append('potion')
time.sleep(1)
print('Interesting...It looks like a sleeping potion, but I cannot be sure. We need to reference a \n'
'spellbook. Keep that and we will check it later. For now, we must keep moving.')
time.sleep(1)
user_direction = pyinputplus.inputChoice(['0', 'south'], 'Lets go south, I think it leads to the dungeon.\n'
'Enter south to continue or 0 to exit game:\n')
if user_direction == 'south':
ballroom()
elif user_direction == '0':
print('Oh no! They will surely die without you! Please come back soon!')
exit(0)
# noinspection PyShadowingNames
def ballroom():
print('''Oh, This is the Ballroom... or it used to be. I only recognized it because of the golden tiles on the
floor and the chandelier. It looks like the Evil Queens guardsmen have taken it over to store their
attire and worn out weaponry. Surely there is something useful in all this junk. Lets look...''')
time.sleep(2)
print('Items:', items, '\n', inventory)
if 'uniform' in items:
item = pyinputplus.inputChoice(['uniform', 'none'], 'Enter item name:\n')
if item in 'uniform':
items.remove('uniform')
inventory.append('uniform')
print('A guardsman uniform! That is perfect. Put it on.')
time.sleep(2)
print('Looking snazzy Charming. It may not fool the Evil Queen, but if we run into guards in the dungeon,')
time.sleep(2)
print('it should at least buy us a few minutes. Everything else here is worthless. Lets keep moving.')
user_direction = pyinputplus.inputChoice(['north', 'south', 'west', '0'], ''''
It looks like there are several ways to exit this room. I will let you choose this time.
([3]) Go West
([2]) Go South
([1]) Go North
([0]) EXIT Game
Enter north, south or west to continue or 0 to exit game:''')
if user_direction in 'north':
tea_room()
elif user_direction in 'south':
torture_chamber()
elif user_direction in 'west':
kitchen()
elif user_direction in '0':
print('Oh no!! Hurry back before the evil queen kills the dwarves!')
exit(0)
# noinspection PyShadowingNames
def library():
print('The Library. I have not been in this room in a very long time. *Cough*Cough*Cough.. given all the dust I \n'
'just breathed in, I would say no one else has either! Lets split up and look for books about \n'
'potions and spells.\n')
print('Items:', items, '\n', inventory)
if 'spellbook' in items:
item = pyinputplus.inputChoice(['spellbook', 'none'], 'When you find it, Enter item name:\n')
if item in 'spellbook':
items.remove('spellbook')
inventory.append('spellbook')
print('''
Perfect. The spellbook is exactly what I needed. Now I just need to compare the potion we found
earlier, to the ones in this book! I will wait until we reach the Armory to be certain it is
correct before encountering any guards.''')
time.sleep(2)
user_direction = pyinputplus.inputChoice(['north', 'east', '0'], '''
It looks like we can go through the door to the north and east. Which way do you think we should go?
([1]) Go North
([2]) Go East
([0]) EXIT Game
Enter north or east to continue traveling or Enter 0 to EXIT Game:\n''')
if user_direction in 'north':
kitchen()
elif user_direction in 'east':
torture_chamber()
elif user_direction in '0':
print('Oh no!! Hurry back before the evil queen kills the dwarves!')
exit(0)
# noinspection PyShadowingNames
def torture_chamber():
print('''Isssss tthhhaaattt one of those things they use to cut off heads??\nI guess the rumors of the Evil Queens
Torture Chamber is true, and we are in it!.....''')
time.sleep(1)
print('Sorry, of course Prince, I can be quieter...')
time.sleep(1)
print('''
Bububububu..but.. if you do not mind, I will take my leave now. I cannot risk loosing my head. I have not
used it enough!... Thank you Prince! Before I go, I think there is some sort of shinning metal thing in
the corner. You should take it. It may prove useful.''')
time.sleep(1)
print('Items:', items, '\n', inventory)
if 'crowbar' in items:
item = pyinputplus.inputChoice(['crowbar', 'none'], '''
Think Charming! Something shinny metal...hmm, the Queens dungeon keys
are black, so that only leaves one possible item. Enter item name:\n''')
if item in 'crowbar':
items.remove('crowbar')
inventory.append('crowbar')
print('Of course! A crowbar! Snow told me there is a trapdoor in the dungeon to use for our escape! \nIt '
'must be boarded over!\n')
time.sleep(2)
user_direction = pyinputplus.inputChoice(['north', 'east', 'west', '0'], '''
Okay Charming..get a hold of
yourself, the dungeon has to
be close..but which direction????
([1]) Go North
([2]) Go East
([3]) Go West
([0]) EXIT Game
Enter north, east or west to continue or 0 to exit:\n''')
if user_direction in 'north':
ballroom()
elif user_direction in 'east':
armory()
elif user_direction in 'west':
library()
elif user_direction in '0':
print('Oh no, the dwarves will surely be dead if you do not return soon!!')
exit(0)
# noinspection PyShadowingNames
def armory():
global item
if 'crowbar' and 'potion' and 'pie' and 'spellbook' and 'uniform' not in inventory:
print('You have to go back through the rooms to collect missing items. Once you have them,'
' you can return'
'to the Armory.')
ballroom()
if 'keys' not in inventory:
print('''
The Armory! "The guide told me to look through the spellbook to find what kind of potion I found.
............''')
time.sleep(2)
print('''I think this potion in the photo is the one we are looking for! Its a sleeping potion. PERFECT. It says
all I need to do is throw it and bust the glass and it should put everyone within five feet of it to sleep!
Now, all we have to find is the last item somewhere here in the Armory!''')
print('Items:', items, '\n', inventory)
if 'keys' in items:
item = pyinputplus.inputChoice(['keys', 'none'], '''Enter item name:\n''')
if item in 'keys':
items.remove('keys')
inventory.append('keys')
time.sleep(1)
print('''
Dungeon keys! These will definitely be useful. I was never very good at lock picking!
We must be getting close to the dungeon!....But...we are likely getting closer to the
Evil Queen as well.''')
time.sleep(2)
user_direction = pyinputplus.inputChoice(['0', 'north', 'south', 'west'], '''
Okay, I am almost certain one door leads back to the ballroom, but I am not sure of the other two.
([1]) Go North\n'
([2]) Go South\n'
([3]) Go West\n'
([0]) EXIT Game\n'
Enter north, south, or west to continue or 0 to EXIT Game:\n''')
if user_direction in 'north':
queen()
elif user_direction in 'south':
dungeon()
elif user_direction in 'west':
ballroom()
elif user_direction in '0':
print('No, you were so close. Please return quickly to save the dwarves from certain death!')
exit(0)
def queen():
print('The dungeon! Oh no, the guards recognized you, even with the uniform!...')
time.sleep(2)
print('CRACK! "Potion fog bellowing...zzzzzz.....zzzzzzz......zzzzzzzzzzzzzz, The sleeping potion worked')
time.sleep(1)
print('''The dwarves are rejoiced to see you! You quickly unlock their dungeon cells, use the crowbar to open the
'trapdoor, and escape the Evil Queens wrath and remain undetected! Thank you Prince Charming!..''')
time.sleep(1)
print('And they all lived...', end='')
time.sleep(1)
print('happily...', end='')
time.sleep(1)
print('ever...', end='')
time.sleep(1)
print('after!!')
exit(0)
def dungeon():
print('THE EVIL QUEEN!!!')
time.sleep(1)
print('''Here lies Prince Charming... He was captured by the evil queen, while trying to rescue the seven
dwarves...''')
time.sleep(1)
print('While trying to reach the dungeon, he stumbled into the queens evil layer instead...')
time.sleep(1)
print('''The Queens guards seized him and were instructed to hang him over the side of the castle. After three
days, all that her hungry crows left of the Prince was the bones in this grave....''')
time.sleep(2)
print('R.I.P. Prince Charming.')
exit(0)
snows_chambers()
kitchen()
tea_room()
library()
ballroom()
torture_chamber()
queen()
dungeon()
@tjhartline
Copy link
Author

IT-140 SNHU Text Based Game Project 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment