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();
            }
        }
 public PlayGameForm(Runner runner, string startMessage)
 {
     InitializeComponent();
     this.runner = runner;
     FetchPlayers();
     ShowActionsTextBox.AppendText(startMessage);
 }
        private void SaveGameBtnTwo_Click(object sender, EventArgs e)
        {
            SaveFileForm saveFileForm = new SaveFileForm();

            saveFileForm.ShowDialog();
            string        chosenName    = saveFileForm.ReturnFileName();
            TextFileSaver textFileSaver = new TextFileSaver();

            textFileSaver.PrepareOverwriteSave(chosenName);
            foreach (var player in runner.CurrentPlayers)
            {
                textFileSaver.SaveTextFile(chosenName, player.PlayerName, player.PlayerPoints);
            }
            if (saveFileForm.SavedOver)
            {
                ShowActionsTextBox.AppendText($"Sparade över fil med namn { chosenName }!");
            }
            else
            {
                ShowActionsTextBox.AppendText($"Ny sparfil med namn { chosenName } skapad!");
            }
        }
        public void PlayRound()
        {
            Points points = new Points();

            int[] roundThrows  = new int[3];
            int   playerPoints = 0;
            int   throwValue   = 0;

            foreach (var player in runner.CurrentPlayers)
            {
                FetchPlayers();
                playerPoints              = player.CalculatePoints();
                RoundTextBox.Text         = player.PlayerRounds.ToString();
                CurrentPlayerTextBox.Text = player.PlayerName;
                PlayerPointsTextBox.Text  = player.CalculatePoints().ToString();
                if (player.PlayerName.Contains("Dator"))
                {
                    for (int i = 0; i < roundThrows.Length; i++)
                    {
                        throwValue     = points.RandomThrow();
                        roundThrows[i] = throwValue;
                        playerPoints  += throwValue;
                        ShowActionsTextBox.AppendText($"Kast: { (i + 1) }/3 { player.PlayerName } kastade och träffade { throwValue }" +
                                                      (Environment.NewLine));
                        WaitCondition(player.PlayerName, throwValue, (i + 1));
                        int showValue = player.CalculatePoints() + throwValue;
                        PlayerPointsTextBox.Text = (showValue.ToString());
                    }
                    if (playerPoints < 301)
                    {
                        player.AddTurn(roundThrows[0], roundThrows[1], roundThrows[2]);
                        ShowActionsTextBox.AppendText($"Runda { player.PlayerRounds }, { player.PlayerName } fick { (roundThrows[0] + roundThrows[1] + roundThrows[2]) } poäng" +
                                                      (Environment.NewLine) + (Environment.NewLine));
                    }
                    else if (playerPoints > 301)
                    {
                        ShowActionsTextBox.AppendText($"Runda { player.PlayerRounds }, { player.PlayerName } kom över 301 poäng och rundan blev nullifierad" +
                                                      (Environment.NewLine) + (Environment.NewLine));
                    }
                    player.PlayerRounds++;
                    PlayerPointsTextBox.Text = player.CalculatePoints().ToString();
                    FetchPlayers();
                }
                else
                {
                    for (int i = 0; i < roundThrows.Length; i++)
                    {
                        RoundTextBox.Text         = player.PlayerRounds.ToString();
                        CurrentPlayerTextBox.Text = player.PlayerName;
                        PlayerPointsTextBox.Text  = player.CalculatePoints().ToString();
                        int humanChoice = HumanChoice();
                        throwValue     = points.AimedThrow(humanChoice);
                        roundThrows[i] = throwValue;
                        playerPoints  += throwValue;
                        int showValue = player.CalculatePoints() + throwValue;
                        PlayerPointsTextBox.Text = (showValue.ToString());
                        ShowActionsTextBox.AppendText($"Kast: { (i + 1) }/3 { player.PlayerName } kastade och träffade { throwValue }" +
                                                      (Environment.NewLine));
                    }
                    if (playerPoints < 301)
                    {
                        player.AddTurn(roundThrows[0], roundThrows[1], roundThrows[2]);
                        ShowActionsTextBox.AppendText($"Runda { player.PlayerRounds }, { player.PlayerName } fick { (roundThrows[0] + roundThrows[1] + roundThrows[2]) } poäng" +
                                                      (Environment.NewLine) + (Environment.NewLine));
                    }
                    else if (playerPoints > 301)
                    {
                        ShowActionsTextBox.AppendText($"Runda { player.PlayerRounds }, { player.PlayerName } kom över 301 poäng och rundan blev nullifierad" +
                                                      (Environment.NewLine) + (Environment.NewLine));
                    }
                    player.PlayerRounds++;
                    PlayerPointsTextBox.Text = player.CalculatePoints().ToString();
                    FetchPlayers();
                }
                FetchPlayers();
            }
        }