Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
0
        public void RotateRobotToLeft()
        {
            /*
             * Should rotate the Robot without moving it
             * 1. Test initial state
             * 2. Place the robot
             * 3. 360 degrees rotation
             */

            //1
            Assert.Throws <ToyRobotHasNotBeenPlacedException>(() => toyRobot.GetCurrentPosition());
            Assert.IsFalse(toyRobot.HasBeenPlaced());

            //2
            var          args         = "0,0,WEST";
            PlaceCommand placeCommand = new PlaceCommand(map, args);

            toyRobot.Execute(placeCommand);

            //3
            LeftCommand leftCommand = new LeftCommand(map, string.Empty);

            toyRobot.Execute(leftCommand);
            Assert.IsTrue(toyRobot.GetCurrentPosition().Item3 == FacesEnum.SOUTH);
            toyRobot.Execute(leftCommand);
            Assert.IsTrue(toyRobot.GetCurrentPosition().Item3 == FacesEnum.EAST);
            toyRobot.Execute(leftCommand);
            Assert.IsTrue(toyRobot.GetCurrentPosition().Item3 == FacesEnum.NORTH);
            toyRobot.Execute(leftCommand);
            Assert.IsTrue(toyRobot.GetCurrentPosition().Item3 == FacesEnum.WEST);
        }
Ejemplo n.º 5
0
        public void Robot_TestMultipleMovement_RobotReportsCorrectLocation()
        {
            Robot          robot     = new Robot();
            Tabletop       table     = new Tabletop(5, 5);
            RobotCommander commander = new RobotCommander();

            PlaceCommand place = new PlaceCommand(robot, table);

            place.Direction = "North";
            MoveCommand  move  = new MoveCommand(robot, table);
            RightCommand right = new RightCommand(robot);
            LeftCommand  left  = new LeftCommand(robot);


            commander.Commands.Enqueue(place);
            commander.Commands.Enqueue(move);
            commander.Commands.Enqueue(move);
            commander.Commands.Enqueue(right);
            commander.Commands.Enqueue(move);
            commander.Commands.Enqueue(left);
            commander.Commands.Enqueue(left);

            commander.ExecuteCommands();

            Assert.Equal(Facing.West, robot.Direction);
            Assert.Equal(2, robot.Position.Y);
            Assert.Equal(1, robot.Position.X);
        }
Ejemplo n.º 6
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.º 7
0
        public Command CreateCommand(char commandChar, Engine engine)
        {
            Command command = null;

            switch (commandChar)
            {
            case 'V':
                command = new DownCommand(engine);
                break;

            case '^':
                command = new UpCommand(engine);
                break;

            case '<':
                command = new LeftCommand(engine);
                break;

            case '>':
                command = new RightCommand(engine);
                break;

            default:
                throw new ArgumentException("Invalid command!");
            }

            return(command);
        }
Ejemplo n.º 8
0
        public IList <ICommand> Build(string robotCommandsInput)
        {
            IList <ICommand> commands = new List <ICommand>();

            foreach (var commandInput in robotCommandsInput.ToCharArray())
            {
                ICommand command;
                switch (commandInput)
                {
                case 'R':
                    command = new RightCommand();
                    break;

                case 'L':
                    command = new LeftCommand();
                    break;

                case 'M':
                    command = new MoveCommand();
                    break;

                default:
                    throw new InvalidRobotCommandException();
                }
                commands.Add(command);
            }
            return(commands);
        }
Ejemplo n.º 9
0
        public void Robot_TestUndoWhenWhenRobotIsStuckAgainstSouthWall_RobotReportsOrignalPosition()
        {
            Robot          robot     = new Robot();
            Tabletop       table     = new Tabletop(5, 5);
            RobotCommander commander = new RobotCommander();

            PlaceCommand place = new PlaceCommand(robot, table);

            place.Direction = "North";
            MoveCommand  move  = new MoveCommand(robot, table);
            RightCommand right = new RightCommand(robot);
            LeftCommand  left  = new LeftCommand(robot);


            commander.Commands.Enqueue(place);
            commander.Commands.Enqueue(right);
            commander.Commands.Enqueue(right);
            commander.Commands.Enqueue(move);

            commander.ExecuteCommands();
            commander.UndoCommands(1);

            Assert.Equal(0, robot.Position.Y);
            Assert.Equal(0, robot.Position.X);
        }
Ejemplo n.º 10
0
        public string Operation()
        {
            var areaResult = new AreaResult(_Direction, _Coordinate);

            foreach (var command in _Commands)
            {
                Command.Base.Command cmd;
                switch (command)
                {
                case 'L':
                    cmd = new LeftCommand(areaResult.Direction, areaResult.Coordinate);
                    break;

                case 'R':
                    cmd = new RightCommand(areaResult.Direction, areaResult.Coordinate);
                    break;

                case 'M':
                    cmd = new MoveCommand(areaResult.Direction, areaResult.Coordinate);
                    break;

                default: throw new ArgumentException($"Invalid command parameter {command}");
                }
                areaResult = cmd.Execute();
                if (!_GridArea.ValidPosition(areaResult.Coordinate))
                {
                    throw new ArgumentOutOfRangeException($"Coordinate unknow {areaResult.Coordinate}");
                }
            }
            return(areaResult.ToString());
        }
