Guest User

Untitled

a guest
Feb 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. from textwrap import dedent
  2. from sys import exit
  3.  
  4. class Player(object):
  5.  
  6.  
  7. actions = {
  8. 'QUIT': quit
  9. }
  10. def __init__(self, actions):
  11. self.actions = actions
  12. # Want actions to be a list of actions like in the Room Class
  13. #
  14.  
  15. def quit(self):
  16. # Quits the game
  17. exit(0)
  18.  
  19. class Room(object):
  20.  
  21. # Description is just a basic room description. No items needed to be added here.
  22. def __init__(self, desc, exits, exitdesc):
  23. self.desc = desc
  24. self.exits = exits
  25. self.exitdesc = exitdesc
  26. # Also want list of general actions for a room here.
  27.  
  28. def enterroom(self):
  29. #First print the description of the room
  30. print(self.desc)
  31. #Then print the list of exits.
  32. if len(self.exits) > 1:
  33. print(f"You see the following exits:")
  34. for exd in self.exitdesc:
  35. print(self.exitdesc[exd])
  36. elif len(self.exits) == 1:
  37. print(f"There is one exit:")
  38. for exd in self.exitdesc:
  39. print(self.exitdesc[exd])
  40. else:
  41. print("There are no exits.")
  42. # Then allow the player to make a choice.
  43. self.roomactivity()
  44.  
  45. # Here's what I mean about calling the methods via a dictionary
  46. def roomactivity(self):
  47. while True:
  48. print("What do you want to do?")
  49. choice = input("> ").upper()
  50. if choice in self.exits:
  51. self.exits[choice].enterroom()
  52.  
  53. #And here's where I want to call actions other than directions.
  54. elif choice in player.actions:
  55. player.actions[choice]
  56. else:
  57. print("I don't understand.")
  58.  
  59. class VoidRoom(Room):
  60. def __init__(self):
  61. super().__init__(
  62. desc = "ONLY VOID.",
  63. exits = {},
  64. exitdesc = {})
  65.  
  66. class TestRoom(Room):
  67. def __init__(self):
  68. super().__init__(
  69. desc = dedent("""
  70. This room is only a test room.
  71. It has pure white walls and a pure white floor.
  72. Nothing is in it and you can hear faint echoes
  73. of some mad sounds."""),
  74.  
  75. exitdesc = {
  76. 'NORTH': 'To the NORTH is a black door.',
  77. 'SOUTH': 'To the SOUTH is a high window.',
  78. 'EAST': 'To the EAST is a red door.',
  79. 'WEST': 'To the WEST is a blue door.'},
  80. exits = {
  81. 'NORTH': void_room,
  82. 'SOUTH': void_room,
  83. 'EAST': void_room,
  84. 'WEST': void_room})
  85.  
  86. void_room = VoidRoom()
  87. test_room = TestRoom()
  88. player = Player()
  89.  
  90. test_room.enterroom()
Add Comment
Please, Sign In to add comment