Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Text Adventure
- import shlex
- def map():
- print ' ______________________________'
- print '| | | |'
- print '| | | |'
- print '| Room B = Room D = Room E |'
- print '| Jack | Sword | Bear |'
- print '| | | |'
- print '|____||___|____||___|__________|'
- print '| | |'
- print '| | |'
- print '| Steve | Jesse |'
- print '| Room A = Room C |'
- print '| | |'
- print '|_________|_________|'
- class Room(object):
- def __init__(self, location,itemsinRoom, description,descriptionpeople,descriptiondirections):
- self.location = location
- self.itemsinRoom = itemsinRoom
- self.description = description
- self.descriptionpeople = descriptionpeople
- self.descriptiondirections = descriptiondirections
- def display_Room(self):
- stri = (' ')
- itemprint = []
- for item in self.itemsinRoom:
- itemprint.append('A ' + item.name + ' is here.')
- rtr = stri.join(itemprint)
- return self.description + self.descriptionpeople + rtr
- def printobejcts(self):
- pass
- class People(object):
- def __init__(self,location,name,text,description,state):
- self.location = location
- self.name = name
- self.text = text
- self.description = description
- self.state = state
- def printText(self):
- print self.text
- def go(self,location,Decision):
- newlocation = list(self.location)
- if Decision == 'go north' or Decision == 'go n' or Decision == 'n':
- newlocation[1] += 1
- test = world.get(tuple(newlocation))
- if test == None:
- print 'You cannot go there'
- else:
- Ply.location = tuple(newlocation)
- elif Decision == 'go south' or Decision == 'go s' or Decision == 's':
- newlocation[1] -= 1
- test = world.get(tuple(newlocation))
- if test == None:
- print 'You cannot go there'
- else:
- Ply.location = tuple(newlocation)
- elif Decision == 'go east' or Decision == 'go e' or Decision == 'e':
- newlocation[0] += 1
- test = world.get(tuple(newlocation))
- if test == None:
- print 'You cannot go there'
- else:
- Ply.location = tuple(newlocation)
- elif Decision == 'go west' or Decision == 'go w' or Decision == 'w':
- newlocation[0] -= 1
- test = world.get(tuple(newlocation))
- if test == None:
- print 'You cannot go there'
- else:
- Ply.location = tuple(newlocation)
- class Player(People):
- def __init__(self,location,name,text,state):
- self.location = location
- self.name = name
- self.text = text
- self.state = state
- def printlocation(self,location):
- return world.get(self.location).display_Room()
- def take(self,location,Decision):
- tokens = shlex.split(Decision)
- if len(tokens) != 2 or tokens[0] != 'take' or tokens[1] not in objects:
- print "This doesn't exist"
- else:
- if Ply.location == objects[tokens[1]].location:
- if objects[tokens[1]].ininv == 'no':
- Inventory.append(objects[tokens[1]].name)
- print 'Taken'
- objects[tokens[1]].ininv = 'yes'
- world.get(self.location).itemsinRoom.remove(objects[tokens[1]])
- elif objects[tokens[1]].ininv == 'no':
- print "You already have that"
- else:
- print "You don't see that"
- def drop(self,location,Decision):
- tokens = shlex.split(Decision)
- if len(tokens) != 2 or tokens[1] not in Inventory:
- print "You don't have that"
- else:
- objects[tokens[1]].ininv = 'no'
- Inventory.remove(objects[tokens[1]].name)
- objects[tokens[1]].location == self.location
- world.get(self.location).itemsinRoom.append(objects[tokens[1]])
- def talk(self,location,Decision):
- if Decision == 'talk steve' or Decision == 'talk to steve' or Decision == 'talk with steve':
- if self.location == Steve.location:
- if Jack.state == 'dead':
- if gold.ininv == 'no':
- print 'You killed Jack! Take this is a reward.'
- print 'Gold added to Inventory'
- Inventory.append(gold.name)
- elif gold.ininv == 'yes':
- print 'Thanks again, man.'
- elif Steve.state == 'dead':
- print 'This person is dead.'\
- else:
- Steve.printText()
- else:
- print "This person is not here."
- elif Decision == 'talk jack' or Decision == 'talk to jack' or Decision == 'talk with jack':
- if self.location == Jack.location:
- if Jack.state == 'dead':
- print 'This person is dead.'
- else:
- Jack.printText()
- else:
- print 'This person is not here'
- elif Decision == 'talk jesse' or Decision == 'talk to jesse' or Decision == 'talk with jesse':
- if self.location == Jesse.location:
- 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 'THEN FUCK OFF'
- elif Drug == 'yes':
- Inventory.remove('gold')
- Inventory.append(meth.name)
- print 'Gold removed from Inventory'
- print 'Meth added to Inventory'
- else:
- Jesse.printText()
- else:
- print 'This person is not here'
- elif Decision == 'talk bear' or Decision == 'talk to bear' or Decision == 'talk with bear':
- if self.location == Bear.location:
- if Bear.state == 'dead':
- print 'this monster is dead'
- else:
- Bear.printText()
- print 'The bear killed you'
- print 'Game over'
- Ply.state = 'dead'
- else:
- print 'This thing is not here'
- class Item(object):
- def __init__(self,name,text,location,cankill,ininv):
- self.name = name
- self.text = text
- self.location = location
- self.cankill = cankill
- self.ininv = ininv
- def kill(Decision):
- tokens = shlex.split(Decision)
- if len(tokens) == 2:
- if tokens[1] in people:
- if Ply.location == people[tokens[1]].location:
- killhelp(tokens[1])
- else:
- print 'This person is not here.'
- else:
- print 'This person does not exist'
- elif len(tokens) == 4:
- if tokens[2] == 'with':
- if tokens[1] in people:
- if Ply.location == people[tokens[1]].location:
- killhelpwithitem(tokens[3],tokens[1])
- else:
- print 'This person is not here.'
- else:
- print 'This person does not exist'
- else:
- print "This won't work"
- else:
- print "This doesn't work"
- def killhelp(victim):
- Dec = raw_input('With what?')
- Dec2 = Dec.lower()
- if Dec2 in objects:
- if Dec2 in Inventory:
- if objects[Dec2].cankill == 'yes':
- killcons(victim)
- else:
- print "You can't kill with that!"
- else:
- print "You don't have that."
- else:
- print "This doesn't exist."
- def killhelpwithitem(Item,victim):
- if Item in objects:
- if Item in Inventory:
- if objects[Item].cankill == 'yes':
- killcons(victim)
- else:
- print "You can't kill with that!"
- else:
- print "You don't have that."
- else:
- print "This doesn't exist."
- def killcons(victim):
- if victim == 'steve':
- Steve.state = 'dead'
- print 'Steve died'
- RoomA.descriptionpeople = "You see Steve's dead body. "
- if victim == 'jack':
- Jack.state = 'dead'
- print 'Jack died'
- RoomB.descriptionpeople = "You see Jack's dead body. "
- if victim == 'jesse':
- Jesse.state = 'dead'
- print 'Jesse died'
- RoomD.descriptionpeople = "You see Jesse's dead body. "
- if victim == 'myself':
- print 'You killed yourself. Good job, Really. Congratulations.'
- print 'Game over'
- Ply.state = 'dead'
- if victim == 'bear':
- print 'YOU CANNOT KILL A BEAR GODDAMNIT'
- def inv():
- stri = ', '
- print 'You have ' + stri.join(Inventory)
- def exam(Decision):
- tokens = shlex.split(Decision)
- if len(tokens) != 2 or tokens[0] != 'exam' or tokens[1] not in objects:
- print "This doesn't exist"
- else:
- if Ply.location == objects[tokens[1]].location or tokens[1] in Inventory:
- print objects[tokens[1]].text
- else:
- print "You don't see this"
- def dodrugs(Decision):
- if Decision == 'do meth' or 'do drugs':
- if 'meth' in Inventory:
- print 'YOU ARE HIGH'
- Inventory.remove('meth')
- meth.ininv = 'no'
- else:
- print "You don't have that"
- else:
- print "things"
- def helpp():
- print "You can use the following commands:"
- print "go (north,south,west,east)"
- print "talk (person)"
- print "kill (person) with (item)"
- print "take (item)"
- print "inventory"
- print "examine (item)"
- print "quit"
- Inventory = []
- sword = Item('sword','This is a sword',(2,2),'yes','no')
- gold = Item('gold','This is gold',(1,1),'no','no')
- meth = Item('meth','THIS IS SOME REALLY NICE BLUE METH',(1,2),'no','no')
- Ply = Player((1,1),'Player','','alive')
- Steve = People((1,1),'Steve',"Hi, I'm Steve. Dude, can you do me favor? Kill Jack.",'This is Steve','alive')
- Jack = People((1,2),'Jack',"Hi, I'm Jack.",'This is Jack','alive')
- Jesse = People((2,1),'Steve','Piss off, bitch.','This is Jesse','alive')
- Bear = People((3,2),'Bear','RAWWWRRR','THIS IS A FUCKING BEAR','alive')
- itemsinroomA = []
- itemsinroomB = []
- itemsinroomC = [sword]
- itemsinroomD = []
- itemsinroomE = []
- RoomA = Room((1,1),itemsinroomA,'You are in Room A.',' You see Steve. ',\
- ' You see a door to the north and to the east.')
- RoomB = Room((1,2),itemsinroomB,'You are in Room B.',' You see Jack. ',\
- ' You see a door to the south and to the east.')
- RoomC = Room((2,2),itemsinroomC,'You are in Room C.','',\
- ' You see a door to the west, to the east and to the south.')
- RoomD = Room((2,1),itemsinroomD,'You are in Room D.',' You see Jesse. ',\
- ' You see a door to the north and to the west.')
- RoomE = Room((3,2),itemsinroomE,'You are in Room E.',' You see a bear. ',\
- ' You see a door to the west.')
- world = {
- (1,1):RoomA,
- (1,2):RoomB,
- (2,2):RoomC,
- (2,1):RoomD,
- (3,2):RoomE
- }
- objects = {
- 'sword': sword,
- 'gold': gold,
- 'meth': meth
- }
- people = {
- 'steve': Steve,
- 'jack': Jack,
- 'jesse': Jesse,
- 'bear' : Bear,
- 'myself': Ply
- }
- emptyline = '\n'
- def main():
- print "Welcome to my Text Adventure!"
- print "Use the 'help' command for help!"
- while Ply.state == 'alive':
- print Ply.printlocation(Ply.location)
- Decisionst = raw_input('>')
- Decisionstr = Decisionst.lower()
- lst = shlex.split(Decisionstr)
- if lst[0] == 'go' or lst[0] in 'nwse':
- Ply.go(Ply.location,Decisionstr)
- elif lst[0] == 'take':
- Ply.take(Ply.location, Decisionstr)
- elif lst[0] == 'drop':
- Ply.drop(Ply.location,Decisionstr)
- elif lst[0] == 'quit':
- break
- elif lst[0] == 'talk':
- Ply.talk(Ply.location, Decisionstr)
- elif lst[0] == 'kill':
- kill(Decisionstr)
- elif lst[0] == 'die':
- killcons('myself')
- elif lst[0] == 'inventory' or lst[0] == 'inv' or lst[0] == 'i':
- inv()
- elif lst[0] == 'help':
- helpp()
- elif lst[0] == 'win':
- print 'nice try'
- elif lst[0] == 'shout':
- print 'AAARGGGGGGHHHHH'
- elif lst[0] == 'look':
- Ply.printlocation(Ply.location)
- elif lst[0] == 'examine' or 'exam':
- exam(Decisionstr)
- elif lst[0] == 'do drugs' or 'do meth':
- dodrugs()
- else:
- print 'This doesnt work'
- map()
- main()
- #TEST CODE
- """
- """
- #IDEAS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement