Ejemplo n.º 1
0
        /// <summary>
        /// Handler for when slide manipulation is complete
        /// </summary>
        private void ContentGrid_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
        {
            if (SwipeStatus == SwipeStatus.Idle)
            {
                return;
            }

            var x = _transform.TranslateX;

            _contentAnimation.From = x;
            _commandContainerClipTranslateAnimation.From = 0;
            _commandContainerClipTranslateAnimation.To   = -x;
            _contentStoryboard.Begin();

            if (SwipeStatus == SwipeStatus.SwipingPassedLeftThreshold)
            {
                RightCommandRequested?.Invoke(this, EventArgs.Empty);
                RightCommand?.Execute(RightCommandParameter);
            }
            else if (SwipeStatus == SwipeStatus.SwipingPassedRightThreshold)
            {
                LeftCommandRequested?.Invoke(this, EventArgs.Empty);
                LeftCommand?.Execute(LeftCommandParameter);
            }

            Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { SwipeStatus = SwipeStatus.Idle; }).AsTask();
        }
Ejemplo n.º 2
0
    void Update()
    {
        if (Input.GetKey(KeyCode.UpArrow))
        {
            moveUp = new UpCommand(this.transform, _speed);
            moveUp.Execute();
            MoveGameManager.Instance.AddCommand(moveUp);
        }

        if (Input.GetKey(KeyCode.DownArrow))
        {
            moveDown = new DownCommand(this.transform, _speed);
            moveDown.Execute();
            MoveGameManager.Instance.AddCommand(moveDown);
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            moveLeft = new LeftCommand(this.transform, _speed);
            moveLeft.Execute();
            MoveGameManager.Instance.AddCommand(moveLeft);
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            moveRight = new RightCommand(this.transform, _speed);
            moveRight.Execute();
            MoveGameManager.Instance.AddCommand(moveRight);
        }
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Handler for when slide manipulation is complete
        /// </summary>
        private void ContentGrid_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
        {
            if (!MouseSlidingEnabled && e.PointerDeviceType == PointerDeviceType.Mouse)
            {
                return;
            }

            var x = _transform.TranslateX;

            _contentAnimation.From = x;
            _contentStoryboard.Begin();

            _leftCommandTransform.TranslateX  = 0;
            _rightCommandTransform.TranslateX = 0;
            _leftCommandPanel.Opacity         = 1;
            _rightCommandPanel.Opacity        = 1;

            if (x < -ActivationWidth)
            {
                RightCommandRequested?.Invoke(this, new EventArgs());
                RightCommand?.Execute(null);
            }
            else if (x > ActivationWidth)
            {
                LeftCommandRequested?.Invoke(this, new EventArgs());
                LeftCommand?.Execute(null);
            }
        }
Ejemplo n.º 4
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKey(KeyCode.UpArrow))
     {
         ICommand command = new UpCommand(this.transform, this._speed);
         command.Execute();
         CommandManager.Instance.AddCommand(command);
     }
     else if (Input.GetKey(KeyCode.DownArrow))
     {
         ICommand command = new DownCommand(this.transform, this._speed);
         command.Execute();
         CommandManager.Instance.AddCommand(command);
     }
     else if (Input.GetKey(KeyCode.RightArrow))
     {
         ICommand command = new RightCommand(this.transform, this._speed);
         command.Execute();
         CommandManager.Instance.AddCommand(command);
     }
     else if (Input.GetKey(KeyCode.LeftArrow))
     {
         ICommand command = new LeftCommand(this.transform, this._speed);
         command.Execute();
         CommandManager.Instance.AddCommand(command);
     }
     else if (Input.GetKeyDown(KeyCode.Space))
     {
         CommandManager.Instance.Reverse();
     }
 }
