public static void Auto_Load_Game()
 {
     try
     {
         string        FolderName = Path.Combine(Directory.GetCurrentDirectory(), "Saves");
         List <string> filesnames = Directory.GetFiles(FolderName).ToList();
         var           start      = new DateTime(1970, 1, 1, 0, 0, 0);
         var           fileToLoad = "";
         foreach (var filename in filesnames)
         {
             if (File.GetCreationTime(filename) > start)
             {
                 fileToLoad = filename;
                 start      = File.GetCreationTime(filename);
             }
         }
         if (String.IsNullOrEmpty(fileToLoad))
         {
             throw new Exception();
         }
         StreamReader saveGetting = new StreamReader(fileToLoad);
         using (saveGetting)
         {
             var loadedSave = JsonConvert.DeserializeObject <Save>(saveGetting.ReadToEnd(), new JsonSerializerSettings()
             {
                 TypeNameHandling = TypeNameHandling.Auto
             });
             switch (loadedSave.savedStage)
             {
             case 0:
             case 1:
                 new Tutorial(loadedSave.savedCharacter);
                 break;
             }
         }
     }
     catch
     {
         Console.WriteLine("There are no saves in the directory");
         MainFunctions.MainMenu();
     }
 }
예제 #2
0
        public static Character Start_Game()
        {
            using (StreamReader intro = new StreamReader(Path.Combine(Directory.GetCurrentDirectory(), "Resources", "intro.txt")))
            {
                Console.WriteLine(intro.ReadToEnd());
            }
            Character newCharacter = new Character();

            newCharacter.preGiving();
            Console.WriteLine($"Congratulations! You've chosen your name. Now you are called {newCharacter.name}.");
            Console.WriteLine($"\nYour health is {newCharacter.health}, and your stamina is {newCharacter.stamina}.\n");
            using (StreamReader stats = new StreamReader(Path.Combine(Directory.GetCurrentDirectory(), "Resources", "statsDialogue.txt")))
            {
                Console.WriteLine(stats.ReadToEnd());
            }
            int decision = ServiceFunctions.ChoosingRightKey(Console.ReadKey().KeyChar);

            while ((decision < 0) || decision > 1)
            {
                Console.WriteLine("Please press appropriate key");
                decision = ServiceFunctions.ChoosingRightKey(Console.ReadKey().KeyChar);
            }
            if (decision > 0)
            {
                newCharacter.ChooseStats();
                Console.WriteLine($"\nYour character may develop a certain set of skills during the game. The first one is Archaeopteryx:\n");
                newCharacter.CreditArchaeopteryx(new Archaeopteryx());
            }
            else
            {
                MainFunctions.Exit_Game();
            }
            newCharacter.SetGender(0);
            Console.WriteLine($"{newCharacter.name} is preparing to become a parent. Their first target is to watch for their not yet born children. Or... is it?\n");
            return(newCharacter);
        }
        public static void Load_Game()
        {
            List <string> filesnames = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "Saves")).ToList();

            if (filesnames.Count > 0)
            {
                foreach (string name in filesnames)
                {
                    StreamReader SaveGetting = new StreamReader(name);
                    using (SaveGetting)
                    {
                        var shortFileName = Regex.Match(name, @"[0-9]{1,}.dns");
                        shortFileName = Regex.Match(name, @"[0-9]{1,}");
                        var loadedSave = JsonConvert.DeserializeObject <Save>(SaveGetting.ReadToEnd(), new JsonSerializerSettings()
                        {
                            TypeNameHandling = TypeNameHandling.Auto
                        });
                        Console.WriteLine("Number: {0}", shortFileName);
                        Console.WriteLine("Stage: {0}", loadedSave.savedStage);
                        Console.WriteLine("Character: {0}", loadedSave.savedCharacter.name);
                        Console.WriteLine();
                        Console.WriteLine();
                    }
                }
                Console.WriteLine("Write the number of save you want to load");
                string ReadableSave = Console.ReadLine();
                if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Saves", ReadableSave + ".dns")))
                {
                    StreamReader SaveGetting = new StreamReader(Path.Combine(Directory.GetCurrentDirectory(), "Saves", ReadableSave + ".dns"));
                    using (SaveGetting)
                    {
                        var loadedSave = JsonConvert.DeserializeObject <Save>(SaveGetting.ReadToEnd(), new JsonSerializerSettings()
                        {
                            TypeNameHandling = TypeNameHandling.Auto
                        });
                        switch (loadedSave.savedStage)
                        {
                        case 0:
                        case 1:
                            new Tutorial(loadedSave.savedCharacter);
                            break;
                        }
                    }
                }
                else
                {
                    while (!(File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Saves", ReadableSave + ".dns"))))
                    {
                        Console.WriteLine("Wrong file name. Insert once more");
                        ReadableSave = Console.ReadLine();
                    }
                    StreamReader SaveGetting = new StreamReader(Path.Combine(Directory.GetCurrentDirectory(), "Saves", ReadableSave + ".dns"));
                    using (SaveGetting)
                    {
                        var loadedSave = JsonConvert.DeserializeObject <Save>(SaveGetting.ReadToEnd(), new JsonSerializerSettings()
                        {
                            TypeNameHandling = TypeNameHandling.Auto
                        });
                        switch (loadedSave.savedStage)
                        {
                        case 0:
                        case 1:
                            new Tutorial(loadedSave.savedCharacter);
                            break;
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("There are no saves in the directory");
                MainFunctions.MainMenu();
            }
        }