void Update()
 {
     if (Input.GetKey(KeyCode.W))
     {
         moveUp = new MoveUpCommand(this.transform, _speed);
         moveUp.Execute();
         CommandManger_2.Instance.AddCommand(moveUp);
     }
     else if (Input.GetKey(KeyCode.S))
     {
         moveDown = new MoveDownCommand(this.transform, _speed);
         moveDown.Execute();
         CommandManger_2.Instance.AddCommand(moveDown);
     }
     else if (Input.GetKey(KeyCode.A))
     {
         moveLeft = new MoveLeftCommand(this.transform, _speed);
         moveLeft.Execute();
         CommandManger_2.Instance.AddCommand(moveLeft);
     }
     else if (Input.GetKey(KeyCode.D))
     {
         moveRight = new MoveRightCommand(this.transform, _speed);
         moveRight.Execute();
         CommandManger_2.Instance.AddCommand(moveRight);
     }
 }
        protected override void OnPreviewKeyDown(KeyEventArgs e)
        {
            base.OnPreviewKeyDown(e);

            DataGridCell senderCell = e.OriginalSource as DataGridCell;
            bool         ctrlDown   = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl);

            if (e.Key == Key.Return)
            {
                if (senderCell != null && !senderCell.IsEditing)
                {
                    // Enter edit mode if current cell is not in edit mode
                    senderCell.Focus();
                    this.BeginEdit();
                    e.Handled = true;
                }
            }
            else if (e.Key == Key.Space)
            {
                if (senderCell != null && !senderCell.IsEditing)
                {
                    object item = senderCell.DataContext;

                    // In some cases senderCell is not selected. This can happen after multi selection over all items.
                    if (!senderCell.IsSelected)
                    {
                        item = SelectedItem; // simply use first selected item
                    }

                    ToggleEnabledForItem(item);
                    e.Handled = true;
                }
            }
            else if (ctrlDown && e.Key == Key.Up)
            {
                if (MoveUpCommand != null && MoveUpCommand.CanExecute(null))
                {
                    var focusedCellItem = (Keyboard.FocusedElement as DataGridCell)?.DataContext;

                    MoveUpCommand.Execute(null);

                    // DataGrid loses keyboard focus after moving items
                    FocusCellAfterDelay(focusedCellItem);
                }
                e.Handled = true;
            }
            else if (ctrlDown && e.Key == Key.Down)
            {
                if (MoveDownCommand != null && MoveDownCommand.CanExecute(null))
                {
                    var focusedCellItem = (Keyboard.FocusedElement as DataGridCell)?.DataContext;

                    MoveDownCommand.Execute(null);

                    // DataGrid loses keyboard focus after moving items
                    FocusCellAfterDelay(focusedCellItem);
                }
                e.Handled = true;
            }
        }
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKey(KeyCode.Z))
     {
         // Move up command
         moveUp = new MoveUpCommand(this.transform, this._speed);
         moveUp.Execute();
         MoveCommandManager.Instance.AddCommand(moveUp);
     }
     else if (Input.GetKey(KeyCode.S))
     {
         // Move down command
         moveDown = new MoveDownCommand(this.transform, this._speed);
         moveDown.Execute();
         MoveCommandManager.Instance.AddCommand(moveDown);
     }
     else if (Input.GetKey(KeyCode.Q))
     {
         // Move left command
         moveLeft = new MoveLeftCommand(this.transform, this._speed);
         moveLeft.Execute();
         MoveCommandManager.Instance.AddCommand(moveLeft);
     }
     else if (Input.GetKey(KeyCode.D))
     {
         // Move right command
         moveRight = new MoveRightCommand(this.transform, this._speed);
         moveRight.Execute();
         MoveCommandManager.Instance.AddCommand(moveRight);
     }
 }
 void Update()
 {
     if (Input.GetKey(upKey))
     {
         moveUp = new MoveUpCommand(this.transform, _speed);
         moveUp.Execute();
         CommandManager.Instance.AddBuffer(moveUp);
     }
     else if (Input.GetKey(downKey))
     {
         moveDown = new MoveDownCommand(this.transform, _speed);
         moveDown.Execute();
         CommandManager.Instance.AddBuffer(moveDown);
     }
     else if (Input.GetKey(rightKey))
     {
         moveRight = new MoveRightCommand(this.transform, _speed);
         moveRight.Execute();
         CommandManager.Instance.AddBuffer(moveRight);
     }
     if (Input.GetKey(leftKey))
     {
         moveLeft = new MoveLeftCommand(this.transform, _speed);
         moveLeft.Execute();
         CommandManager.Instance.AddBuffer(moveLeft);
     }
 }
        public void MoveCommRight_When_NewDesk_Then_RightMoving()
        {
            var  desk        = _helper.GenerateDesk(4);
            var  moveCommand = new MoveDownCommand(desk);
            bool res         = moveCommand.Execute();

            Assert.True(res);
        }
        public void MoveCommRight_When_NewDesk_Then_DeskChanged()
        {
            var newDesk     = _helper.GenerateDesk(4);
            var desk        = _helper.GenerateDesk(4);
            var moveCommand = new MoveDownCommand(desk);

            moveCommand.Execute();

            Assert.NotEqual(newDesk.GetDesk(), desk.GetDesk());
        }
Exemple #7
0
        public void HoverCommand_ShouldExecuteClientMoveDown()
        {
            // arrange
            moveDownCommand = new MoveDownCommand(DroneClientMock.Object);

            // act
            moveDownCommand.Execute();

            // assert
            DroneClientMock.Verify(x => x.MoveDown(), Times.Once);
        }
Exemple #8
0
        public void SimpleWinChecker_When_UncorrectDesk_Then_FalseResult()
        {
            var desk        = _helper.GenerateDesk(4);
            var moveCommand = new MoveDownCommand(desk);

            moveCommand.Execute();
            desk.SetWinner(new SimpleWinChecker());
            bool res = desk.IsInWinPosition();

            Assert.False(res);
        }
        public void MoveCommRightandAndUndo_When_NewDesk_Then_CorrectUndo()
        {
            var newDesk     = _helper.GenerateDesk(4);
            var desk        = _helper.GenerateDesk(4);
            var moveCommand = new MoveDownCommand(desk);

            moveCommand.Execute();

            moveCommand.Undo();

            Assert.Equal(newDesk.GetDesk(), desk.GetDesk());
        }
Exemple #10
0
        public void ShouldInvokeMoveDownAndSetStateToHandled()
        {
            var slnControl = new Mock <ISolutionExplorerControl>();

            slnControl.Setup(x => x.MoveDown());

            var command = new MoveDownCommand(slnControl.Object);
            var context = new Context();
            var result  = command.Execute(context, Keys.J);

            Assert.Equal(CommandState.Handled, result.State);
            slnControl.VerifyAll();
        }
        public void TestCommandMoveDown()
        {
            // Arrange
            int     originalLocationY = fakeGameComponent.Y;
            Command moveDown          = new MoveDownCommand();
            int     finalLocationY;
            // The amount the game object should move in one command
            int expectedMoveAmount = 1;

            // Act
            moveDown.Execute(fakeGameComponent);
            finalLocationY = fakeGameComponent.Y;

            // Assert
            Assert.AreEqual(finalLocationY, originalLocationY - expectedMoveAmount);
        }