Quote Originally Posted by Niya View Post
Well my friend the solution is far more simple than you realize:-
vbnet Code:
  1. Public Class MapInfo
  2.  
  3.     Private _colTiles As New Collections.ObjectModel.Collection(Of tilerec)
  4.  
  5.     Public Property Tiles() As Collections.ObjectModel.Collection(Of tilerec)
  6.         Get
  7.             Return _colTiles
  8.         End Get
  9.         Set(ByVal value As Collections.ObjectModel.Collection(Of tilerec))
  10.             _colTiles = value
  11.         End Set
  12.     End Property
  13.  
  14.  
  15. End Class

You can create a class like the above and use XML serialization to save and load:-
vbnet Code:
  1. '
  2.     Public Function LoadMapInfo(ByVal fileName As String) As MapInfo
  3.         Dim ser As New XmlSerializer(GetType(MapInfo))
  4.         Dim fs As New FileStream(fileName, FileMode.Open)
  5.         Dim ret As MapInfo
  6.  
  7.         ret = ser.Deserialize(fs)
  8.  
  9.         fs.Close()
  10.         fs.Dispose()
  11.  
  12.         Return ret
  13.  
  14.     End Function
  15.  
  16.     Public Sub SaveMapInfo(ByVal map As MapInfo, ByVal fileName As String)
  17.         Dim ser As New XmlSerializer(GetType(MapInfo))
  18.         Dim fs As New FileStream(fileName, FileMode.Create)
  19.  
  20.         ser.Serialize(fs, map)
  21.  
  22.         fs.Close()
  23.         fs.Dispose()
  24.     End Sub

The above functions can load and save the class to a file and load it back. Here is an example of their use:-
vbnet Code:
  1. '
  2.         Dim mi As New MapInfo
  3.  
  4.         mi.Tiles.Add(New tilerec With {.data = 12, .name = "Unknown", .x = 11, .y = 0})
  5.         mi.Tiles.Add(New tilerec With {.data = 11, .name = "Bing", .x = 12, .y = 4})
  6.         mi.Tiles.Add(New tilerec With {.data = 122, .name = "True", .x = 40, .y = 155})
  7.         mi.Tiles.Add(New tilerec With {.data = 3000, .name = "GRRR...!!", .x = 30, .y = 122})
  8.  
  9.         SaveMapInfo(mi, "c:\MI.TXT")
  10.  
  11.  
  12.         Dim mi2 As MapInfo = LoadMapInfo("C:\MI.TXT")

The saved data would look like this:-
xml Code:
  1. <?xml version="1.0"?>
  2. <MapInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  3.   <Tiles>
  4.     <tilerec>
  5.       <x>11</x>
  6.       <y>0</y>
  7.       <data>12</data>
  8.       <name>Unknown</name>
  9.     </tilerec>
  10.     <tilerec>
  11.       <x>12</x>
  12.       <y>4</y>
  13.       <data>11</data>
  14.       <name>Bing</name>
  15.     </tilerec>
  16.     <tilerec>
  17.       <x>40</x>
  18.       <y>155</y>
  19.       <data>122</data>
  20.       <name>True</name>
  21.     </tilerec>
  22.     <tilerec>
  23.       <x>30</x>
  24.       <y>122</y>
  25.       <data>3000</data>
  26.       <name>GRRR...!!</name>
  27.     </tilerec>
  28.   </Tiles>
  29. </MapInfo>

However, games generally don't save their map data in a text format like Xml. A binary version of the same data would be far smaller in size and much faster in IO operations. You should consider that, its not absolutely necessary, its just more efficient. It should only take a mild alteration to the above code to make it serialize as a binary file instead of Xml.
Tiles should be a readonly property