// 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(); } }
/// <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(); }
/// <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); } }
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); } }
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); }
public void RightCommand_WithoutSetCurrentPosition_Returns_UnchangedPosition() { ICommand rightCommand = new RightCommand(new string[] { }); Position currentPosition = null; IPositionValidator positionValidator = new PositionValidator(5, 5); Position newPosition = rightCommand.Execute(currentPosition, positionValidator); Assert.IsNull(newPosition); }
public void ShouldNotTurnInvalidRobot() { var robot = new Robot(); var command = new RightCommand(); command.Execute(robot); Assert.Equal(Direction.Invalid, robot.Direction); Assert.Equal(Coordinate.Invalid, robot.Coordinate); }
public void When_Given_Direction_and_Coordinates_Then_It_Should_RightCommand_Execute(int x, int y) { ICoordinate coordinate = new Coordinate(x, y); IDirection direction = new EastDirection(); ICommand command = new RightCommand(direction, coordinate); var result = command.Execute(); result.Should().NotBeNull(); result.Coordinate.Should().NotBeNull(); result.Direction.Should().NotBeNull(); }
public void EastRighttTest() { var currRobot = new Robot() { Dir = Face.South }; var command = new RightCommand(); currRobot = command.Execute("Right", currRobot); Assert.Equal(Face.West, currRobot.Dir); }
public void RightCommand() { var mockTable = Mock.Of <ITableTop>(); var robot = new Robot() { X = 0, Y = 0, DirectionFacing = Direction.North }; var command = new RightCommand(); command.Execute(robot, mockTable); Assert.AreEqual(robot.DirectionFacing, Direction.East); }
/// <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(); }
public void RightCommand_Should_Call_Create_Method_When_Expected_Value() { //Given _roverService.Setup(s => s.GetCurrentRover()).Returns(new RoverPositionModel(1, 1, Direction.North)); var rightCommand = new RightCommand(_roverService.Object, _directionService.Object); //When rightCommand.Execute(); //Than _directionService.Verify(mock => mock.Right(Direction.North), Times.Once); }
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); } }
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); }
public void Execute_RobotNotPlacedOnTable_NoEffect() { // Arrange var robot = new Robot(); var rightCommand = new RightCommand(); // Act rightCommand.Execute(robot); // Assert Assert.Null(robot.Heading); Assert.Null(robot.X); Assert.Null(robot.Y); }
public void ShouldTurnRightAndKeepCoordinate(Direction before, Direction after) { var robot = new Robot(); robot.PlaceAt(new Coordinate(1, 1), before); var command = new RightCommand(); command.Execute(robot); Assert.Equal(after, robot.Direction); Assert.Equal(1, robot.Coordinate.X); Assert.Equal(1, robot.Coordinate.Y); }
public void RightCommand_CurrentPositionWest_SetPositionToNorth() { Position currentPosition = new Position { Facing = Direction.WEST, X = 0, Y = 0 }; IPositionValidator positionValidator = new PositionValidator(5, 5); ICommand RightCommand = new RightCommand(new string[] { }); Position newPosition = RightCommand.Execute(currentPosition, positionValidator); Assert.That(newPosition.Facing == Direction.NORTH); }
public HeaderWithImageView() { InitializeComponent(); TapGestureRecognizer RightClickTGR = new TapGestureRecognizer(); RightClickTGR.Tapped += (object sender, EventArgs e) => { if (RightCommand != null) { RightCommand.Execute(this); } }; RightImageView.GestureRecognizers.Add(RightClickTGR); TapGestureRecognizer ThirdRightClickTGR = new TapGestureRecognizer(); ThirdRightClickTGR.Tapped += (object sender, EventArgs e) => { if (RightThirdCommand != null) { RightThirdCommand.Execute(this); } }; RightThirdImageView.GestureRecognizers.Add(ThirdRightClickTGR); TapGestureRecognizer SecondRightClickTGR = new TapGestureRecognizer(); SecondRightClickTGR.Tapped += (object sender, EventArgs e) => { if (RightSecondCommand != null) { RightSecondCommand.Execute(this); } }; RightSecondImageView.GestureRecognizers.Add(SecondRightClickTGR); TapGestureRecognizer FirstRightClickTGR = new TapGestureRecognizer(); FirstRightClickTGR.Tapped += (object sender, EventArgs e) => { if (RightFirstCommand != null) { RightFirstCommand.Execute(this); } }; RightFirstImageView.GestureRecognizers.Add(FirstRightClickTGR); }
public void Robot_Valid_Rotate_Right_Command_From_North_Should_Turn_Robot_To_East() { Robot toyRobot = new Robot(table); Command command = new PlaceCommand(); command.Execute(toyRobot, "2,2,NORTH"); var afterPlacePosition = toyRobot.CurrentPosition; command = new RightCommand(); command.Execute(toyRobot); var afterTurnRightPosition = toyRobot.CurrentPosition; Assert.NotNull(afterPlacePosition); Assert.NotNull(afterTurnRightPosition); Assert.Equal("EAST", afterTurnRightPosition.Direction.ToString()); }
public void TestRightCommand() { var rover = new Rover(); rover.Stand(new Point(1, 1), Direction.NORTH); var cmd = new RightCommand(rover); Assert.IsTrue(cmd.Validate()); cmd.Execute(); Assert.AreEqual(rover.Position.X, 1); Assert.AreEqual(rover.Position.Y, 1); Assert.AreEqual(rover.Direction, Direction.EAST); }
/// <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); } } }
public void Execute_RobotFacingWest_FacingNorth() { // 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 rightCommand = new RightCommand(); // Act rightCommand.Execute(robot); // Assert Assert.Equal(x, robot.X); Assert.Equal(y, robot.Y); Assert.Equal((int)CompassPoint.North, robot.Heading); Assert.Same(table, robot.Table); }
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); } }
public void visit(RightCommand right) { right.Execute(); }
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(); } }
public void CanNotExecutePlaceCommandWithNullRobot() { //Act & Assert _rightCommand.Execute(null); }