Ejemplo n.º 1
0
 public AttributeSet GetAttributes(int level)
 {
     return(new AttributeSet(
                _strengthFormula.Calculate(level),
                _dexterityFormula.Calculate(level),
                _resolveFormula.Calculate(level),
                _intelligenceFormula.Calculate(level),
                _magicFormula.Calculate(level)
                ));
 }
Ejemplo n.º 2
0
        public void Execute(int op1, IOperator opr, int op2)
        {
            //STEP 1: calculate
            //int result = Calculate(op1, opr, op2);
            int result = opr.Calculate(op1, op2);
            //Step 2: format
            string output = Formatter.FormatResult(op1, opr.GetType().Name, op2, result);

            //Step 3: calculate
            Presenter.Present(output);
        }
        public decimal Calculate(string operation)
        {
            //If we have a simple number, we return it
            decimal result;

            if (decimal.TryParse(operation, out result))
            {
                return(result);
            }

            //We execute operation for each operator type
            foreach (var operatorGroup in Operators)
            {
                char[] symbols = new char[operatorGroup.Count];

                //We build symbol list to do the split
                for (var i = 0; i < operatorGroup.Count; i++)
                {
                    symbols[i] = operatorGroup[i].Symbol;
                }

                //Find the first symbol, the one of the first operation in the string
                char?usedSymbol = GetFirstCharMatching(symbols, operation);
                if (usedSymbol == null)
                {
                    continue;
                }

                //Split the both members
                var splitted = operation.Split(symbols, 2);
                if (splitted.Length >= 2)
                {
                    //use recursion to calculate the both members value
                    decimal operand1 = Calculate(splitted[0]);
                    decimal operand2 = Calculate(splitted[1]);

                    IOperator _operator = operatorGroup.Find(x => x.Symbol == usedSymbol);
                    return(_operator.Calculate(operand1, operand2));
                }
            }

            throw new IncorrectExpressionException();
        }
Ejemplo n.º 4
0
 public int Calculate(int value)
 {
     return(Math.Max(_left.Calculate(value), _right.Calculate(value)));
 }
Ejemplo n.º 5
0
 private void Button_Result_Click(object sender, RoutedEventArgs e)
 {
     ourOperator           = FindOperator(TextBox_Entry.Text);
     TextBlock_Result.Text = ourOperator.Calculate().ToString();
 }
Ejemplo n.º 6
0
        private int Calculate(string operation, int firstNumber, int secondNumber)
        {
            IOperator calculationOperator = this.operators.FirstOrDefault(x => x.CommandName == operation);

            return(calculationOperator.Calculate(firstNumber, secondNumber));
        }
Ejemplo n.º 7
0
 public int Calculate(int value)
 {
     return(_left.Calculate(value) / _right.Calculate(value));
 }
Ejemplo n.º 8
0
 public int Calculate(int value)
 {
     return((int)Math.Pow(_left.Calculate(value), _right.Calculate(value)));
 }