コード例 #1
0
        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();
            }
        }