Ejemplo n.º 5
0
        public HeaderView()
        {
            InitializeComponent();
            TapGestureRecognizer LeftClickTGR = new TapGestureRecognizer();

            LeftClickTGR.Tapped += (object sender, EventArgs e) =>
            {
                if (LeftCommand != null)
                {
                    LeftCommand.Execute(this);
                }
            };
            LeftImageView.GestureRecognizers.Add(LeftClickTGR);

            TapGestureRecognizer RightClickTGR = new TapGestureRecognizer();

            RightClickTGR.Tapped += (object sender, EventArgs e) =>
            {
                if (RightCommand != null)
                {
                    RightCommand.Execute(this);
                }
            };
            RightImageView.GestureRecognizers.Add(RightClickTGR);
        }
Ejemplo n.º 6
0
        public void LeftCommand_WithoutSetCurrentPosition_Returns_UnchangedPosition()
        {
            ICommand           leftCommand       = new LeftCommand(new string[] { });
            Position           currentPosition   = null;
            IPositionValidator positionValidator = new PositionValidator(5, 5);

            Position newPosition = leftCommand.Execute(currentPosition, positionValidator);

            Assert.IsNull(newPosition);
        }
Ejemplo n.º 7
0
        public void EastLeftTest()
        {
            var currRobot = new Robot()
            {
                Dir = Face.South
            };
            var command = new LeftCommand();

            currRobot = command.Execute("Left", currRobot);
            Assert.Equal(Face.East, currRobot.Dir);
        }
Ejemplo n.º 8
0
        public void When_Given_Direction_and_Coordinates_Then_It_Should_LeftCommand_Execute(int x, int y)
        {
            ICoordinate coordinate = new Coordinate(x, y);
            IDirection  direction  = new EastDirection();
            ICommand    command    = new LeftCommand(direction, coordinate);
            var         result     = command.Execute();

            result.Should().NotBeNull();
            result.Coordinate.Should().NotBeNull();
            result.Direction.Should().NotBeNull();
        }
Ejemplo n.º 9
0
        public void ShouldNotTurnInvalidRobot()
        {
            var robot = new Robot();

            var command = new LeftCommand();

            command.Execute(robot);

            Assert.Equal(Direction.Invalid, robot.Direction);
            Assert.Equal(Coordinate.Invalid, robot.Coordinate);
        }
Ejemplo n.º 10
0
        public void LeftCommandWrap()
        {
            var mockTable = Mock.Of <ITableTop>();
            var robot     = new Robot()
            {
                X = 0, Y = 0, DirectionFacing = Direction.North
            };
            var command = new LeftCommand();

            command.Execute(robot, mockTable);
            Assert.AreEqual(robot.DirectionFacing, Direction.West);
        }
        /// <summary>
        /// Handler for when slide manipulation is complete
        /// </summary>
        private void ContentGrid_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
        {
            if ((!MouseSlidingEnabled && e.PointerDeviceType == PointerDeviceType.Mouse) || (!IsLeftCommandEnabled && !IsRightCommandEnabled))
            {
                return;
            }

            var endcapX = _endcapPathTransform.TranslateX;

            _endcapPathAnimation.From = endcapX;

            var startcapX = _startcapPathTransform.TranslateX;

            _startcapAnimation.From = startcapX;

            var x = _transform.TranslateX;

            _contentAnimation.From = x;
            _commandContainerClipTranslateAnimation.From = 0;
            _commandContainerClipTranslateAnimation.To   = -x;

            if (x > _startcapPath.ActualWidth)
            {
                double unitsPerMs               = x / FinishAnimationDuration;
                double distanceTillStartCap     = x - _startcapPath.ActualWidth;
                double millisecondsTillStartCap = distanceTillStartCap / unitsPerMs;
                _startcapAnimation.BeginTime = TimeSpan.FromMilliseconds(millisecondsTillStartCap);

                double millisecondsFromStartCapToEnd = _startcapPath.ActualWidth / unitsPerMs;
                _startcapAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(millisecondsFromStartCapToEnd));
            }
            else
            {
                _startcapAnimation.BeginTime = null;
                _startcapAnimation.Duration  = new Duration(TimeSpan.FromMilliseconds(FinishAnimationDuration));
            }

            _contentStoryboard.Begin();

            if (SwipeStatus == SwipeStatus.SwipingPassedLeftThreshold)
            {
                RightCommandRequested?.Invoke(this, new EventArgs());
                RightCommand?.Execute(RightCommandParameter);
            }
            else if (SwipeStatus == SwipeStatus.SwipingPassedRightThreshold)
            {
                LeftCommandRequested?.Invoke(this, new EventArgs());
                LeftCommand?.Execute(LeftCommandParameter);
            }

            Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { SwipeStatus = SwipeStatus.Idle; }).AsTask();
        }
