SHARE
    TWEET
    selib

    test

    Nov 9th, 2013
    86
    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. import shlex
    3. class Room(object):
    4. def __init__(self, location, description):
    5. self.location = location
    6. self.description = description
    7. def display_Room(self):
    8. print self.description
    9. class People(object):
    10. def __init__(self,name,text,state,location):
    11. self.name = name
    12. self.text = text
    13. self.state = state
    14. self.location = location
    15. def talk(self):
    16. print self.text
    17. def go(self,location,Decision):
    18. newlocation = list(Player.location)
    19. if Decision == 'go north':
    20. newlocation[1] += 1
    21. test = world.get(tuple(newlocation))
    22. if test == None:
    23. print 'You cannot go there'
    24. else:
    25. self.location = tuple(newlocation)
    26. elif Decision == 'go south':
    27. newlocation[1] -= 1
    28. test = world.get(tuple(newlocation))
    29. if test == None:
    30. print 'You cannot go there'
    31. else:
    32. self.location = tuple(newlocation)
    33. elif Decision == 'go east':
    34. newlocation[0] += 1
    35. test = world.get(tuple(newlocation))
    36. if test == None:
    37. print 'You cannot go there'
    38. else:
    39. self.location = tuple(newlocation)
    40. elif Decision == 'go west':
    41. newlocation[0] -= 1
    42. test = world.get(tuple(newlocation))
    43. if test == None:
    44. print 'You cannot go there'
    45. else:
    46. self.location = tuple(newlocation)
    47. class Player(People):
    48. def __init__(self,location,name,text,state):
    49. self.location = location
    50. self.name = name
    51. self.text = text
    52. self.state = state
    53. def pos(self,location):
    54. return self.location
    55. def printlocation(self,location):
    56. print world.get(self.location).display_Room()
    57. def take(self,location,Decision):
    58. if Decision == 'take sword':
    59. if self.location == Sword.location:
    60. Inventory.append(Sword)
    61. print 'Taken'
    62. RoomC.description = 'You are in Room C.'
    63. class Item(object):
    64. def __init__(self,name,text,location):
    65. self.name = name
    66. self.text = text
    67. self.location = location
    68. def exam(self):
    69. print self.text
    70. Inventory = []
    71. Sword = Item('Sword','This is a sword',(2,2))
    72. Player = Player((1,1),'Player','','alive')
    73. RoomA = Room((1,1),'You are in Room A.')
    74. RoomB = Room((1,2),'You are in Room B.')
    75. RoomC = Room((2,2),'You are in Room C. You see a sword')
    76. RoomD = Room((2,1),'You are in Room D.')
    77. world = {
    78. (1,1):RoomA,
    79. (1,2):RoomB,
    80. (2,2):RoomC,
    81. (2,1):RoomD,
    82. }
    83. def parser():
    84. while Player.state == 'alive':
    85. Player.printlocation(Player.location)
    86. Decisionst = raw_input('>')
    87. Decisionstr = Decisionst.lower()
    88. lst = shlex.split(Decisionstr)
    89. if lst[0] == 'go':
    90. Player.go(Player.location,Decisionstr)
    91. elif lst[0] == 'take':
    92. Player.take(Player.location, Decisionstr)
    93. elif lst[0] == 'quit':
    94. break
    95. else:
    96. print 'This doesnt work'
    97. parser()
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /