Пример #1
0
 public void SaveMapToFile(string filename)
 {
     map.ClearAttachment();
     //Create the file.
     using (FileStream fs = File.Create(filename))
     {
         map.ClearArray();//清空数组内容再存储,以节省存储空间
         BinaryFormatter formatter = new BinaryFormatter();
         formatter.Serialize(fs, map);
         fs.Close();
         map.RestoreArrayFromList();//从List恢复内容到数组
     }
 }
Пример #2
0
 public void LoadMapFromFile(string filename)
 {
     //Open the stream and read it back.
     using (FileStream fs = File.OpenRead(filename))
     {
         BinaryFormatter formatter = new BinaryFormatter();
         PositionMap     newMap    = (PositionMap)formatter.Deserialize(fs);
         if (newMap != null)
         {
             map = newMap;
             map.RestoreArrayFromList();//从List恢复内容到数组
             mapWidth  = map.GetWidth();
             mapHeight = map.GetHeight();
             ChangeMapSize(mapWidth, mapHeight);
             AdapteBlockSizeAccordingToMapSize();
             ClearTags();
             drawMap();
         }
         fs.Close();
     }
 }