Guest User

Untitled

a guest
Oct 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.07 KB | None | 0 0
  1. def uppy():
  2.     print "-"*50
  3.     for num, obj in LocalGame.dObjectList.iteritems():
  4.         print "%s in room number %d"%(obj.Name,num)
  5.     print "-"*50
  6.  
  7. class Game_Handler(object):
  8.     def __init__(self):
  9.         self.dRooms = {}
  10.         self.dObjectList = {}
  11.         self.dCharList = {}
  12.         print "JoshMUD has been initialized"
  13.     def createRoom(self,name,desc,num): #This method creates a room, DERP
  14.         room = Room(name,desc,num)
  15.     def describeRoom(self,roomnum): #This method describes the roomnum
  16.         if roomnum in self.dRooms:
  17.             self.dRooms[roomnum].describe()
  18.         else:
  19.             print "An area of nil existance [nil]"
  20.             print
  21.             print "You cannot see anything."
  22.     def objectsInRoom(self,roomnum): #Returns a list containing the objects in the room
  23.         return [obj for num, obj in self.dObjectList.iteritems() if num == roomnum]
  24.     def createObject(self,name,num): #Creates an object and places it in the roomnum
  25.         object = Object(name,num)
  26.     def teleportObject(self,name,newnum): #Teleports the object with name
  27.         for num, obj in self.dObjectList.iteritems():
  28.             if obj.Name == name:
  29.                 uppy()
  30.                 obj.teleport(newnum)
  31.                 uppy()
  32.  
  33. LocalGame = Game_Handler()
  34.  
  35.  
  36. class Room(object): #The Room class, all in-game rooms will be instances of this
  37.     def __init__(self,name,desc,roomnumber):
  38.         if not roomnumber in LocalGame.dRooms: #If the room number isn't taken
  39.             self.Name = name
  40.             self.Description = desc
  41.             self.RoomNumber = roomnumber
  42.             LocalGame.dRooms[self.RoomNumber] = self #Make an entry in dRooms
  43.             print "A room has been created with room number %d." %self.RoomNumber
  44.         else:
  45.             print "A room was attempted to be created with room number %d, but that room number is already taken." %roomnumber
  46.     def describe(self):
  47.         print "%s [%d]"%(self.Name,self.RoomNumber)
  48.         print
  49.         print self.Description
  50.         for obj in LocalGame.objectsInRoom(self.RoomNumber):
  51.             print "You see a %s." %obj.Name
  52.  
  53. class Object(object): #The Object class, all in-game objects will be instances of this
  54.     def __init__(self,name,roomLoc): #self.RoomLoc is the room number it's in, name is obvious
  55.         self.Name = name
  56.         self.RoomLoc = roomLoc
  57.         print "A new object was created! It's a %s." %self.Name
  58.         if self.RoomLoc in LocalGame.dCharList:
  59.             print "A %s appears out of nowhere and drops to the floor."%self.Name
  60.         if not self.RoomLoc in LocalGame.dRooms:
  61.             print "The %s was created outside the realm of existance!" %self.Name
  62.         LocalGame.dObjectList[self.RoomLoc] = self
  63.     def teleport(self,newroom):
  64.         if newroom in LocalGame.dRooms:
  65.             uppy()
  66.             if self.RoomLoc in LocalGame.dCharList: #If someone is watching
  67.                 print "The %s is engulfed in a foggy blue haze, and then vanishes."%self.Name
  68.             del LocalGame.dObjectList[self.RoomLoc]
  69.             uppy()
  70.             self.RoomLoc = newroom
  71.             LocalGame.dObjectList[self.RoomLoc] = self #Re-enter the object entry
  72.             uppy()
  73.             if self.RoomLoc in LocalGame.dCharList:
  74.                 print "A foggy blue haze spreads out from a pinprick of light, then a %s reconstructs itself and drops to the floor."%self.Name
  75.             uppy()
  76.             print "A %s teleported to room %d!" %(self.Name,self.RoomLoc)
  77.             uppy()
  78.         else:
  79.             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)
  80.  
  81.  
  82. class Character(object): #The Character class. Constuctor arguments are name and starting room number, respectivly
  83.     def __init__(self,name,roomnum):
  84.         self.RoomNumber = roomnum
  85.         self.Name = name
  86.         print "%s entered the game! They are currently located at room number %d." %(self.Name,self.RoomNumber)
  87.         LocalGame.dCharList[self.RoomNumber] = self #Create an entry for the char
  88.         if self.RoomNumber in LocalGame.dRooms:
  89.             LocalGame.describeRoom(self.RoomNumber)
  90.         else:
  91.             print "%s was created out of the realm of existance!"%self.Name
  92.             print "An area of nil existance [nil]"
  93.             print
  94.             print "You cannot see anything."
  95.  
  96.     def switchRoom(self,newnumber): #This method switches the room number
  97.         if newnumber in LocalGame.dRooms:
  98.             del LocalGame.dCharList[self.RoomNumber]
  99.             self.RoomNumber = newnumber
  100.             LocalGame.dCharList[self.RoomNumber] = self
  101.             print "You walk to room %d." %self.RoomNumber
  102.             LocalGame.describeRoom(self.RoomNumber)
  103.         else:
  104.             print "You try to walk to room %d, but it is out of the realm of existance!"%newnumber
  105.  
  106. LocalGame.createRoom("A bare, white room","This is a bright white room with no features across the pale walls.",1)
  107. LocalGame.createRoom("An bare, slightly grey room","This is a slighty grey room with no features across the grey walls.",2)
  108. 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)
  109. LocalGame.createObject("bowl of soup",1)
  110. LocalCharacter = Character("Jishaxe",1)
  111.  
  112. '''while True:
  113.    inp = raw_input(">>>")
  114.    if inp == "l" or inp == "look": #Look command
  115.        if LocalCharacter.RoomNumber in dRooms:
  116.            for rnum, room in dRooms.iteritems():
  117.                if rnum == LocalCharacter.RoomNumber:
  118.                    room.Describe()
  119.    elif inp[0:7] == "create ": #Create command
  120.        sep = inp.find(" in room ",8) #Sep is location of " in room ", if found
  121.        if sep != -1: #If " in room " exists in the command
  122.            obname = inp[8:sep] #Seperate the object name from the string
  123.            roomnum = inp[sep + 8].int() #Seperate the room number from the string - TODO: Needs verification for intyness of the string
  124.            temp = cObject(obname,roomnum) #Create the object '''
Add Comment
Please, Sign In to add comment