Example #1
0
        private void ExecutedRollCommand(object sender, ExecutedRoutedEventArgs e)
        {
            TextBlock target = e.Source as TextBlock;

            if (target == null)
            {
                return;
            }

            DiceExpressionParserDetailed diceParser = new DiceExpressionParserDetailed(new StandardDiceRoller());

            IComponent diceExpression = new Constant(0);

            try
            {
                diceExpression = diceParser.ParseString(e.Parameter as string);
            }
            catch (ParseException)
            {
                MessageBox.Show("Could not parse the expression, please check your expression and try again", "Expression failure", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            target.Text = $"Rolled {diceExpression.ToString()} for a result of {diceExpression.Calculate()}";
        }
Example #2
0
        public void TestConstant()
        {
            IExpression e = new Constant(1.0);

            Assert.AreEqual(1, e.Calculate());
        }