Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Gamestate():
- def __init__(self):
- self.roomdict = {}
- self.player = Player(name="unnamed")
- def spawn_exits(self):
- for room in self.roomdict:
- if room.north != None:
- room.north = self.room_lookup(north)
- if room.east != None:
- room.east = self.room_lookup(east)
- if room.south != None:
- room.south = self.room_lookup(south)
- if room.west != None:
- room.west = self.room_lookup(west)
- def room_lookup(self, rnum=1):
- if gamestate.player.rnum in self.roomdict.keys():
- return self.roomdict[rnum]
- else:
- return None
- def add_room(self, room):
- if room.rnum in self.roomdict.keys():
- print("rnum %d already in room dictionary" % room.rnum)
- del(room)
- return
- self.roomdict[room.rnum] = room
- def generate_world(self):
- self.add_room(Room(rnum=1, rname="main", rdesc="welcome to room main", north=2, south=3, east=4, west=5))
- self.add_room(Room(rnum=2, rname="trail", rdesc="welcome to room trail", south=1))
- self.add_room(Room(rnum=3, rname="boat", rdesc="welcome to room boat", north=1))
- self.add_room(Room(rnum=4, rname="East Shore", rdesc="welcome to the east shore", west=1))
- self.add_room(Room(rnum=5, rname="West Shore", rdesc="welcome to the west shore", east=1))
- self.spawn_exits()
- class Room():
- def __init__(self, rnum, rname, rdesc, north=None, east=None, south=None, west=None):
- self.rnum = rnum
- self.name = rname
- self.desc = rdesc
- self.north = north
- self.east = east
- self.south = south
- self.west = west
- class Player():
- def __init__(self,name, location):
- self.name = name
- self.hp = 100
- self.energy = 100
- self.location = location
- gamestate = Gamestate()
- gamestate.player.name = input("enter a name> ")
- print("\nhello %s" % (gamestate.player.name))
- print(gamestate.room_lookup)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement