示例#1
0
        // Simple statement for game deletion on starting a new game
        public static bool DeleteSave()
        {
            if (String.IsNullOrEmpty(File.ReadAllText(LocalSavePath)))
            {
                return(true);
            }
            LineHelpers.PrintLine("Are you sure you want to delete your save?");
            LineHelpers.PrintLine("1. Yes");
            LineHelpers.PrintLine("2. No");

            var input = LineHelpers.ReadInputNumber(new int[] { 1, 2 });

            if (input == 1)
            {
                try
                {
                    File.WriteAllText(LocalSavePath, "");
                    LineHelpers.PrintLineWithContinue("Save game deleted...");
                    return(true);
                }
                catch
                {
                    LineHelpers.PrintLineWithContinue("Error, save was not deleted...");
                    return(false);
                }
            }
            else
            {
                LineHelpers.PrintLineWithContinue("Save was not deleted...");
                return(false);
            }
        }
示例#2
0
 // These are the save helpers they serialize an object and print it to a file
 // Upon load they read and unserialize the object and move it to a Model that will be used to init the character
 public static bool Save(Player player)
 {
     try
     {
         string jsonToSave = JsonConvert.SerializeObject(player);
         File.WriteAllText(LocalSavePath, jsonToSave);
         LineHelpers.PrintLineWithContinue("Game saved successfully... The game will now exit.");
         return(true);
     }
     catch (Exception ex)
     {
         LineHelpers.PrintLineWithContinue("Error Message: " + ex.ToString());
         LineHelpers.PrintLineWithContinue("\nFailed to save game please try again.");
         return(false);
     }
 }