Esempio n. 1
0
        public void SaveGame()
        {
            gameMap.Save(out ElementID[,] saveP, out float[,] saveT);
            saveContainer = new SaveContainer(saveP, saveT);

            IFormatter formatter = new BinaryFormatter();
            Stream     stream    = new FileStream("Save.grain", FileMode.Create, FileAccess.Write, FileShare.None);

            formatter.Serialize(stream, saveContainer);
            stream.Close();

            Console.WriteLine("save");
        }
Esempio n. 2
0
        public void LoadGame()
        {
            try
            {
                IFormatter    formatter     = new BinaryFormatter();
                Stream        stream        = new FileStream("Save.grain", FileMode.Open, FileAccess.Read, FileShare.Read);
                SaveContainer saveContainer = (SaveContainer)formatter.Deserialize(stream);
                stream.Close();

                this.gameMap.Load(saveContainer.saveParticles, saveContainer.saveTemps);

                Console.WriteLine("load");
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("unable to load");
            }
        }
Esempio n. 3
0
        public void LoadGame()
        {
            using (System.Windows.Forms.OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog())
            {
                fileDialog.InitialDirectory = Path.GetFullPath("Content\\");
                fileDialog.Filter           = "grain sim (*.grain)|*.grain";
                fileDialog.RestoreDirectory = true;

                if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //Get the path of specified file
                    string filePath = fileDialog.FileName;

                    IFormatter    formatter     = new BinaryFormatter();
                    Stream        stream        = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    SaveContainer saveContainer = (SaveContainer)formatter.Deserialize(stream);
                    stream.Close();

                    this.gameMap.Load(saveContainer.saveParticles, saveContainer.saveTemps);
                }
            }
        }
Esempio n. 4
0
        public void SaveGame()
        {
            using (System.Windows.Forms.SaveFileDialog fileDialog = new System.Windows.Forms.SaveFileDialog())
            {
                fileDialog.InitialDirectory = Path.GetFullPath("Content\\");
                fileDialog.Filter           = "grain sim (*.grain)|*.grain";
                fileDialog.RestoreDirectory = true;

                if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //Get the path of specified file
                    string filePath = fileDialog.FileName;

                    gameMap.Save(out ElementID[,] saveP, out float[,] saveT);
                    saveContainer = new SaveContainer(saveP, saveT);

                    IFormatter formatter = new BinaryFormatter();
                    Stream     stream    = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None);
                    formatter.Serialize(stream, saveContainer);
                    stream.Close();
                }
            }
        }