Skip to content

Instantly share code, notes, and snippets.

@GalaxyCr8r
Last active December 8, 2020 04:05
Show Gist options
  • Save GalaxyCr8r/d195003a898758b530dc25d195f01b7f to your computer and use it in GitHub Desktop.
Save GalaxyCr8r/d195003a898758b530dc25d195f01b7f to your computer and use it in GitHub Desktop.
A simple text adventure for simple folk
## Karl's Kwuest!
from time import sleep
directions = ("north", "south", "west", "east")
print("Welcome to Karl's Kwest!")
print("")
player = {
'hp': 3,
'name': "",
'location': (0, 0),
}
inventory = []
while player["name"] == "":
player["name"] = input("What is thine name dost hero? ")
print("Hallo brave hero "+player['name']+"! After a night of bravely " +
"conquering barley pop, you come-to somewhere you don't recognize.\n")
sleep(1)
world = {
(0, 0): {
'description': "A old dank, dark small dungeon.",
'directions': {},
'items': {
'skull': {
'visible': True,
'look': ('A skull is barely within reach.',),
'talk': ('You say "To be or not to be" at it. Nothing happens.',),
'take': True,
}
},
},
}
items = {
'skull': {
'look': ('A clean skull from someone who obviously died ages ago.',),
'talk': ('You say "To be or not to be" at it. Nothing happens.',),
'use': ('You turn the skull over and a KEY drops to the floor!', 'ADD_CURRENT_ROOM', 'key'),
},
'key': {
'look': ("It's a brass grimy old key.",),
}
}
print ("(Commands you can use are /LOOK/, /TALK/, /USE/, or /TAKE/)")
print()
while player["hp"] > 0:
sleep(1)
currentLocation = world[player["location"]]
print(currentLocation['description'])
if currentLocation['items'] and len(currentLocation['items']) > 0:
for item in currentLocation['items']:
print("You see a " + item.upper())
print("")
playerInput = input(": ").lower().split()
command = playerInput[0]
print("command: " + command)
print()
if command in directions:
if player["location"] == (0, 0):
if "key" not in inventory:
print("You're stuck in this cell.")
else:
print("YOU'RE FREE!! CONGRATS!!")
break
elif command == 'look':
target = playerInput[1]
if target == "room":
if currentLocation['items'] and len(currentLocation['items']) > 0:
for item in currentLocation['items']:
print("You see a " + item.upper())
else:
print("You see nothing special here.")
continue
else:
if currentLocation['items'] and len(currentLocation['items']) > 0:
for item in currentLocation['items']:
if target == item:
print(currentLocation['items'][item]['look'][0])
break
continue
print("Couldn't find " + target)
elif command == 'talk':
pass
elif command == 'use':
pass
elif command == 'take':
# Check if the object to be took is in the room, and then check if it does something.
pass
elif command == 'quit' or command == 'exit':
result = input("Are you sure? (y/n) ").lower()
if result == 'y' or result == 'yes':
print("Your vision fades as the world slips from your consciousness as the capricious whims of the mortal who controlled you dictates that you should die.")
break
else:
print("I don't understand your command.")
print("Commands you can use are /LOOK/, /TALK/, /USE/, or /TAKE/")
print()
print("YOU DED")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment