Execute() public method

public Execute ( ) : void
return void
 private void Move(MoveDirection direction)
 {
     MoveCommand moveCommand = new MoveCommand(moveCommandReciever, direction, moveDistance, objectToMove);
     moveCommand.Execute();
     commands.Add(moveCommand);
     currentCommandNum++;
 }
        public void ShouldRollbackFileMove()
        {
            // Given
            var command = new MoveCommand (OriginFilePath, DestinyFilePath);
            command.Execute ();

            // When
            command.Rollback ();

            // Then
            Assert.IsTrue (File.Exists (OriginFilePath));
            Assert.IsFalse (File.Exists (DestinyFilePath));
        }
        public void ShouldMoveFile()
        {
            // Given
            Assert.IsTrue (File.Exists (OriginFilePath));
            Assert.IsFalse (File.Exists (DestinyFilePath));

            // When
            var command = new MoveCommand (OriginFilePath, DestinyFilePath);
            command.Execute ();

            // Then
            Assert.IsFalse (File.Exists (OriginFilePath));
            Assert.IsTrue (Directory.Exists (Path.GetDirectoryName (DestinyFilePath)));
            Assert.IsTrue (File.Exists (DestinyFilePath));
        }
    void Update()
    {
        // Every tick the enemy shall fly downward and into the direction of
        // the player
        if (player != null) {
            float xDistance = player.transform.position.x - this.transform.position.x;

            Direction direction = Direction.left;

            ICommand moveCommand = new MoveCommand(direction);
            moveCommand.Execute(toControl);

            // if distance on the x-axis of this enemies and the players
            // position is smaller than a given range the enemy shall shoot
            if (Mathf.Abs(xDistance) < shootingRange) {
                ICommand shootCommand = new ShootCommand();
                shootCommand.Execute(toControl);
            }
        }
    }
Beispiel #5
0
        protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);
            var pos = e.GetPosition(this);

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                if (LineCommand?.CanExecute(pos) ?? false)
                {
                    LineCommand?.Execute(pos);
                }
            }
            else if (e.RightButton == MouseButtonState.Pressed)
            {
                if (MoveCommand?.CanExecute(pos) ?? false)
                {
                    MoveCommand?.Execute(pos);
                }
            }
        }
    void Update()
    {
        // Every tick the enemy shall fly downward and into the direction of
        // the player
        if (player != null)
        {
            float xDistance = player.transform.position.x - this.transform.position.x;

            Direction direction = Direction.left;

            ICommand moveCommand = new MoveCommand(direction);
            moveCommand.Execute(toControl);

            // if distance on the x-axis of this enemies and the players
            // position is smaller than a given range the enemy shall shoot
            if (Mathf.Abs(xDistance) < shootingRange)
            {
                ICommand shootCommand = new ShootCommand();
                shootCommand.Execute(toControl);
            }
        }
    }
        public void CommandExecution_ValidMove_CommandSavedAndMoveMadeAndMovesIncrementedAndCheckedIsSolved(Direction direction, Frame[,] board)
        {
            // arrange
            _playfieldStub.SetupGet(p => p.Board).Returns(board);

            _gameMock.SetupGet(g => g.Playfield).Returns(_playfieldStub.Object);
            _gameMock.SetupGet(g => g.Settings).Returns(_defaultSettings);

            _manipulatorMock.Setup(m => m.MakeMove(_playfieldStub.Object, direction, false)).Returns(true);

            MoveCommand testCommand = new MoveCommand(_gameMock.Object, direction, _manipulatorMock.Object, _historyMock.Object);

            // act
            testCommand.Execute();

            // assert
            _manipulatorMock.Verify(m => m.MakeMove(_playfieldStub.Object, direction, false), Times.Once);
            _gameMock.Verify(g => g.SaveGameMemento(), Times.Once);
            _historyMock.Verify(h => h.SaveCommand(testCommand), Times.Once);

            _gameMock.Verify(g => g.IncrementMovesNumber(), Times.Once);
            _gameMock.Verify(g => g.IsSolved(), Times.Once);
        }
Beispiel #8
0
        private void AssociatedObject_Drop(object sender, DragEventArgs e)
        {
            var currentRow = FindRow(e.OriginalSource, rowName, noGoCallerTypes2);

            if (currentRow == null)
            {
                return;
            }
            var currentRowIndex = currentRow.GetIndex();
            var itemToCopy      = e.Data.GetData(typeof(CoinTableCopy)) as CoinTableCopy;

            if (itemToCopy == null)
            {
                return;
            }
            itemToCopy.DestinationWorker         = (Worker)((DataGrid)sender).DataContext;
            itemToCopy.DestinationCoinTableIndex = currentRowIndex;
            if (effect == DragDropEffects.Move)
            {
                if (MoveCommand != null)
                {
                    MoveCommand.Execute(itemToCopy);
                }
            }
            if (effect == DragDropEffects.Copy)
            {
                if (CopyCommand != null)
                {
                    CopyCommand.Execute(itemToCopy);
                }
            }
            var dg = ((DataGrid)sender);

            dg.SelectedIndex = currentRowIndex;
            dg.Focus();
            floatingTip.IsOpen = false;
        }
Beispiel #9
0
        public void Test_Execute_BottomLeft(
            [ValueSource(nameof(ExecuteValues))] Tuple <int, int, Direction, int, int, bool> values)
        {
            // arrange
            _piece.X = values.Item1;
            _piece.Y = values.Item2;
            _piece.SightDirection = values.Item3;
            bool thrown = false;

            // act
            try
            {
                _command.Execute();
            }
            catch (InvalidOperationException)
            {
                thrown = true;
            }

            // assert
            Assert.AreEqual(values.Item6, thrown);
            Assert.AreEqual(values.Item4, _piece.X);
            Assert.AreEqual(values.Item5, _piece.Y);
        }
Beispiel #10
0
        private void HandleTap(int row, int column, Rectangle field)
        {
            if (Match.State != Core.Enums.GameState.YourTurn)
            {
                return;
            }

            var board        = Match.CurrentBoard.Content as ChessMoveResult;
            var playerIndex  = Match.PlayerIndex;
            var clickedPiece = board.PieceInfos.FirstOrDefault(p => p.Row == row && p.Column == column);

            // We clicked on an empty field
            if (clickedPiece == null)
            {
                // ... and haven't selected any pieces to move, so we return early
                if (lastTapped == null)
                {
                    return;
                }
            }
            // If we clicked on our own piece
            else if ((playerIndex == 0 && clickedPiece.Color == Core.DTOs.Chess.Color.White) || (playerIndex == 1 && clickedPiece.Color == Core.DTOs.Chess.Color.Black))
            {
                // Save the position as our selected piece and return
                lastTapped = new Field()
                {
                    Column = column, Row = row
                };
                if (lastTappedRect != null)
                {
                    lastTappedRect.Fill = new SolidColorBrush(lastTappedRectColor);
                }
                lastTappedRect = field;
                var fieldColor = (row + column) % 2 == 0 ? Colors.White : Colors.DarkGray;
                lastTappedRectColor       = fieldColor;
                (field as Rectangle).Fill = new SolidColorBrush(Colors.Yellow);
                return;
            }
            // Else if we clicked on the opponent's piece
            else if ((playerIndex == 0 && clickedPiece.Color == Core.DTOs.Chess.Color.Black) || (playerIndex == 1 && clickedPiece.Color == Core.DTOs.Chess.Color.White))
            {
                // Do nothing if we haven't selected our piece to move yet
                if (lastTapped == null)
                {
                    return;
                }
            }
            // Perform the move, then reset highlight
            var moveData = new ChessMoveData()
            {
                FromColumn = lastTapped.Column,
                FromRow    = lastTapped.Row,
                ToColumn   = column,
                ToRow      = row,
                MatchId    = Match.Id
            };

            MoveCommand.Execute(moveData);
            lastTapped          = null;
            lastTappedRect.Fill = new SolidColorBrush(lastTappedRectColor);
            lastTappedRect      = null;
        }
