Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Text Adventure
- import shlex
- class Room(object):
- def __init__(self, location, description):
- self.location = location
- self.description = description
- def display_Room(self):
- print self.description
- class People(object):
- def __init__(self,name,text,state,location):
- self.name = name
- self.text = text
- self.state = state
- self.location = location
- def talk(self):
- print self.text
- def go(self,location,Decision):
- newlocation = list(Player.location)
- if Decision == 'go north':
- newlocation[1] += 1
- test = world.get(tuple(newlocation))
- if test == None:
- print 'You cannot go there'
- else:
- self.location = tuple(newlocation)
- elif Decision == 'go south':
- newlocation[1] -= 1
- test = world.get(tuple(newlocation))
- if test == None:
- print 'You cannot go there'
- else:
- self.location = tuple(newlocation)
- elif Decision == 'go east':
- newlocation[0] += 1
- test = world.get(tuple(newlocation))
- if test == None:
- print 'You cannot go there'
- else:
- self.location = tuple(newlocation)
- elif Decision == 'go west':
- newlocation[0] -= 1
- test = world.get(tuple(newlocation))
- if test == None:
- print 'You cannot go there'
- else:
- self.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 pos(self,location):
- return self.location
- def printlocation(self,location):
- print world.get(self.location).display_Room()
- def take(self,location,Decision):
- if Decision == 'take sword':
- if self.location == Sword.location:
- Inventory.append(Sword)
- print 'Taken'
- RoomC.description = 'You are in Room C.'
- class Item(object):
- def __init__(self,name,text,location):
- self.name = name
- self.text = text
- self.location = location
- def exam(self):
- print self.text
- Inventory = []
- Sword = Item('Sword','This is a sword',(2,2))
- Player = Player((1,1),'Player','','alive')
- RoomA = Room((1,1),'You are in Room A.')
- RoomB = Room((1,2),'You are in Room B.')
- RoomC = Room((2,2),'You are in Room C. You see a sword')
- RoomD = Room((2,1),'You are in Room D.')
- world = {
- (1,1):RoomA,
- (1,2):RoomB,
- (2,2):RoomC,
- (2,1):RoomD,
- }
- def parser():
- while Player.state == 'alive':
- Player.printlocation(Player.location)
- Decisionst = raw_input('>')
- Decisionstr = Decisionst.lower()
- lst = shlex.split(Decisionstr)
- if lst[0] == 'go':
- Player.go(Player.location,Decisionstr)
- elif lst[0] == 'take':
- Player.take(Player.location, Decisionstr)
- elif lst[0] == 'quit':
- break
- else:
- print 'This doesnt work'
- parser()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement