public void LoadGame()
        {
            runner.CurrentPlayers.Clear();
            LoadFileForm loadFileForm = new LoadFileForm();

            loadFileForm.ShowDialog();

            if (loadFileForm.DidClose)
            {
                ShowActionsTextBox.AppendText(Environment.NewLine + $"Åtgärden avbruten, ingen spelfil laddad!");
            }
            else
            {
                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);
                }
                ShowActionsTextBox.AppendText(Environment.NewLine + $"Sparfil med namn { loadFileForm.ReturnFileName() } laddad!");
                FetchPlayers();
            }
        }
Beispiel #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;
            }
        }