Exemplo n.º 1
0
 public void SerializeObject(string fileName, SerializeObject serializeObject)
 {
     try
     {
         BinaryFormatter binaryFormatter = new BinaryFormatter();
         using (Stream stream = File.Open(fileName, FileMode.Create))
         {
             binaryFormatter.Serialize(stream, serializeObject);
         }
     }
     catch (Exception)
     {
         GameBackground.CleanBackground();
         Console.SetCursorPosition(16, 10);
         Console.WriteLine("Error occured while trying to write to file.");
         System.Threading.Thread.Sleep(1000);
         GameBackground.CleanBackground();
         GameManager.Menu();
     }
 }
Exemplo n.º 2
0
 public static void LoadGame()
 {
     try
     {
         string          fileName        = "../../../Save.memory";
         Serializer      serializer      = new Serializer();
         SerializeObject serializeObject = new SerializeObject();
         serializeObject = serializer.Deserializeobject(fileName);
         GameEngine gameEngine = serializeObject.GameEngine;
         gameEngine.Run();
     }
     catch (Exception)
     {
         GameBackground.CleanBackground();
         Console.SetCursorPosition(8, 10);
         Console.WriteLine("Error occureed while trying to open file, or file doesn't exist ");
         System.Threading.Thread.Sleep(1000);
         GameBackground.CleanBackground();
         GameManager.Menu();
     }
 }