Advertisement
Guest User

game2.py

a guest
Dec 12th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. class Gamestate():
  2. def __init__(self):
  3. self.roomdict = {}
  4. self.player = Player(name="unnamed")
  5.  
  6. def spawn_exits(self):
  7. for room in self.roomdict:
  8. if room.north != None:
  9. room.north = self.room_lookup(north)
  10. if room.east != None:
  11. room.east = self.room_lookup(east)
  12. if room.south != None:
  13. room.south = self.room_lookup(south)
  14. if room.west != None:
  15. room.west = self.room_lookup(west)
  16.  
  17. def room_lookup(self, rnum=1):
  18. if gamestate.player.rnum in self.roomdict.keys():
  19. return self.roomdict[rnum]
  20. else:
  21. return None
  22.  
  23. def add_room(self, room):
  24. if room.rnum in self.roomdict.keys():
  25. print("rnum %d already in room dictionary" % room.rnum)
  26. del(room)
  27. return
  28. self.roomdict[room.rnum] = room
  29.  
  30. def generate_world(self):
  31. self.add_room(Room(rnum=1, rname="main", rdesc="welcome to room main", north=2, south=3, east=4, west=5))
  32. self.add_room(Room(rnum=2, rname="trail", rdesc="welcome to room trail", south=1))
  33. self.add_room(Room(rnum=3, rname="boat", rdesc="welcome to room boat", north=1))
  34. self.add_room(Room(rnum=4, rname="East Shore", rdesc="welcome to the east shore", west=1))
  35. self.add_room(Room(rnum=5, rname="West Shore", rdesc="welcome to the west shore", east=1))
  36. self.spawn_exits()
  37.  
  38. class Room():
  39. def __init__(self, rnum, rname, rdesc, north=None, east=None, south=None, west=None):
  40. self.rnum = rnum
  41. self.name = rname
  42. self.desc = rdesc
  43. self.north = north
  44. self.east = east
  45. self.south = south
  46. self.west = west
  47.  
  48. class Player():
  49. def __init__(self,name, location):
  50. self.name = name
  51. self.hp = 100
  52. self.energy = 100
  53. self.location = location
  54.  
  55. gamestate = Gamestate()
  56.  
  57. gamestate.player.name = input("enter a name> ")
  58. print("\nhello %s" % (gamestate.player.name))
  59.  
  60. print(gamestate.room_lookup)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement