All pastes #943625 Raw Edit

Untitled

public text v1 · immutable
·published 2008-03-15 12:56 UTC
rendered paste body
 public void SaveMap( string name)
        {
            // Create file to save the data to
            FileStream fs = new FileStream( name, FileMode.Create );

            // Create an XmlSerializer object to perform the serialization
            XmlSerializer xs = new XmlSerializer( typeof (Tile) );

            for (int y = 0; y < _height; y++)
            {
                for (int x = 0; x < _width; x++)
                {
                    xs.Serialize( fs, _tiles[x, y] );
                }
            }

            // Close the file
            fs.Close();
        }

        public void LoadMap(string name)
        {
            // Create file to save the data to
            FileStream fs = new FileStream( name, FileMode.Open );

            // Create an XmlSerializer object to perform the serialization
            XmlSerializer xs = new XmlSerializer( typeof (Tile) );

            for (int y = 0; y < _height; y++)
            {
                for (int x = 0; x < _width; x++)
                {
                    _tiles[x, y] = (Tile) xs.Deserialize( fs );
                }
            }

            // Close the file
            fs.Close();
        }