Ejemplo n.º 12
0
        public void LeftCommand_Should_Call_Create_Method_When_Expected_Value()
        {
            //Given
            _roverService.Setup(s => s.GetCurrentRover()).Returns(new RoverPositionModel(1, 1, Direction.North));

            var rightCommand = new LeftCommand(_roverService.Object, _directionService.Object);

            //When
            rightCommand.Execute();

            //Than
            _directionService.Verify(mock => mock.Left(Direction.North), Times.Once);
        }
Ejemplo n.º 13
0
 private void TryExecuteCommand(double x)
 {
     if (x < -ActivationOffset)
     {
         RightCommandRequested?.Invoke(this, new EventArgs());
         RightCommand?.Execute(RightCommandParameter);
     }
     else if (x > ActivationOffset)
     {
         LeftCommandRequested?.Invoke(this, new EventArgs());
         LeftCommand?.Execute(LeftCommandParameter);
     }
 }
Ejemplo n.º 14
0
        public void ShouldTurnLeftAndKeepCoordinate(Direction before, Direction after)
        {
            var robot = new Robot();

            robot.PlaceAt(new Coordinate(1, 1), before);

            var command = new LeftCommand();

            command.Execute(robot);

            Assert.Equal(after, robot.Direction);
            Assert.Equal(1, robot.Coordinate.X);
            Assert.Equal(1, robot.Coordinate.Y);
        }
Ejemplo n.º 15
0
        public void Execute_RobotNotPlacedOnTable_NoEffect()
        {
            // Arrange
            var robot       = new Robot();
            var leftCommand = new LeftCommand();

            // Act
            leftCommand.Execute(robot);

            // Assert
            Assert.Null(robot.Heading);
            Assert.Null(robot.X);
            Assert.Null(robot.Y);
        }
Ejemplo n.º 16
0
        public void LeftCommand_CurrentPositionEast_SetPositionToNorth()
        {
            Position currentPosition = new Position
            {
                Facing = Direction.EAST,
                X      = 0,
                Y      = 0
            };
            IPositionValidator positionValidator = new PositionValidator(5, 5);
            ICommand           leftCommand       = new LeftCommand(new string[] { });

            Position newPosition = leftCommand.Execute(currentPosition, positionValidator);

            Assert.That(newPosition.Facing == Direction.NORTH);
        }
