Exemplo n.º 1
0
        public override Object Evaluate(ExpressionContext context)
        {
            OperandValue1 = Operand1.Evaluate(context);
            OperandValue2 = Operand2.Evaluate(context);

            return(OperandValue1 != OperandValue2);
        }
Exemplo n.º 2
0
        /// <summary>Resolves the two operands and then compares them using the user specified operator</summary>
        protected override double Execute(IGameState gameState)
        {
            var op1 = Operand1.Evaluate(gameState);
            var op2 = Operand2.Evaluate(gameState);

            switch (Operator)
            {
            case MathsOperator.Add: return(op1 + op2);

            case MathsOperator.Sub: return(op1 - op2);

            case MathsOperator.Mul: return(op1 * op2);

            case MathsOperator.Div when op2 != 0: return(op1 / op2);    // Return 0 if user tried to divide by zero.

            case MathsOperator.Mod when op2 != 0: return(op1 % op2);

            default: return(0);
            }
        }
Exemplo n.º 3
0
        /// <summary>Resolves the two operands and then compares them using the user specified operator</summary>
        public double Evaluate(IGameState gameState)
        {
            var op1 = Operand1.Evaluate(gameState);
            var op2 = Operand2.Evaluate(gameState);

            switch (Operator)
            {
            case MathsOperator.Add: return(op1 + op2);

            case MathsOperator.Sub: return(op1 - op2);

            case MathsOperator.Mul: return(op1 * op2);

            case MathsOperator.Div: return(op2 == 0 ? 0 : op1 / op2);    // Return 0 if user tried to divide by zero. Easier than having to deal with Infinity (which C# returns).

            case MathsOperator.Mod: return(op2 == 0 ? 0 : op1 % op2);

            default: return(0);
            }
        }
Exemplo n.º 4
0
        /// <summary>Resolves the two operands and then compares them with the user-specified operator.</summary>
        protected override bool Execute(IGameState gameState)
        {
            var op1 = Operand1.Evaluate(gameState);
            var op2 = Operand2.Evaluate(gameState);

            switch (Operator)
            {
            case ComparisonOperator.EQ: return(op1 == op2);

            case ComparisonOperator.NEQ: return(op1 != op2);

            case ComparisonOperator.GT: return(op1 > op2);

            case ComparisonOperator.GTE: return(op1 >= op2);

            case ComparisonOperator.LT: return(op1 < op2);

            case ComparisonOperator.LTE: return(op1 <= op2);

            default: return(false);
            }
        }
Exemplo n.º 5
0
        /// <summary>Compares the two strings with the given operator</summary>
        public bool Evaluate(IGameState gameState)
        {
            var op1 = Operand1.Evaluate(gameState);
            var op2 = Operand2.Evaluate(gameState);

            if (CaseInsensitive)
            {
                op1 = op1.ToLower();
                op2 = op2.ToLower();
            }

            switch (Operator)
            {
            case StringComparisonOperator.Equal: return(op1 == op2);

            case StringComparisonOperator.NotEqual: return(op1 != op2);

            case StringComparisonOperator.Before: return(string.Compare(op1, op2) < 0);

            case StringComparisonOperator.After: return(string.Compare(op1, op2) > 0);

            case StringComparisonOperator.EqualLength: return(op1.Length == op2.Length);

            case StringComparisonOperator.ShorterThan: return(op1.Length < op2.Length);

            case StringComparisonOperator.LongerThan: return(op1.Length > op2.Length);

            case StringComparisonOperator.StartsWith: return(op1.StartsWith(op2));

            case StringComparisonOperator.EndsWith: return(op1.EndsWith(op2));

            case StringComparisonOperator.Contains: return(op1.Contains(op2));

            default: return(false);
            }
        }