示例#1
0
        private void Reset()
        {
            onConsoleOutput = "0";
            lastKey         = LastKey.Digit;
            operandSwitch   = OperandSwitch.OperandA;

            lastKeyValue = '0';
            lastOperator = '#';
        }
    float Movement(float startTime, float stopTime)
    {
        float move = movement;

        float h     = Input.GetAxis("Horizontal");
        float left  = Input.GetAxisRaw("Left");
        float right = Input.GetAxisRaw("Right");

        float posMove = Mathf.Lerp(move, 1, startTime / 100);        // движение вправо
        float negMove = Mathf.Lerp(move, -1, startTime / 100);       // движение влево
        float endMove = Mathf.Lerp(move, 0, stopTime / 100);         // остановка


        if (left != 0 && right == 0)
        {
            lastKey  = LastKey.Left;
            movement = negMove;
        }
        else if (left == 0 && right != 0)
        {
            lastKey  = LastKey.Right;
            movement = posMove;
        }

        if (lastKey == LastKey.Left && right != 0)
        {
            movement = posMove;
        }
        else if (lastKey == LastKey.Right && left != 0)
        {
            movement = negMove;
        }


        if (h == 0)
        {
            isMove = false;

            if (movement <= 0.1f && movement >= -0.1f)
            {
                movement = 0;
            }
            else
            {
                movement = endMove;
            }
        }
        else
        {
            isMove = true;
        }
        return(movement);
    }
        public void Update(GameTime gameTime)
        {
            LastKey = Current;
            Current = Keyboard.GetState();

            if ((LastKey.GetPressedKeys().Length == 0) && (Current.GetPressedKeys().Length > 0))
            {
                KeyClicked = true;
            }
            else
            {
                KeyClicked = false;
            }
        }
示例#4
0
        public string SendKeyPress(char key)
        {
            switch (key)
            {
            case var tempKey when(tempKey >= '0' && tempKey <= '9'):
                if (operandSwitch == OperandSwitch.OperandA)
                {
                    if (lastKey == LastKey.Digit)
                    {
                        if (onConsoleOutput == "0")
                        {
                            onConsoleOutput = key.ToString();
                        }
                        else
                        {
                            onConsoleOutput = onConsoleOutput + key.ToString();
                        }
                        operandA = onConsoleOutput;
                    }
                }

                else if (operandSwitch == OperandSwitch.OperandB)
                {
                    if (lastKey == LastKey.Operator)
                    {
                        onConsoleOutput = key.ToString();
                    }

                    else if (lastKey == LastKey.Digit)
                    {
                        if (onConsoleOutput == "0")
                        {
                            onConsoleOutput = key.ToString();
                        }
                        else
                        {
                            onConsoleOutput = onConsoleOutput + key.ToString();
                        }
                    }
                    operandB = onConsoleOutput;
                }
                lastKeyValue = key;
                lastKey      = LastKey.Digit;
                break;

            case var tempKey when(tempKey == '+' || tempKey == '-' || tempKey == '/' || tempKey.ToString().ToLower() == "x"):
                if (operandSwitch == OperandSwitch.OperandA)
                {
                    operandSwitch = OperandSwitch.OperandB;
                    lastKey       = LastKey.Operator;
                    lastOperator  = tempKey;
                    return(onConsoleOutput);
                }

                Result();

                lastOperator = tempKey;
                lastKey      = LastKey.Operator;
                operandA     = onConsoleOutput;

                if (operandSwitch == OperandSwitch.OperandA)
                {
                    operandSwitch = OperandSwitch.OperandB;
                }

                break;

            case var tempKey when(tempKey.ToString().ToLower() == "s"):
                Toggle();

                break;

            case var tempKey when(tempKey.ToString().ToLower() == "c"):
                Reset();

                break;

            case var tempKey when(tempKey == '='):
                Result();

                break;

            case var tempKey when(tempKey == '.'):
                HandleDecimals();

                break;
            }
            return(onConsoleOutput);
        }
 public bool IsClicked(Keys Key)
 {
     return((LastKey.IsKeyDown(Key) ^ Current.IsKeyDown(Key)) && Current.IsKeyDown(Key));
 }