Ejemplo n.º 1
0
 def loadFeature(self, gameName, featureName):
     featurePath = './saved_games/' + gameName + '/features/' + featureName + '.txt'
     if os.path.exists(featurePath) == False:
         return -1
     else:
         inputFeature = open(featurePath, 'r')
         for line in inputFeature:
             if 'actionText' in line:
                 words = re.split("[:]+", line)
                 words = [x.strip() for x in words]
                 counter = 1
                 featureData = []
                 if len(words) > 1:
                     for x in words[1:]:
                         if counter & 1 and x != '':
                             featureData.append(
                                 (x, fixColor(words[counter + 1])))
                         counter += 1
             elif 'allowedActions' in line:
                 words = re.split("[:,]+", line)
                 words = [x.strip() for x in words]
                 featureData = []
                 if len(words) > 1:
                     for x in words[1:]:
                         if x != '':
                             featureData.append(x)
             else:
                 words = re.split("[:]+", line)
                 words = [x.strip() for x in words]
                 featureData = fixColor(words[1])
             setattr(self, words[0], featureData)
Ejemplo n.º 2
0
 def loadRoom(self, gameName, roomName):
     roomPath = './saved_games/' + gameName + '/rooms/' + roomName + '.txt'
     if os.path.exists(roomPath) == False:
         return -1
     else:
         inputRoom = open(roomPath, 'r')
         for line in inputRoom:
             roomData = ''
             if 'features' in line:
                 words = re.split("[:,]+", line)
                 words = [x.strip() for x in words]
                 roomData = []
                 if len(words) > 1:
                     for x in words[1:]:
                         if x != '':
                             myFeature = Feature()
                             myFeature.loadFeature(gameName, x)
                             roomData.append(myFeature)
             elif 'pickupObjects' in line:
                 words = re.split("[:,]+", line)
                 words = [x.strip() for x in words]
                 roomData = []
                 if len(words) > 1:
                     for x in words[1:]:
                         if x != '':
                             myObject = Obj()
                             myObject.loadObject(gameName, x)
                             roomData.append(myObject)
             else:
                 words = re.split("[:]+", line)
                 words = [x.strip() for x in words]
                 if words[0] == 'visited':
                     if(words[1] == 'True'):
                         roomData = True
                     else:
                         roomData = False
                 elif len(words) > 1:
                     roomData = fixColor(words[1])
             setattr(self, words[0], roomData)
Ejemplo n.º 3
0
 def loadObject(self, gameName, objectName):
     objectPath = './saved_games/' + gameName + '/objects/' + objectName + '.txt'
     if os.path.exists(objectPath) == False:
         return -1
     else:
         inputObject = open(objectPath, 'r')
         for line in inputObject:
             objectData = ''
             if 'actionText' in line:
                 words = re.split("[:]+", line)
                 words = [x.strip() for x in words]
                 counter = 1
                 objectData = []
                 if len(words) > 1 and words[1] != '':
                     for x in words[1:]:
                         if counter & 1:
                             objectData.append((x, words[counter + 1]))
                         counter += 1
             elif 'allowedActions' in line:
                 words = re.split("[:,]+", line)
                 words = [x.strip() for x in words]
                 objectData = []
                 if len(words) > 1 and words[1] != '':
                     for x in words[1:]:
                         objectData.append(x)
             elif 'dropped' in line:
                 words = re.split("[:,]+", line)
                 words = [x.strip() for x in words]
                 if (words[1] == 'True'):
                     objectData = True
                 else:
                     objectData = False
             else:
                 words = re.split("[:]+", line)
                 words = [x.strip() for x in words]
                 if len(words) > 1:
                     objectData = fixColor(words[1])
             setattr(self, words[0], objectData)