Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.94 KB | None | 0 0
  1. import Rooms
  2. import GameItems
  3. world = {}
  4.  
  5.  
  6. class Items:
  7. def __init__(self, name, info, weight):
  8. self.name = name
  9. self.info = info
  10. self.weight = weight
  11.  
  12.  
  13. class DoorKeys(Items):
  14. def __init__(self, name, info, weight):
  15. super().__init__(name, info, weight)
  16.  
  17.  
  18. class Weapon(Items):
  19. def __init__(self, name, info, damage, speed, weight):
  20. super().__init__(name, info, weight)
  21. self.damage = damage
  22. self.speed = speed
  23.  
  24.  
  25. GameItems.Sword
  26. GameItems.Knife
  27. GameItems.Stick
  28. GameItems.Rusty_Key
  29. GameItems.Ornate_Key
  30. GameItems.Moonstone
  31. GameItems.Flower
  32.  
  33.  
  34. class Room:
  35.  
  36. def __init__(self, name, description, exits, actions, roominv, roomkey, lock):
  37. self.name = name
  38. self.description = description
  39. self.exits = exits
  40. self.actions = actions
  41. self.roominv = roominv
  42. self.roomkey = roomkey
  43. self.lock = lock
  44.  
  45.  
  46. Rooms.world['introd']
  47. Rooms.world['clearing']
  48. Rooms.world['forest path']
  49. Rooms.world['stream']
  50. Rooms.world['shack']
  51. Rooms.world['inside shack']
  52. Rooms.world['cottage']
  53.  
  54.  
  55. class Player:
  56.  
  57. def __init__(self, name, health):
  58. self.name = name
  59. self.health = health
  60.  
  61.  
  62. class Location:
  63.  
  64. def __init__(self, room):
  65. self.room = Rooms.world[room]
  66.  
  67. def travel(self, direction):
  68. if direction not in Location.room.exits.keys():
  69. self.NoExit()
  70. else:
  71. self.SetNrN(direction)
  72.  
  73. def SetNrN(self, direction):
  74. NrN = self.room.exits[direction]
  75. print("moving to", NrN)
  76. self.KeyCheck(NrN)
  77.  
  78. def KeyCheck(self, NrN):
  79. if Rooms.world[NrN].lock and Rooms.world[NrN].roomkey not in bag.inventory:
  80. self.NoKey()
  81. else:
  82. Rooms.world[NrN].lock = False
  83. self.SetRoom(NrN)
  84. self.RoomDesc()
  85.  
  86. def SetRoom(self, NrN):
  87. self.room = Rooms.world[NrN]
  88.  
  89. def NoExit(self):
  90. print("You can't go that way!")
  91.  
  92. def NoKey(self):
  93. print('The door is locked! You need the right key!')
  94.  
  95. def RoomDesc(self):
  96. print(self.room.description)
  97. print(self.room.actions)
  98.  
  99.  
  100. class Bag:
  101.  
  102. def __init__(self, inventory):
  103. self.inventory = inventory
  104.  
  105. def addToInventory(self, key):
  106. self.inventory.append(Location.room.roominv[key])
  107. del Location.room.roominv[key]
  108.  
  109. def SearchRoom(self):
  110. if Location.room.roominv:
  111. for item in list(Location.room.roominv.keys()):
  112. print("you find a", item)
  113. else:
  114. print("You don't find anything")
  115.  
  116. def NoneHere(self, key):
  117. print("You can't find a", key)
  118.  
  119. def CheckTake(self):
  120. key = command.split()[1]
  121. if Location.room.roominv and key in Location.room.roominv:
  122. bag.addToInventory(key)
  123. print('you take the', key)
  124. else:
  125. self.NoneHere(key)
  126.  
  127. def CheckInv(self):
  128. for item in list(bag.inventory):
  129. print("Your bag contains:", item.name)
  130.  
  131.  
  132. player = Player("Jeff", 100)
  133. bag = Bag([])
  134. Location = Location('introd')
  135.  
  136. command = ' '
  137. while command != "":
  138. command = input('>>> ')
  139. if command in Location.room.exits:
  140. Location.travel(command)
  141. elif command == 'look':
  142. Location.RoomDesc()
  143. elif command == '':
  144. print('You have to say what it is you want to do!')
  145. command = '#'
  146. elif command == 'search':
  147. bag.SearchRoom()
  148. elif command.split()[0] == 'Take':
  149. bag.CheckTake()
  150. elif command == 'Inventory':
  151. bag.CheckInv()
  152. else:
  153. print('Invalid command')
  154.  
  155. from GameItems import Sword, Flower, Rusty_Key, Ornate_Key, Moonstone, Stick, Knife
  156.  
  157.  
  158. world['introd'] = Room('introd', "You are in a forest, you can hear wildlife all around you. There seems to be a clearing in the distance.", {'n': "clearing"}, {"Search the ground", "Go North"}, {'Sword': Sword}, None, False)
  159.  
  160. world['clearing'] = Room('clearing', "You are in a clearing surrounded by forest. Sunlight is streaming in, illuminating a bright white flower in the center of the clearing.
  161. To the South is the way you entered the forest. A well worn path goes to the East. In the distance a harp can be heard.", {'s': "introd", 'e': "forest path"}, {"Take flower", "Go south", "Go East"}, {'Flower': Flower}, None, False)
  162.  
  163. world['forest path'] = Room('forest path', "You begin walking down a well beaten path. The sounds of the forest surround you. Ahead you can see a fork in the road branching to the South and East.
  164. You can smell smoke coming from the South, and can hear a stream to the East", {'s': "cottage", 'e': "stream", 'w': "clearing"}, {"Go South", "Go East", "Go West"}, {'Stick': Stick}, None, False)
  165.  
  166. world['stream'] = Room('stream', "You come upon a relaxing stream at the edge of the woods. It looks like there is something shiny in the water. To your South is a rickety looking shack,
  167. to your West is the forest path you came down", {'s': "shack", 'w': "forest path"}, {"Go South", "Go West"}, {'Rusty_Key': Rusty_Key}, None, False)
  168.  
  169. world['shack'] = Room('shack', "In front of you is a shack, possibly used as an outpost for hunting. It looks dilapidated.", {'s': "inside shack", 'n': "stream"}, {"Go South", "Go North"}, None, None, False)
  170.  
  171. world['inside shack'] = Room('inside shack', "The inside of the shack is dirty. Bits of ragged fur are scattered about the floor and on a table against the back wall.
  172. A sharp looking knife is on the table. There is an ornate key hanging on the wall by a string.", {'n': "shack"}, {"Go North", "Take Knife", "Take Key"}, {'Knife': Knife, 'Ornate_Key': Ornate_Key}, Rusty_Key, True)
  173.  
  174. world['cottage'] = Room('cottage', "A quaint cottage sits in the middle of a small clearing, smoke drifting lazily from the chimney.", {'n': "forest path"}, {"Go north"}, {'Moonstone': Moonstone}, Ornate_Key, True)
  175.  
  176. Sword = Weapon("Sword", "A sharp looking sword. Good for fighting goblins!", 7, 5, 5)
  177. Knife = Weapon("Knife", "A wicked looking knife, seems sharp!", 5, 7, 3)
  178. Stick = Weapon("Stick", "You could probably hit someone with this stick if you needed to", 2, 3, 3)
  179. Rusty_Key = DoorKeys("Rusty_Key", "A key! I wonder what it opens.", .01)
  180. Ornate_Key = DoorKeys("Ornate_Key", "An ornate key with an engraving of a small cottage on one side", .01)
  181. Moonstone = Items("Moonstone", "A smooth white stone that seems to radiate soft white light", .05)
  182. Flower = Items("Flower", "A beautiful wildflower", .001)
  183.  
  184. # GameItems.py
  185. class Items:
  186. def __init__(...):
  187. ...
  188.  
  189. class DoorKeys(Items):
  190. ...
  191.  
  192. class Weapon(Items):
  193. ...
  194.  
  195. Sword = Weapon(...)
  196. Knife = Weapon(...)
  197. ...
  198. Flower = Items(...)
  199.  
  200. # World.py
  201.  
  202. from GameItems import *
  203.  
  204. class Room:
  205. ...
  206.  
  207. class Player:
  208. ...
  209.  
  210. class Location:
  211. ...
  212.  
  213. class Bag:
  214. ...
  215.  
  216.  
  217. WORLD = {}
  218. WORLD['introd'] = ...
  219. ...
  220. WORLD['cottage'] = ...
  221.  
  222. # Game.py
  223.  
  224. from World import *
  225. ...
  226.  
  227. def main():
  228. player = Player("Jeff", 100)
  229. ...
  230. command = ''
  231. while command != '':
  232. ...
  233. # game code here
  234.  
  235. if __name__ == '__main__':
  236. main()
  237.  
  238. ...
  239. if command in Location.room.exits:
  240. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement