Пример #1
0
        public void LoadFile()
        {
            bool   filechosen = false;
            string gamefilename;
            int    strlen;

            while (!filechosen)
            {
                Console.Write("\nGame File Name?");

                gamefilename  = Console.ReadLine();
                gamefilename += ".game";
                if (Utility.NotBlank(gamefilename))
                {
                    if (File.Exists(gamefilename))
                    {
                        try
                        {
                            game       = saver.LoadGameData(game, gamefilename);
                            filename   = gamefilename;
                            filechosen = true;
                        }
                        catch
                        {
                            Console.Write("\nNot a valid game file!");
                        }
                    }
                    else
                    {
                        Console.Write("\nFile does not exist.  Create new file?");
                        choice = Console.ReadLine();
                        strlen = choice.Length;


                        if (Utility.WordMatch(choice, "yes", false))
                        {
                            filename      = gamefilename;
                            game.filename = gamefilename;
                            saver.SaveGameData(game, filename);
                            Console.WriteLine("New rooms file " + gamefilename + " created\n");
                            filechosen = true;
                        }
                        else
                        {
                            Console.WriteLine("File not created.");
                        }
                    }
                }
            }
        }
Пример #2
0
        public bool LoadRoomFile()
        {
            bool      success  = false;
            bool      finished = false;
            bool      picked   = false;
            string    gamefilename;
            SaveMaker saver = new SaveMaker();

            while (!finished)
            {
                Console.Write("\nWhat Game File?");

                gamefilename = Console.ReadLine();
                if (Utility.NotBlank(gamefilename))
                {
                    gamefilename += ".game";
                    if (File.Exists(gamefilename))
                    {
                        game = saver.LoadGameData(game, gamefilename);
                        Console.Write("\nGame file loaded!\n");
                        success  = true;
                        finished = true;
                    }
                    else
                    {
                        while (!picked)
                        {
                            Console.Write("\nFile does not exist.  Try again?");
                            choice = Console.ReadLine();
                            if (Utility.WordMatch(choice, "yes", picked))
                            {
                                picked   = true;
                                success  = false;
                                finished = false;
                            }
                            if (Utility.WordMatch(choice, "no", picked))
                            {
                                picked   = true;
                                success  = false;
                                finished = true;
                            }
                        }
                    }
                }
                else
                {
                    while (!picked)
                    {
                        Console.Write("\nNo name entered.  Try again?");
                        choice = Console.ReadLine();
                        if (Utility.WordMatch(choice, "yes", picked))
                        {
                            picked   = true;
                            success  = false;
                            finished = false;
                        }
                        if (Utility.WordMatch(choice, "no", picked))
                        {
                            picked   = true;
                            success  = false;
                            finished = true;
                        }
                    }
                }
            }
            return(success);
        }