public void OperandsGetTruncated()
        {
            var leftExpression  = new ConstantExpression(2.9);
            var rightExpression = new ConstantExpression(6.9);

            var expression = new DiceExpression(leftExpression, rightExpression, dice);

            Assert.That(expression.Evaluate(), Is.GreaterThanOrEqualTo(2));
            Assert.That(expression.Evaluate(), Is.LessThanOrEqualTo(12));
        }
        public void SixSidedDice()
        {
            var leftExpression  = new ConstantExpression(2);
            var rightExpression = new ConstantExpression(6);

            var expression = new DiceExpression(leftExpression, rightExpression, dice);

            Assert.That(expression.Evaluate(), Is.GreaterThanOrEqualTo(2));
            Assert.That(expression.Evaluate(), Is.LessThanOrEqualTo(12));
        }
        public void OneSidedDie()
        {
            var leftExpression  = new ConstantExpression(1);
            var rightExpression = new ConstantExpression(1);

            var expression = new DiceExpression(leftExpression, rightExpression, dice);

            Assert.AreEqual(1, expression.Evaluate());
        }
Exemplo n.º 4
0
        private void RollDamageBtn_Click(object sender, EventArgs e)
        {
            DiceExpression exp = DiceExpression.Parse(DamageExpLbl.Text);

            if (exp != null)
            {
                int roll = exp.Evaluate();
                DamageBox.Value = roll;
            }
        }
Exemplo n.º 5
0
        private void RollDamageBtn_Click(object sender, EventArgs e)
        {
            DiceExpression diceExpression = DiceExpression.Parse(this.DamageExpLbl.Text);

            if (diceExpression != null)
            {
                int num = diceExpression.Evaluate();
                this.DamageBox.Value = num;
            }
        }
Exemplo n.º 6
0
        public Task <BaseResult> Command_DiceRollAsync(
            [Name("Dice")][Description("The dice configuration to use. It can be simple, like `6`, or complex, like `d20+d18+4`.")]
            string dice      = "6", [Name("Number of Dice")][Description("The number of dice to roll.")]
            int numberOfDice = 1)
        {
            if (numberOfDice < 1)
            {
                return(BadRequest("You must ask me to roll at least one die!"));
            }

            if (numberOfDice > 100)
            {
                return(BadRequest("Sorry! No more than 100 dice rolls at once, please!"));
            }

            if (!dice.Contains("d" /* No dice */) && int.TryParse(dice, out var diceParsed))
            {
                if (diceParsed < 1)
                {
                    return(BadRequest("Your dice roll must be 1 or above!"));
                }

                if (numberOfDice == 1)
                {
                    return(Ok($"I rolled **{Random.Next(1, diceParsed)}** on a **{dice}**-sided die."));
                }

                return(Ok(string.Join("\n", Enumerable.Range(1, numberOfDice).Select(a => $"- **Die {a}:** {Random.Next(1, diceParsed)}"))));
            }

            try
            {
                return(Ok(string.Join("\n", Enumerable.Range(1, numberOfDice)
                                      .Select(a => $"- **Die {a}:** {DiceExpression.Evaluate(dice)}"))));
            }
            catch (ArgumentException)
            {
                return(BadRequest("Invalid dice!"));
            }
        }