Пример #1
0
        protected override void KeyboardInput(InputEventArgs <TKey> args)
        {
            var moved = false;

            if (KeyboardAdapter.IsUp(args.Input))
            {
                moved = Level.TryMoveUp();
            }
            else if (KeyboardAdapter.IsLeft(args.Input))
            {
                moved = Level.TryMoveLeft();
            }
            else if (KeyboardAdapter.IsDown(args.Input))
            {
                moved = Level.TryMoveDown();
            }
            else if (KeyboardAdapter.IsRight(args.Input))
            {
                moved = Level.TryMoveRight();
            }

            if (moved && Level.IsCompleted)
            {
                OnLevelCompleted?.Invoke(this);
            }
        }
Пример #2
0
        protected override void KeyboardInput(InputEventArgs <TInput> args)
        {
            var key = args.Input;

            if (KeyboardAdapter.IsUp(key))
            {
                _unselectedItemIndex = _selectedItemIndex;
                _selectedItemIndex--;
                if (_selectedItemIndex < 0)
                {
                    _selectedItemIndex = _items.Count - 1;
                }
                OnSelectionChanged?.Invoke(this, _items[_unselectedItemIndex.Value], _items[_selectedItemIndex]);
            }
            else if (KeyboardAdapter.IsDown(key))
            {
                _unselectedItemIndex = _selectedItemIndex;
                _selectedItemIndex++;
                if (_selectedItemIndex >= _items.Count)
                {
                    _selectedItemIndex = 0;
                }
                OnSelectionChanged?.Invoke(this, _items[_unselectedItemIndex.Value], _items[_selectedItemIndex]);
            }
            else if (KeyboardAdapter.IsEnter(key))
            {
                OnSelect?.Invoke(this, _items[_selectedItemIndex]);
            }
        }