Advertisement
selib

test

Nov 9th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.32 KB | None | 0 0
  1. #Text Adventure
  2.  
  3. import shlex
  4.  
  5. class Room(object):
  6.     def __init__(self, location, description):
  7.         self.location = location
  8.         self.description = description
  9.  
  10.  
  11.     def display_Room(self):
  12.         print self.description
  13.  
  14.  
  15. class People(object):
  16.     def __init__(self,name,text,state,location):
  17.         self.name = name
  18.         self.text = text
  19.         self.state = state
  20.         self.location = location
  21.  
  22.     def talk(self):
  23.         print self.text
  24.  
  25.  
  26.  
  27.     def go(self,location,Decision):
  28.  
  29.         newlocation = list(Player.location)
  30.  
  31.  
  32.         if Decision == 'go north':
  33.             newlocation[1] += 1
  34.             test = world.get(tuple(newlocation))
  35.             if test == None:
  36.                 print 'You cannot go there'
  37.             else:
  38.                 self.location = tuple(newlocation)
  39.         elif Decision == 'go south':
  40.             newlocation[1] -= 1
  41.             test = world.get(tuple(newlocation))
  42.             if test == None:
  43.                 print 'You cannot go there'
  44.             else:
  45.                 self.location = tuple(newlocation)
  46.  
  47.         elif Decision == 'go east':
  48.             newlocation[0] += 1
  49.             test = world.get(tuple(newlocation))
  50.             if test == None:
  51.                 print 'You cannot go there'
  52.             else:
  53.                 self.location = tuple(newlocation)
  54.  
  55.         elif Decision == 'go west':
  56.             newlocation[0] -= 1
  57.             test = world.get(tuple(newlocation))
  58.             if test == None:
  59.                 print 'You cannot go there'
  60.             else:
  61.                 self.location = tuple(newlocation)
  62.  
  63.  
  64. class Player(People):
  65.     def __init__(self,location,name,text,state):
  66.         self.location = location
  67.         self.name = name
  68.         self.text = text
  69.         self.state = state
  70.  
  71.  
  72.  
  73.     def pos(self,location):
  74.         return self.location
  75.  
  76.  
  77.     def printlocation(self,location):
  78.         print world.get(self.location).display_Room()
  79.  
  80.     def take(self,location,Decision):
  81.         if Decision == 'take sword':
  82.              if self.location == Sword.location:
  83.                 Inventory.append(Sword)
  84.                 print 'Taken'
  85.                 RoomC.description = 'You are in Room C.'
  86.  
  87.  
  88. class Item(object):
  89.     def __init__(self,name,text,location):
  90.         self.name = name
  91.         self.text = text
  92.         self.location = location
  93.  
  94.     def exam(self):
  95.         print self.text
  96.  
  97.  
  98.  
  99. Inventory = []
  100.  
  101.  
  102. Sword = Item('Sword','This is a sword',(2,2))
  103.  
  104. Player = Player((1,1),'Player','','alive')
  105.  
  106.  
  107. RoomA = Room((1,1),'You are in Room A.')
  108. RoomB = Room((1,2),'You are in Room B.')
  109. RoomC = Room((2,2),'You are in Room C. You see a sword')
  110. RoomD = Room((2,1),'You are in Room D.')
  111.  
  112.  
  113.  
  114. world = {
  115. (1,1):RoomA,
  116. (1,2):RoomB,
  117. (2,2):RoomC,
  118. (2,1):RoomD,
  119. }
  120.  
  121.  
  122.  
  123.  
  124. def parser():
  125.     while Player.state == 'alive':
  126.  
  127.         Player.printlocation(Player.location)
  128.         Decisionst = raw_input('>')
  129.         Decisionstr = Decisionst.lower()
  130.         lst = shlex.split(Decisionstr)
  131.         if lst[0] == 'go':
  132.             Player.go(Player.location,Decisionstr)
  133.         elif lst[0] == 'take':
  134.             Player.take(Player.location, Decisionstr)
  135.         elif lst[0] == 'quit':
  136.             break
  137.         else:
  138.             print 'This doesnt work'
  139.  
  140.  
  141. parser()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement