Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def uppy():
- print "-"*50
- for num, obj in LocalGame.dObjectList.iteritems():
- print "%s in room number %d"%(obj.Name,num)
- print "-"*50
- class Game_Handler(object):
- def __init__(self):
- self.dRooms = {}
- self.dObjectList = {}
- self.dCharList = {}
- print "JoshMUD has been initialized"
- def createRoom(self,name,desc,num): #This method creates a room, DERP
- room = Room(name,desc,num)
- def describeRoom(self,roomnum): #This method describes the roomnum
- if roomnum in self.dRooms:
- self.dRooms[roomnum].describe()
- else:
- print "An area of nil existance [nil]"
- print
- print "You cannot see anything."
- def objectsInRoom(self,roomnum): #Returns a list containing the objects in the room
- return [obj for num, obj in self.dObjectList.iteritems() if num == roomnum]
- def createObject(self,name,num): #Creates an object and places it in the roomnum
- object = Object(name,num)
- def teleportObject(self,name,newnum): #Teleports the object with name
- for num, obj in self.dObjectList.iteritems():
- if obj.Name == name:
- uppy()
- obj.teleport(newnum)
- uppy()
- LocalGame = Game_Handler()
- class Room(object): #The Room class, all in-game rooms will be instances of this
- def __init__(self,name,desc,roomnumber):
- if not roomnumber in LocalGame.dRooms: #If the room number isn't taken
- self.Name = name
- self.Description = desc
- self.RoomNumber = roomnumber
- LocalGame.dRooms[self.RoomNumber] = self #Make an entry in dRooms
- print "A room has been created with room number %d." %self.RoomNumber
- else:
- print "A room was attempted to be created with room number %d, but that room number is already taken." %roomnumber
- def describe(self):
- print "%s [%d]"%(self.Name,self.RoomNumber)
- print
- print self.Description
- for obj in LocalGame.objectsInRoom(self.RoomNumber):
- print "You see a %s." %obj.Name
- class Object(object): #The Object class, all in-game objects will be instances of this
- def __init__(self,name,roomLoc): #self.RoomLoc is the room number it's in, name is obvious
- self.Name = name
- self.RoomLoc = roomLoc
- print "A new object was created! It's a %s." %self.Name
- if self.RoomLoc in LocalGame.dCharList:
- print "A %s appears out of nowhere and drops to the floor."%self.Name
- if not self.RoomLoc in LocalGame.dRooms:
- print "The %s was created outside the realm of existance!" %self.Name
- LocalGame.dObjectList[self.RoomLoc] = self
- def teleport(self,newroom):
- if newroom in LocalGame.dRooms:
- uppy()
- if self.RoomLoc in LocalGame.dCharList: #If someone is watching
- print "The %s is engulfed in a foggy blue haze, and then vanishes."%self.Name
- del LocalGame.dObjectList[self.RoomLoc]
- uppy()
- self.RoomLoc = newroom
- LocalGame.dObjectList[self.RoomLoc] = self #Re-enter the object entry
- uppy()
- if self.RoomLoc in LocalGame.dCharList:
- print "A foggy blue haze spreads out from a pinprick of light, then a %s reconstructs itself and drops to the floor."%self.Name
- uppy()
- print "A %s teleported to room %d!" %(self.Name,self.RoomLoc)
- uppy()
- else:
- print "A %s tried to teleport to room %d, but room %d does not exist so the %s could not!" %(self.Name,newroom,newroom,self.Name)
- class Character(object): #The Character class. Constuctor arguments are name and starting room number, respectivly
- def __init__(self,name,roomnum):
- self.RoomNumber = roomnum
- self.Name = name
- print "%s entered the game! They are currently located at room number %d." %(self.Name,self.RoomNumber)
- LocalGame.dCharList[self.RoomNumber] = self #Create an entry for the char
- if self.RoomNumber in LocalGame.dRooms:
- LocalGame.describeRoom(self.RoomNumber)
- else:
- print "%s was created out of the realm of existance!"%self.Name
- print "An area of nil existance [nil]"
- print
- print "You cannot see anything."
- def switchRoom(self,newnumber): #This method switches the room number
- if newnumber in LocalGame.dRooms:
- del LocalGame.dCharList[self.RoomNumber]
- self.RoomNumber = newnumber
- LocalGame.dCharList[self.RoomNumber] = self
- print "You walk to room %d." %self.RoomNumber
- LocalGame.describeRoom(self.RoomNumber)
- else:
- print "You try to walk to room %d, but it is out of the realm of existance!"%newnumber
- LocalGame.createRoom("A bare, white room","This is a bright white room with no features across the pale walls.",1)
- LocalGame.createRoom("An bare, slightly grey room","This is a slighty grey room with no features across the grey walls.",2)
- LocalGame.createRoom("A dark grey room with a window","This is a dark grey room with a single, square and framed window embedded in the east wall.",3)
- LocalGame.createObject("bowl of soup",1)
- LocalCharacter = Character("Jishaxe",1)
- '''while True:
- inp = raw_input(">>>")
- if inp == "l" or inp == "look": #Look command
- if LocalCharacter.RoomNumber in dRooms:
- for rnum, room in dRooms.iteritems():
- if rnum == LocalCharacter.RoomNumber:
- room.Describe()
- elif inp[0:7] == "create ": #Create command
- sep = inp.find(" in room ",8) #Sep is location of " in room ", if found
- if sep != -1: #If " in room " exists in the command
- obname = inp[8:sep] #Seperate the object name from the string
- roomnum = inp[sep + 8].int() #Seperate the room number from the string - TODO: Needs verification for intyness of the string
- temp = cObject(obname,roomnum) #Create the object '''
Add Comment
Please, Sign In to add comment