Beispiel #11
0
        // Update is called once per frame
        void Update()
        {
            if (CommandManager.Instance.m_isLocked)
            {
                return;
            }

            float h = Input.GetAxis("Horizontal");
            float v = Input.GetAxis("Vertical");

            var move = new MoveCommand(this.transform, v, h, m_speed);

            //move.Execute();

            //(回転と移動)の同時押し
            if (Input.GetKeyDown(KeyCode.Z) && h == 1 || Input.GetKeyDown(KeyCode.Z) && v == 1)
            {
                Debug.Log("同時におした");
                var rotate = new RotateCommand(this.transform, m_rotate_Z);
                rotate.Execute();
                move.Execute();
                commands[0] = rotate;
                commands[1] = move;
                CommandManager.Instance.AddCommand(true, commands);
                return;
            }
            else if (Input.GetKeyDown(KeyCode.X) && h == 1 || Input.GetKeyDown(KeyCode.X) && v == 1)
            {
                Debug.Log("同時におした");
                var rotate = new RotateCommand(this.transform, m_rotate_Z * -1);
                rotate.Execute();
                move.Execute();
                commands[0] = rotate;
                commands[1] = move;
                CommandManager.Instance.AddCommand(true, commands);
                return;
            }

            //通常

            if (Input.GetKeyDown(KeyCode.Z))
            {
                //左回転
                //transform.Rotate(new Vector3(0, 0, m_rotate_Z));
                var rotate = new RotateCommand(this.transform, m_rotate_Z);
                rotate.Execute();
                commands[0] = rotate;
                CommandManager.Instance.AddCommand(false, commands);
                return;
                //CommandManager.Instance.AddCommand(rotate);
            }
            else if (Input.GetKeyDown(KeyCode.X))
            {
                //右回転
                //transform.Rotate(new Vector3(0, 0, m_rotate_Z * -1));
                var rotate = new RotateCommand(this.transform, m_rotate_Z * -1);
                rotate.Execute();
                commands[0] = rotate;
                CommandManager.Instance.AddCommand(false, commands);
                return;
                // CommandManager.Instance.AddCommand(rotate);
            }

            commands[0] = move;
            CommandManager.Instance.AddCommand(false, commands);
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            Console.Clear();
            ConsoleKeyInfo op;

            do
            {
                //Limpiar la pantalla
                Console.WriteLine("");
                Console.WriteLine("Menú - Patrón Command");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("Que desea realizar.");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[A] - Mover una unidad");
                Console.WriteLine("[E] - Reunir recursos");
                Console.WriteLine("[Esc]Salirtnn");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Seleccione opcion...");
                op = Console.ReadKey(true);


                switch (op.Key)
                {
                case ConsoleKey.A:
                    Console.WriteLine("Ud seleccionó la opción [Mover una unidad]");
                    Console.Write("Presione una tecla para continuar...");
                    Console.ReadKey();

                    Console.WriteLine("Ingrese el valor de X");
                    var _X = Console.ReadLine();
                    Console.WriteLine("Ingrese el valor de Y");
                    var _Y = Console.ReadLine();

                    var unit        = new Probe();
                    var moveCommand = new MoveCommand(unit, Convert.ToInt32(_X), Convert.ToInt32(_Y));
                    moveCommand.Execute();
                    Console.Write("Las posiciones de movimiento fueron, X : " + unit.Position.X + " y  Y : " + unit.Position.Y);

                    break;

                case ConsoleKey.E:

                    Console.WriteLine("Ud seleccionó la opción [Reunir recursos]");
                    Console.Write("Presione una tecla para continuar...");
                    Console.ReadKey();

                    var unit_         = new Probe();
                    var gatherCommand = new GatherCommand(unit_);
                    gatherCommand.Execute();

                    Console.Write("El valor fue de " + unit_.Minerals);


                    break;

                case ConsoleKey.Escape:
                    Console.WriteLine("Chao");

                    break;
                }
            } while (op.Key != ConsoleKey.Escape);

            Console.WriteLine("Hello World!");
        }
Beispiel #13
0
 public void Execute_RobotSupplied_MoveCalledOnRobot()
 {
     command.Execute('M', robotStub);
     robotStub.AssertWasCalled(s => s.Move(), o => o.Repeat.Once());
 }
Beispiel #14
0
 public void CanNotExecutePlaceCommandWithNullRobot()
 {
     _moveCommand.Execute(null);
 }
 public void ShouldThrowExceptionIfFileDoesntExist()
 {
     // When
     var command = new MoveCommand (@"c:\temp\foo.txt", DestinyFilePath);
     command.Execute ();
 }