Пример #1
0
        private void btnRoll_Click(object sender, EventArgs e)
        {
            string diceExpression = cmbDiceExpression.Text;
            int    nRolls         = Convert.ToInt32(numRolls.Value);

            StringBuilder sb = new StringBuilder();

            if (this.chkAnalysis.Checked)
            {
                //Roll dice in Analysis mode
                string lineFormat = "{0,5}:\t{1,8}\t{2,3}";
                Dictionary <int, int> ValueCounts = new Dictionary <int, int>();

                for (int i = 0; i < nRolls; i++)
                {
                    int result = Dice.Roll(diceExpression);
                    if (ValueCounts.ContainsKey(result))
                    {
                        ValueCounts[result] += 1;
                    }
                    else
                    {
                        ValueCounts.Add(result, 1);
                    }
                }

                sb.AppendLine("Analysis of " + nRolls + " rolls of \"" + diceExpression + "\":");

                List <int> keys = ValueCounts.Keys.ToList();
                keys.Sort();

                foreach (int key in keys)
                {
                    int    count      = ValueCounts[key];
                    string percentage = ((decimal)count / nRolls).ToString("p");
                    sb.AppendLine(string.Format(lineFormat, key, count, percentage));
                }

                txtResults.Text = sb.ToString();
            }
            else
            {
                //Roll dice normally


                for (int i = 0; i < nRolls; i++)
                {
                    ExpandedDiceRoll result = Dice.RollExpanded(diceExpression);
                    sb.AppendLine(string.Format(lineFormat, i + 1, diceExpression, result.FullResult, result.Accounting));
                }

                txtResults.Text = sb.ToString();
            }
        }
Пример #2
0
        private void btnRollOneOfEach_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();

            this.txtResults.Clear();
            int i = 0;

            foreach (object obj in this.cmbDiceExpression.Items)
            {
                i++;
                string           expr   = (string)obj;
                ExpandedDiceRoll result = Dice.RollExpanded(expr);
                sb.AppendLine(string.Format(lineFormat, i, expr, result.FullResult, result.Accounting));
            }
            txtResults.Text = sb.ToString();
        }