예제 #1
0
        /// <summary>
        /// Load with a dialog and return a file with particular suffix.
        /// </summary>
        /// <returns></returns>
        public static ModuleManager loadDialog()
        {
            LoadFileForm loadFileForm = new LoadFileForm(PATH, SUFFIX);

            loadFileForm.TopMost = true;
            loadFileForm.ShowDialog();

            if (loadFileForm.load)
            {
                Console.WriteLine("File changed to " + loadFileForm.file);
                Properties.Settings.Default["modulemanager"] = loadFileForm.file;
            }

            return(FileSaver.load());
        }
예제 #2
0
        static void MainMenuChoice(int choice)
        {
            Runner runner = new Runner();

            switch (choice)
            {
            case 1:
                StartNewGameForm startNewGameForm = new StartNewGameForm(runner);
                Application.Run(startNewGameForm);
                PlayGameForm playGameForm = new PlayGameForm(startNewGameForm.ReturnRunner(), ("Nytt spel startat!" + Environment.NewLine));
                Application.Run(playGameForm);
                break;

            case 2:
                runner.CurrentPlayers.Clear();
                LoadFileForm loadFileForm = new LoadFileForm();
                loadFileForm.ShowDialog();

                if (loadFileForm.DidClose)
                {
                    MainMenuForm mainMenuForm = new MainMenuForm();
                    Application.Run(mainMenuForm);

                    MainMenuChoice(mainMenuForm.NextWindow);
                }

                var loadedGameData = loadFileForm.ReturnTextFile();

                TextFileSaver textFileSaver = new TextFileSaver();

                var savedNames  = new List <string>();
                var savedPoints = new List <int>();
                textFileSaver.ReturnPointsNames(loadedGameData, savedNames, savedPoints);

                for (int i = 0; i < savedNames.Count; i++)
                {
                    PlayerModel oldPlayer = new PlayerModel();
                    oldPlayer.PlayerName = savedNames[i];
                    runner.CurrentPlayers.Add(oldPlayer);
                    oldPlayer.AddTurn(savedPoints[i], 0, 0);
                }
                PlayGameForm playLoadedGameForm = new PlayGameForm(runner, $"Sparfil med namn { loadFileForm.ReturnFileName() } laddad!");
                Application.Run(playLoadedGameForm);
                return;
            }
        }