#Text Adventure
import shlex
print
#prints the map for the thing
def map():
print ' ___________________'
print '| | |'
print '| | |'
print '| Room B = Room D |'
print '| Jack | Sword |'
print '| | |'
print '|----||---|----||---|'
print '| | |'
print '| Steve | |'
print '| Room A = Room C |'
print '|_________|_________|'
#Defines a Room Object
class Room(object):
def __init__(self, location, description,people,items):
self.location = location
self.description = description
self.people = people
self.items = items
def display_Room(self):
print self.description
#Defines People
class People(object):
def __init__(self,name,text,state):
self.name = name
self.text = text
self.state = state
def talk(self):
print self.text
#Defines Items
class Item(object):
def __init__(self,name,text,location):
self.name = name
self.text = text
self.location = location
def exam(self):
print self.text
#Creates da stuff
Sword = Item('Sword','This is a sword','22')
Gold = Item('Gold','This is gold','-')
Player = People('Player','','alive')
Steve = People('Steve',"Hi, I'm Steve. Dude, can you do me favor? Kill Jack",'alive')
Jack = People('Steve',"Sup, I'm Jack",'alive')
Jesse = People('Jesse','Go away.','alive')
#This doesn't really do something right now
#since I didn't really know how to implement it:(
peopleinroomA = [Steve]
peopleinroomB = [Jack]
peopleinroomC = []
peopleinroomD = [Jesse]
itemsinroomA = []
itemsinroomB = []
itemsinroomC = []
itemsinroomD = [Sword]
RoomA = Room(1001,'You are in Room A. You see Steve',peopleinroomA,itemsinroomA)
RoomB = Room(2001,'You are in Room B. Jack is here',peopleinroomB,itemsinroomB)
RoomC = Room(1002,'You are in Room C.You see Jesse',peopleinroomC,itemsinroomC)
RoomD = Room(2002,'You are in Room D. You see sword' ,peopleinroomD,itemsinroomD)
#defines the rooms that exist in the game
definedlocations = [RoomA.location,RoomB.location,RoomC.location,RoomD.location]
#defines the players location
location = {'xy':1001}
#opens up a open inventory list
Inventory = []
#adds to player location. 1000 for y values, 1 for the x values
#if a new location doesn't exist in the definedlocations list,
# it doesn't let you go there
def go(Decision,location):
test_n = location['xy']
test_n += 1000
test_s = location['xy']
test_s -= 1000
test_e = location['xy']
test_e += 1
test_w = location['xy']
test_w -= 1
if Decision == 'go north':
if test_n in definedlocations:
location['xy'] += 1000
else:
print "You can't go there"
elif Decision == 'go south':
if test_s in definedlocations:
location['xy'] -= 1000
else:
print "You can't go there"
elif Decision == 'go east':
if test_e in definedlocations:
location['xy'] += 1
else:
print "You can't go there"
elif Decision == 'go west':
if test_w in definedlocations:
location['xy'] -= 1
else:
print "You can't go there"
#decides what the person says, that you talk to
def talk(Decision):
if Decision == 'talk steve' or Decision == 'talk to steve':
if location['xy'] == 1001:
if Jack.state == 'dead':
print 'You killed Jack! Take this is a reward.'
print 'Gold added to Inventory'
Inventory.append('Gold')
elif Steve.state == 'dead':
print 'This person is dead.'\
else:
Steve.talk()
else:
print "This person is not here."
elif Decision == 'talk jack' or Decision == 'talk to jack':
if location['xy'] == 2001:
if Jack.state == 'dead':
print 'This person is dead.'
else:
Jack.talk()
else:
print 'This person is not here'
else:
print 'thing'
if Decision == 'talk jesse' or Decision == 'talk to jesse':
if location['xy'] == 1002:
if Jesse.state == 'dead':
print 'This person is dead'
elif 'Gold' in Inventory:
Drug = raw_input('You wanna buy some drugs?')
if Drug == 'no':
print 'Bitch'
elif Drug == 'yes':
Inventory.remove('Gold')
Inventory.append('Meth')
print 'Meth added to Inventory'
else:
print 'k'
else:
Jesse.talk()
else:
print 'This person is not here'
#adds something to your inventroy
def take(Decision):
if Decision == 'take sword':
if location['xy'] == 2002:
Inventory.append('Sword')
print 'Taken'
RoomD.description = 'You are in Room D.'
if Decision == 'take drugs' or 'take meth':
if 'Meth' in Inventory:
print 'YOU ARE HIGH'
else:
print "You can't do that"
#prints the inventory
def Inv():
print Inventory
#gives back the item description
def examine(Dec):
Decision = Dec.lower()
if Decision == 'examine gold':
if 'Gold' in Inventory:
Gold.exam()
else:
print "You can't do that."
if Decision == 'examine sword':
if 'Sword' in Inventory:
Sword.exam()
elif location['xy'] == 2002:
Sword.exam()
else:
print "You can't do that"
if Decision == 'examine meth':
if 'Meth' in Inventory:
Meth.exam()
else:
print "You can't do that'"
#kills someone, but only if you have the right weapon
def kill(Decision):
if Decision == 'kill steve':
Dec = raw_input('Kill Steve with what?')
Dec2 = Dec.lower()
if Dec2 == 'sword':
if 'Sword' in Inventory:
Steve.state = 'dead'
print 'Steve died'
RoomA.description = "You are in Room A. You see Steve's dead body"
else:
print "You can't do that"
else:
print "You can't do that"
elif Decision == 'kill jack':
Dec = raw_input('Kill Jack with what?')
Dec2 = Dec.lower()
if Dec2 == 'sword':
if 'Sword' in Inventory:
Jack.state = 'dead'
print 'Jack died'
RoomB.description = "You are in Room B. You see Jack's dead body"
else:
print "You can't do that"
else:
print "You can't do that"
elif Decision == 'kill myself':
Dec = raw_input('Kill yourself with what?')
Dec2 = Dec.lower()
if Dec2 == 'sword':
if 'Sword' in Inventory:
print 'You killed yourself. Good job. Really.'
print 'Game Over I guess'
Player.state = 'dead'
else:
print "You can't do that"
else:
print "You can't do that"
if Decision == "kill steve with sword":
if 'Sword' in Inventory:
if 'Sword' in Inventory:
Steve.state = 'dead'
print 'Steve died'
RoomA.description = "You are in Room A. You see Steve's dead body"
else:
print "You can't do that"
else:
print "You can't do that"
if Decision == "kill jack with sword":
if 'Sword' in Inventory:
Jack.state = 'dead'
print 'Jack died'
print Jack.state
RoomB.description = "You are in Room B. You see Jack's dead body"
else:
print "You can't do that"
if Decision == "kill myself with sword":
if 'Sword' in Inventory:
print 'You killed yourself. Good job. Really.'
print 'Game Over I guess'
Player.state = 'dead'
else:
print "You can't do that"
def help():
print "You can use the following commands:"
print "talk (person)"
print "kill (person) with (item)"
print "take (item)"
print "inventory"
print "examine (item)"
print "quit"
#gives back the current location
def printlocation(location):
if location['xy'] == 1001:
RoomA.display_Room()
elif location['xy'] == 2001:
RoomB.display_Room()
elif location['xy'] == 1002:
RoomC.display_Room()
elif location['xy'] == 2002:
RoomD.display_Room()
#the parser
#checks the first word in a command and then uses the corresponding funtion
def parser():
while Player.state == 'alive':
printlocation(location)
Decisionst = raw_input('>')
Decisionstr = Decisionst.lower()
lst = shlex.split(Decisionstr)
if lst[0] == 'go':
go(Decisionstr,location)
elif lst[0] == 'talk':
talk(Decisionstr)
elif lst[0] == 'take':
take(Decisionstr)
elif lst[0] == 'inventory':
Inv()
elif lst[0] == 'kill':
kill(Decisionstr)
elif lst[0] == 'examine':
examine(Decisionstr)
elif lst[0] == 'help':
help()
elif lst[0] == 'win':
print 'nice try'
elif Decisionstr == 'quit':
break
else:
print "Try again"
map()
parser()