Beispiel #1
0
 public static void NoSaveFilesFound()
 {
     Console.WriteLine("No save files found. Starting new game...");
     CMethods.SmartSleep(100);
     CMethods.PrintDivider();
     UnitManager.CreatePlayer();
 }
Beispiel #2
0
        public static void LoadTheGame()
        {
            // File.Exists(path);
            Console.WriteLine("Searching for existing save files...");
            CMethods.SmartSleep(100);

            if (!Directory.Exists(base_dir))
            {
                NoSaveFilesFound();
                return;
            }

            Dictionary <string, List <string> > save_files = new Dictionary <string, List <string> >();
            List <string> save_file_components             = new List <string>()
            {
                sav_gems,
                sav_equipment,
                sav_inventory,
                sav_boss_flags,
                sav_game_info,
                sav_dialogue_flags,
                sav_chests,
                sav_player,
                sav_solou,
                sav_chili,
                sav_chyme,
                sav_parsto,
                sav_adorine,
                sav_storm,
                sav_kaltoh
            };

            foreach (string path in Directory.GetDirectories(base_dir))
            {
                if (save_file_components.All(x => File.Exists($"{path}/{x}")))
                {
                    // ...then set the dictionary key equal to the newly-formatted save file names
                    string folder_name = path.Split('\\').Last();
                    save_files[folder_name] = save_file_components.Select(x => $"{base_dir}/{folder_name}/{x}").ToList();
                }
            }

            if (save_files.Count == 0)
            {
                NoSaveFilesFound();
                return;
            }

            CMethods.PrintDivider();
            Console.WriteLine($"Found {save_files.Count} existing save files: ");

            // Print the list of save files
            int counter = 0;

            foreach (string folder in save_files.Keys)
            {
                Console.WriteLine($"      [{counter + 1}] {folder}");
                counter++;
            }

            while (true)
            {
                string chosen = CMethods.FlexibleInput("Input [#] (or type [c]reate new): ", save_files.Count);

                try
                {
                    adventure_name = save_files.Keys.ToList()[int.Parse(chosen) - 1];
                }

                catch (Exception ex) when(ex is FormatException || ex is ArgumentOutOfRangeException)
                {
                    // Let the player create a new save file
                    if (chosen.StartsWith("c"))
                    {
                        CMethods.PrintDivider();
                        UnitManager.CreatePlayer();
                        return;
                    }

                    continue;
                }

                CMethods.PrintDivider();
                Console.WriteLine($"Loading Save File: '{adventure_name}'...");
                CMethods.SmartSleep(100);
                JSONDeserializer.DeserializeEverything();
                Console.WriteLine("Game loaded!");

                return;
            }
        }