Ejemplo n.º 17
0
        public void TestLeftCommand()
        {
            var rover = new Rover();

            rover.Stand(new Point(1, 1), Direction.NORTH);

            var cmd = new LeftCommand(rover);

            Assert.IsTrue(cmd.Validate());

            cmd.Execute();

            Assert.AreEqual(rover.Position.X, 1);
            Assert.AreEqual(rover.Position.Y, 1);
            Assert.AreEqual(rover.Direction, Direction.WEST);
        }
        public void Robot_Valid_Rotate_Left_Command_From_North_Should_Turn_Robot_To_West()
        {
            Robot   toyRobot = new Robot(table);
            Command command  = new PlaceCommand();

            command.Execute(toyRobot, "2,2,NORTH");
            var afterPlacePosition = toyRobot.CurrentPosition;

            command = new LeftCommand();
            command.Execute(toyRobot);
            var afterTurnLeftPosition = toyRobot.CurrentPosition;

            Assert.NotNull(afterPlacePosition);
            Assert.NotNull(afterTurnLeftPosition);
            Assert.Equal("WEST", afterTurnLeftPosition.Direction.ToString());
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Handler for when slide manipulation is complete
        /// </summary>
        private void ContentGrid_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
        {
            if (!MouseSlidingEnabled && e.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
            {
                return;
            }

            var x = transform.TranslateX;

            contentAnimation.From = x;
            contentStoryboard.Begin();

            leftCommandTransform.TranslateX  = 0;
            rightCommandTransform.TranslateX = 0;
            leftCommandPanel.Opacity         = 1;
            rightCommandPanel.Opacity        = 1;

            if (x < -ActivationWidth)
            {
                if (RightCommandRequested != null)
                {
                    RightCommandRequested(this, new EventArgs());
                }
                if (RightCommand != null)
                {
                    RightCommand.Execute(null);
                }
            }
            else if (x > ActivationWidth)
            {
                if (LeftCommandRequested != null)
                {
                    LeftCommandRequested(this, new EventArgs());
                }
                if (LeftCommand != null)
                {
                    LeftCommand.Execute(null);
                }
            }
        }
Ejemplo n.º 20
0
 private void Update()
 {
     if (Input.GetButtonDown("Jump"))
     {
         jumpCom.Execute(gameObject);
     }
     else if (Input.GetKeyDown(KeyCode.S))
     {
         crouchCom.Execute(gameObject);
     }
     else if (Input.GetKeyDown(KeyCode.Mouse0))
     {
         attackCom.Execute(gameObject);
     }
     else if (Input.GetKeyDown(KeyCode.Mouse1))
     {
         specialCom.Execute(gameObject);
     }
     else if (Input.GetKeyDown(KeyCode.B))
     {
         altSpecialCom.Execute(gameObject);
     }
     else if (Input.GetKeyDown(KeyCode.Q))
     {
         mindControlCom.Execute(gameObject);
     }
     else if (Input.GetKey(KeyCode.A))
     {
         leftCom.Execute(gameObject);
     }
     else if (Input.GetKey(KeyCode.D))
     {
         rightCom.Execute(gameObject);
     }
     else
     {
         idleCom.Execute(gameObject);
     }
 }
Ejemplo n.º 21
0
    private void MakeCommand(KeyValuePair <KeyCode, string> item)
    {
        Command command = null;

        switch (item.Value)
        {
        case "right":
            command = new RightCommand();
            break;

        case "left":
            command = new LeftCommand();
            break;

        case "rewind":
            if (Commands.Count > 0)
            {
                if (!MoveCommandTarg.activeSelf)
                {
                    MoveCommandTarg.SetActive(true);
                }
                command = (Command)Commands.Pop();
                if (command is ICommandUndo)
                {
                    command = ((ICommandUndo)command).UndoCommand;
                }
            }
            break;
        }

        if (command != null)
        {
            if (command is ICommandUndo)
            {
                Commands.Push((ICommandUndo)command);
            }
            command.Execute(MoveCommandTarg);
        }
    }
Ejemplo n.º 22
0
        public void Execute_RobotFacingWest_FacingSouth()
        {
            // Arrange
            var robot   = new Robot();
            var table   = new Table();
            var x       = 0;
            var y       = 0;
            var heading = (int)CompassPoint.West;

            robot.PlaceOnTable(table, x, y, heading);

            var leftCommand = new LeftCommand();

            // Act
            leftCommand.Execute(robot);

            // Assert
            Assert.Equal(x, robot.X);
            Assert.Equal(y, robot.Y);
            Assert.Equal((int)CompassPoint.South, robot.Heading);
            Assert.Same(table, robot.Table);
        }
Ejemplo n.º 23
0
        public void TheRobotShouldTurnAllDirectionWithTurnCommandAfterPlacedCorrectlly()
        {
            ToyRobot     robot        = PlaceRobotInPosition(new Position(3, 3), Direction.NORTH);
            LeftCommand  leftCommand  = new LeftCommand();
            RightCommand rightCommand = new RightCommand();

            //Place Robot At the edge of NORTH, face to NORTH
            leftCommand.Execute(robot);
            //Robot stayed at the last correct position
            Assert.AreEqual(robot.RobotRoute.RobotFaceDirection, Direction.WEST);

            rightCommand.Execute(robot);
            //Robot stayed at the last correct position
            Assert.AreEqual(robot.RobotRoute.RobotFaceDirection, Direction.NORTH);

            rightCommand.Execute(robot);
            //Robot stayed at the last correct position
            Assert.AreEqual(robot.RobotRoute.RobotFaceDirection, Direction.EAST);

            rightCommand.Execute(robot);
            //Robot stayed at the last correct position
            Assert.AreEqual(robot.RobotRoute.RobotFaceDirection, Direction.SOUTH);
        }
Ejemplo n.º 24
0
 public void visit(LeftCommand left)
 {
     left.Execute();
 }
Ejemplo n.º 25
0
 public void CanNotExecutePlaceCommandWithNullRobot()
 {
     _leftCommand.Execute(null);
 }
Ejemplo n.º 26
0
        public void Update()
        {
            gamePadState = GamePad.GetState(PlayerIndex.One);
            ICommand command;
            ICommand idleCommand = new IdleMarioCommand(Game1.Instance);

            if (gamePadState.IsButtonDown(Buttons.A) || gamePadState.IsButtonDown(Buttons.B) || gamePadState.IsButtonDown(Buttons.DPadLeft) || gamePadState.IsButtonDown(Buttons.DPadRight) ||
                gamePadState.IsButtonDown(Buttons.DPadUp) || gamePadState.IsButtonDown(Buttons.DPadDown) || gamePadState.ThumbSticks.Left.X > 0.5f || gamePadState.ThumbSticks.Left.X < -0.5f ||
                gamePadState.ThumbSticks.Left.Y > 0.5f || gamePadState.ThumbSticks.Left.X < -0.5f || gamePadState.IsButtonDown(Buttons.Back) || gamePadState.IsButtonDown(Buttons.Start))
            {
                if (gamePadState.IsButtonDown(Buttons.A))
                {
                    command = new UpCommand(Game1.Instance);
                    command.Execute();
                }
                if (gamePadState.IsButtonDown(Buttons.B))
                {
                    command = new FireBallCommand(Game1.Instance);
                    command.Execute();
                    command = new SprintCommand(Game1.Instance);
                    command.Execute();
                }
                if (gamePadState.IsButtonDown(Buttons.DPadLeft))
                {
                    command = new LeftCommand(Game1.Instance);
                    command.Execute();
                }
                if (gamePadState.IsButtonDown(Buttons.DPadRight))
                {
                    command = new RightCommand(Game1.Instance);
                    command.Execute();
                }
                if (gamePadState.IsButtonDown(Buttons.DPadUp))
                {
                    command = new UpCommand(Game1.Instance);
                    command.Execute();
                }
                if (gamePadState.IsButtonDown(Buttons.DPadDown))
                {
                    command = new DownCommand(Game1.Instance);
                    command.Execute();
                }
                if (gamePadState.ThumbSticks.Left.X > 0.5f)
                {
                    command = new RightCommand(Game1.Instance);
                    command.Execute();
                }
                if (gamePadState.ThumbSticks.Left.X < -0.5f)
                {
                    command = new LeftCommand(Game1.Instance);
                    command.Execute();
                }
                if (gamePadState.ThumbSticks.Left.Y > 0.5f)
                {
                    command = new UpCommand(Game1.Instance);
                    command.Execute();
                }
                if (gamePadState.ThumbSticks.Left.X < -0.5f)
                {
                    command = new DownCommand(Game1.Instance);
                    command.Execute();
                }
                if (gamePadState.IsButtonDown(Buttons.Back))
                {
                    command = new ExitCommand(Game1.Instance);
                    command.Execute();
                }
                if (gamePadState.IsButtonDown(Buttons.Start))
                {
                    command = new SwitchControllerCommand();
                    command.Execute();
                }
                if (!gamePadState.IsButtonDown(Buttons.DPadLeft) && !gamePadState.IsButtonDown(Buttons.DPadRight))
                {
                    command = new IdleMarioCommand(Game1.Instance);
                    command.Execute();
                }
            }
            else
            {
                idleCommand.Execute();
            }
        }