Skip to content

Instantly share code, notes, and snippets.

@Lambdanaut
Created September 8, 2012 22:59
Show Gist options
  • Select an option

  • Save Lambdanaut/3680703 to your computer and use it in GitHub Desktop.

Select an option

Save Lambdanaut/3680703 to your computer and use it in GitHub Desktop.
A Text Based RPG that my Nephew is working on.
# Constants
class Player:
def __init__(self):
self.name = "Clinton Bill"
self.room = Family_Den()
self.description = "You are a tall dark and mysterious rogue android hell bent on finding your creator. You are a robotic aparition used for being a butlerbot. "
self.items = [Tophat()]
def view_items(self):
print ('Your Inventory:')
counter = 1
for item in self.items:
print (str(counter) + ') ' + item.name + ': ' + item.description)
counter += 1
def get_item(self, item_name):
filtered_items = filter(lambda i: i.name.lower() == item_name, self.items)
if filtered_items: return filtered_items[0]
else: return None
# Rooms
class Room:
def __init__(self):
self.name = None
self.description = 'What will you do?'
self.items = []
self.doodads = []
def view_items(self):
counter = 1
everything = self.items + self.doodads
print("Items in " + self.name)
for item in everything:
print (str(counter) + ') ' + item.name)
counter += 1
def look(self):
print ("You're in the " + self.name)
print (self.description)
self.view_items()
class Family_Den(Room):
def __init__(self):
self.name = 'Family Den'
self.description = "There is a musty smell from cigarette smoke. "
self.items = [Golf_Club(), Piggy_Pajamas()]
self.doodads = [SNES(), Television()]
# Items
class Item:
def __init__(self):
self.name = None
self.description = 'thisw is da itrwem descwiption'
def action(self):
pass
class Golf_Club(Item):
def __init__ (self):
self.name = "Golf Club"
self.description = "What could I possibly need this for? A day at the green?"
class Tophat(Item):
def __init__ (self):
self.name = "Tophat"
self.description = "This hat makes you look devilishly handsome at the ballroom. "
class Piggy_Pajamas(Item):
def __init__ (self):
self.name = "PIGGY Pajamas"
self.description = "These look like they fit a 4 year old child. Why did you pick this up?"
#Doodads
class Television(Item):
def __init__ (self):
self.name = "Television"
self.description = "The television is on, you never knew a Mario Bros. movie could be so terrible. "
class SNES(Item):
def __init__ (self):
self.name = "Super Nintendo"
self.description = "Ahh the SNES, a couple minutes on Kirby Superstar wouldn't hurt anybody. "
# Main Game Functions
def input_loop(player):
while True:
# Get user_input
uinput = raw_input(' > ').lower()
# Get Player Bio
if uinput == "bio":
print (player.description)
# Get Player Items
elif uinput == "items":
player.view_items()
elif uinput == "look":
player.room.look()
else:
matched_player_item = player.get_item(uinput)
if matched_player_item:
matched_player_item.action()
# Command not found
else:
print ('Say What?')
def main():
# Initializes Game
player = Player()
# Startup Message
print ('*_STARTING UP_*....')
print ('Hello, to read about yourself type "Bio", while ingame type "Items" to see your inventory, the interactive items would be listed for every area, to interact with or use an item simply type its name. To know what room you\'re in type "look". Now you\'re ready to get going. ')
input_loop(player)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment