예제 #1
0
 public InputDispatcher()
 {
     _keyboard  = new KeyboardAdapter();
     _mouse     = new MouseAdapter();
     _joysticks = new JoystickAdapter();
     _touch     = new TouchAdapter();
 }
예제 #2
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);
            }
        }
예제 #3
0
        private Control <TGlyph, TColor, TKey> CreateLoadMenu()
        {
            var menu  = Menu();
            var items = new List <object>(10);

            for (var i = 0; i < items.Capacity; i++)
            {
                items.Add(menu.AddItem(_glyphProvider.FromString($"Slot {i}")));
            }
            menu.OnSelect += (m, item) =>
            {
                var index = items.IndexOf(item);
                if (File.Exists($"save{index}.sav"))
                {
                    _levelControl.Level = Level.Load($"save{index}.sav");
                    Page = NewGamePage;
                }
            };
            menu.OnKeyboardInput += (control, args) =>
            {
                if (KeyboardAdapter.IsEscape(args.Input))
                {
                    Page = _previousPage;
                }
            };

            return(Panel(Boder(20, 12, "Load menu", menu)));
        }
예제 #4
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]);
            }
        }
예제 #5
0
파일: Editor.cs 프로젝트: vorov2/slot
 public void RunCommand(KeyInput input)
 {
     if (KeyboardAdapter.ProcessInput(input) == InputState.Complete)
     {
         if (!RunCommand(KeyboardAdapter.LastKey))
         {
             OnCommandRejected();
         }
     }
 }
        public void OnKeyDown_APage_EventSentThrough()
        {
            var adapter = new KeyboardAdapter();
            var page    = Substitute.For <IScenePage>();

            adapter.AssignSubscriber(page);
            var args = new KeyDownEventArguments(Key.Up, 0, false, 0, 0);

            adapter.OnKeyDown(null, args);

            page.Received().OnKeyDown(null, args);
        }
예제 #7
0
 protected override void KeyboardInput(InputEventArgs <TInput> args)
 {
     if (KeyboardAdapter.IsTab(args.Input))
     {
         var index = Controls.IndexOf(Focused) + 1;
         Focused           = Controls[index % Controls.Count];
         Focused.IsFocused = true;
     }
     else
     {
         Focused.NotifyKeyboardInput(args.Input);
     }
 }
        public void OnKeyDown_PageDeactivated_PageDoesntReceiveCall()
        {
            var adapter = new KeyboardAdapter();
            var page1   = Substitute.For <IScenePage>();

            adapter.AssignSubscriber(page1);
            adapter.ReleaseSubscriber(page1);

            var args = new KeyDownEventArguments(Key.Up, 0, false, 0, 0);

            adapter.OnKeyDown(null, args);

            page1.Received(0).OnKeyDown(null, args);
        }
        public void OnKeyDown_PageDeactivated_KeyCancelMessageReceived()
        {
            var adapter = new KeyboardAdapter();
            var page1   = Substitute.For <IScenePage>();

            adapter.AssignSubscriber(page1);
            var args = new KeyDownEventArguments(Key.Up, 0, false, 0, 0);

            adapter.OnKeyDown(null, args);

            adapter.ReleaseSubscriber(page1);

            page1.Received(1).OnKeyCancel(adapter, Arg.Any <KeyCancelEventArguments>());
        }
        public void OnKeyDown_PageChanged_CorrectPageReceivesCall()
        {
            var adapter = new KeyboardAdapter();
            var page1   = Substitute.For <IScenePage>();
            var page2   = Substitute.For <IScenePage>();

            adapter.AssignSubscriber(page1);
            adapter.ReleaseSubscriber(page1);

            adapter.AssignSubscriber(page2);
            var args = new KeyDownEventArguments(Key.Up, 0, false, 0, 0);

            adapter.OnKeyDown(null, args);

            page1.Received(0).OnKeyDown(null, args);
            page2.Received(1).OnKeyDown(null, args);
        }
예제 #11
0
 private Control <TGlyph, TColor, TKey> CreateGame()
 {
     _levelControl = new LevelControl <TGlyph, TColor, TKey>(_glyphProvider, _colorProvider)
     {
         Left = 1,
         Top  = 1
     };
     _levelControl.OnKeyboardInput += (s, e) =>
     {
         if (_levelControl.Level.IsCompleted)
         {
             e.Handled = true;
             var index = _levelControl.Level.Index + 1;
             if (_levelProvider.Count == index)
             {
                 Page = MainMenuPage;
             }
             else
             {
                 StartLevel(index);
             }
         }
         else if (KeyboardAdapter.IsEscape(e.Input))
         {
             e.Handled = true;
             Page      = LocalMenuPage;
         }
         else if (KeyboardAdapter.IsBackspace(e.Input))
         {
             e.Handled = true;
             _levelControl.Level.Undo();
         }
     };
     _levelControl.OnLevelCompleted += s =>
     {
         _levelCompleteMessageLabel.Text = _glyphProvider.FromString("Congratulations, you have completed the Level!");
     };
     _levelCompleteMessageLabel = new Label <TGlyph, TColor, TKey>
     {
         ColorTheme = _colorProvider.SokobanLabelColorTheme,
         Delimiter  = _glyphProvider.Delimiter,
         Height     = 1,
         Width      = 46
     };
     return(Panel(_levelControl, _levelCompleteMessageLabel));
 }
        public void OnKeyDown_NoPage_DoesNotThrow()
        {
            var adapter = new KeyboardAdapter();

            adapter.OnKeyDown(null, new KeyDownEventArguments(Key.Up, 0, false, 0, 0));
        }