Ejemplo n.º 11
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.º 12
0
 public void Setup()
 {
     _leftCommand = new LeftCommand();
     _robot       = new Robot(X, Y)
     {
         CurrentPosition = new Position(X, Y, Facing.N)
     };
 }
Ejemplo n.º 13
0
        private static IMovementService GetMovementService()
        {
            var leftCommand  = new LeftCommand();
            var rightCommand = new RightCommand();
            var moveCommand  = new MoveCommand();

            return(new MovementService(leftCommand, rightCommand, moveCommand));
        }
Ejemplo n.º 14
0
        public async Task ShouldFailValidationRobotNotOnTheTableTest()
        {
            var   leftCommand = new LeftCommand();
            Robot robot       = new Robot(Table.GetTableInstance());

            var result = await leftCommand.Excute(robot);

            result.ShouldBe(false);
        }
Ejemplo n.º 15
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.º 16
0
        public void Setup()
        {
            _command = new LeftCommand();

            _gridMock = new Mock <IGrid>();
            _gridMock.Setup(x => x.Width).Returns(5);
            _gridMock.Setup(x => x.Height).Returns(5);

            _robot = Robot.Construct("3 3 N", _gridMock.Object);
        }
Ejemplo n.º 17
0
        public void CheckNotPlaced()
        {
            var command = new LeftCommand();
            var robot   = new Robot()
            {
                Placed = false
            };

            Assert.False(Program.CheckValidCommand(command, robot));
        }
Ejemplo n.º 18
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.º 19
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.º 20
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);
        }
    void Start()
    {
        ICommand up    = new UpCommand();
        ICommand down  = new DownCommand();
        ICommand left  = new LeftCommand();
        ICommand right = new RightCommand();

        dict.Add(KeyCode.W, up);
        dict.Add(KeyCode.S, down);
        dict.Add(KeyCode.A, left);
        dict.Add(KeyCode.D, right);
    }
Ejemplo n.º 22
0
        public async Task ShouldSucceedTest(Direction from, Direction expected)
        {
            var   leftCommand = new LeftCommand();
            Robot robot       = new Robot(Table.GetTableInstance());

            robot.SetPositionOnTable(new Position(0, 0, from));

            var result = await leftCommand.Excute(robot);

            result.ShouldBe(true);
            robot.Direction.ShouldBe(expected);
        }
Ejemplo n.º 23
0
 private void Start()
 {
     rightCom       = new RightCommand();
     leftCom        = new LeftCommand();
     attackCom      = new AttackCommand();
     jumpCom        = new JumpCommand();
     crouchCom      = new CrouchCommand();
     idleCom        = new IdleCommand();
     specialCom     = new SpecialCommand();
     altSpecialCom  = new AltSpecialCommand();
     mindControlCom = new MindControlCommand();
 }
    void Start()
    {
        ICommand up    = new UpCommand();
        ICommand down  = new DownCommand();
        ICommand left  = new LeftCommand();
        ICommand right = new RightCommand();

        dict.Add(KeyCode.UpArrow, up);
        dict.Add(KeyCode.DownArrow, down);
        dict.Add(KeyCode.LeftArrow, left);
        dict.Add(KeyCode.RightArrow, right);
    }
Ejemplo n.º 25
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.º 27
0
        public void ShouldParseCommand(string commandline, bool shouldParse)
        {
            var command = LeftCommand.Parse(commandline);

            if (shouldParse)
            {
                Assert.NotNull(command);
            }
            else
            {
                Assert.Null(command);
            }
        }
Ejemplo n.º 28
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.º 29
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.º 30
0
        /// <summary>
        /// Makes from a string and value a command
        /// </summary>
        /// <param name="command"></param>
        /// <param name="value"></param>
        /// <returns>Command</returns>
        public IDroneCommand makeCommand(string command, double value = 0)
        {
            IDroneCommand droneCommand = null;

            if (command.Equals("Start"))
            {
                droneCommand = new StartCommand(_droneController);
            }
            else if (command.Equals("Land"))
            {
                droneCommand = new LandCommand(_droneController);
            }
            else if (command.Equals("Rise"))
            {
                droneCommand = new RiseCommand(_droneController, value);
            }
            else if (command.Equals("Fall"))
            {
                droneCommand = new FallCommand(_droneController, value);
            }
            else if (command.Equals("Right"))
            {
                droneCommand = new RightCommand(_droneController, value);
            }
            else if (command.Equals("Left"))
            {
                droneCommand = new LeftCommand(_droneController, value);
            }
            else if (command.Equals("Forward"))
            {
                droneCommand = new ForwardCommand(_droneController, value);
            }
            else if (command.Equals("Backward"))
            {
                droneCommand = new BackwardCommand(_droneController, value);
            }
            else if (command.Equals("Turn"))
            {
                droneCommand = new TurnCommand(_droneController, (int)value);
            }
            else if (command.Equals("TakePicture"))
            {
                droneCommand = new TakePictureCommand(_droneController, (int)value);
            }
            else if (command.Equals("FollowLine"))
            {
                droneCommand = new FollowLineCommand(_droneController);
            }

            return(droneCommand);
        }