Exemplo n.º 1
0
 private void SetAbilities(DieRollResults results)
 {
     AbilityScores.Add(Ability.Strength, results[0]);
     AbilityScores.Add(Ability.Intelligence, results[1]);
     AbilityScores.Add(Ability.Wisdom, results[2]);
     AbilityScores.Add(Ability.Dexterity, results[3]);
     AbilityScores.Add(Ability.Constitution, results[4]);
     AbilityScores.Add(Ability.Charisma, results[5]);
 }
Exemplo n.º 2
0
        protected void ButtonRoll_Click(object sender, EventArgs e)
        {
            DieRoll dr = DieRoll.FromString(TextDieRoll.Text);

            int rollCount;

            try
            {
                rollCount = Convert.ToInt32(TextRollCount.Text);
            }
            catch (Exception ex)
            {
                rollCount = 1;
            }

            if (rollCount > 0)
            {
                DieRollResults results = Roll(dr, rollCount);

                StringBuilder sb = new StringBuilder();
                sb.Append("Minimum, Maximum, Average for ");
                sb.Append(dr.ToString());
                sb.Append(": ");
                sb.Append(dr.Minimum.ToString());
                sb.Append(", ");
                sb.Append(dr.Maximum.ToString());
                sb.Append(", ");
                sb.Append(dr.Average.ToString());
                sb.Append("<br />Roll results: ");
                sb.Append(results.ToString());
                sb.Append("<br />Sorted: ");
                sb.Append(results.Sorted().ToString());
                sb.Append("<br />Reversed: ");
                sb.Append(results.Sorted(DieRollResults.SortOrder.Descending).ToString());
                sb.Append("<br />Lowest, Highest, Average rolled: ");
                sb.Append(results.Lowest.ToString());
                sb.Append(", ");
                sb.Append(results.Highest.ToString());
                sb.Append(", ");
                sb.Append(results.Average.ToString());

                if (rollCount > 3)
                {
                    results.KeepBest(3);
                    sb.Append("<br />Top 3 rolls: ");
                    sb.Append(results.ToString());
                    sb.Append(", total ");
                    sb.Append(results.Total.ToString());
                }
                LabelResult.Text = sb.ToString();
            }
            else
            {
                LabelResult.Text = "Number of Rolls must be a positive integer.";
            }
        }
Exemplo n.º 3
0
        private DieRollResults Roll(DieRoll dr, int count)
        {
            DieRollResults rolls = new DieRollResults();

            for (int i = 1; i <= count; i++)
            {
                rolls.Add(dr.Roll());
            }
            return(rolls);
        }
Exemplo n.º 4
0
        public void RollAbilities()
        {
            DieRoll dr;

            if (Method == RollingMethod.Simple)
            {
                // Simply roll 3d6 for each attribute and take what you get
                dr = new DieRoll(3, 6, 0);
                DieRollResults results = dr.MultiRoll(6);
                SetAbilities(results);
            }
            else if (Method == RollingMethod.Method1)
            {
                // Roll 4d6 for each ability and keep the top 3 dice
                dr      = new DieRoll(4, 6, 0);
                dr.Keep = 3;
                AbilityScores.Add(Ability.Strength, dr.Roll());
                AbilityScores.Add(Ability.Intelligence, dr.Roll());
                AbilityScores.Add(Ability.Wisdom, dr.Roll());
                AbilityScores.Add(Ability.Dexterity, dr.Roll());
                AbilityScores.Add(Ability.Constitution, dr.Roll());
                AbilityScores.Add(Ability.Charisma, dr.Roll());
            }
            else if (Method == RollingMethod.Method2)
            {
                // Roll 3d6 12 times and keep the best 6 results
                dr = new DieRoll(3, 6, 0);
                DieRollResults results = dr.MultiRoll(12, 6);
                results.KeepBest(6);
                SetAbilities(results);
            }
            else if (Method == RollingMethod.Method3)
            {
                // For each ability roll 3d6 6 times and keep the best result
                dr = new DieRoll(3, 6, 0);
                DieRollResults results = new DieRollResults();
                for (int i = 0; i < 6; i++)
                {
                    // when called with params Roll returns a RollResult;
                    // add the first and only member of this RollResult, an int,  to the results list
                    results.Add(dr.MultiRoll(6, 1)[0]);
                }
                SetAbilities(results);
            }
        }