Exemplo n.º 1
0
        public void Move(MovementDirectionEnum movementDirection)
        {   //BAT
            //Define Behavior
            System.Windows.Point    batLocation             = _imageManager.GetImageLocation(EnemyImage);
            BehaviorPropertiesModel behaviorPropertiesModel = new BehaviorPropertiesModel()
            {
                EnemyName         = EnemyName,
                MovementDirection = movementDirection,
                Target            = _playerLocationPoint,
                Chaser            = batLocation,
            };

            var behavioralDirection = _selectedBehavior.ApplyBehavior(behaviorPropertiesModel);
            //Confirm Castle Wall Boundaries reached
            var _imageObjectShapeModel        = _castle.GetCanvasLocationAndDimensionsOuterLimits();
            var castleSideWallBoundaryReached = _imageManager.ImageIsBeyondBoundaries_Adaptor(_imageObjectShapeModel, EnemyImage);

            var selectedMovementDirection = (castleSideWallBoundaryReached == MovementDirectionEnum.MovementClear_NoBoundariesReached)
                                            ? behavioralDirection
                                            :_movementDirectionManager.GetOppositeDirection(castleSideWallBoundaryReached);

            //Set Movement
            MovementDirection = selectedMovementDirection;
            //Process Movement
            System.Drawing.Point newLocationPoint      = _movementStrategy.GetMovement(MovementDirection);
            System.Drawing.Point newSpeedLocationPoint = _imageManager.ModifyLocationPointValues(newLocationPoint, _speedMovement);
            _imageManager.SetNewLocationImage(EnemyImage, newSpeedLocationPoint);
        }
Exemplo n.º 2
0
        public KeyboardActionProcessorModel Execute(KeyEventArgs e, IPlayer player = null, List <Image> weaponImages = null, List <Image> potionImages = null)
        {
            MovementDirectionEnum selectedMovement = MovementDirectionEnum.NotMoving;

            switch (e.Key)
            {
            case Key.Left:
                selectedMovement = MovementDirectionEnum.MovingLeft;
                break;

            case Key.Right:
                selectedMovement = MovementDirectionEnum.MovingRight;
                break;

            case Key.Up:
                selectedMovement = MovementDirectionEnum.MovingUp;
                break;

            case Key.Down:
                selectedMovement = MovementDirectionEnum.MovingDown;
                break;
            }

            return(new KeyboardActionProcessorModel
            {
                PlayerRelatedAction = PlayerRelatedActionsEnum.Movement,
                ActionExecuted = new List <Enum>()
                {
                    selectedMovement
                },
            });
        }
Exemplo n.º 3
0
        public MovementDirectionEnum GetOppositeMovement(MovementDirectionEnum direction)
        {
            switch (direction)
            {
            case MovementDirectionEnum.Down:
                return(MovementDirectionEnum.Up);

            case MovementDirectionEnum.Up:
                return(MovementDirectionEnum.Down);

            case MovementDirectionEnum.Left:
                return(MovementDirectionEnum.Right);

            case MovementDirectionEnum.Right:
                return(MovementDirectionEnum.Left);

            case MovementDirectionEnum.DiagonalLeftDown:
                return(MovementDirectionEnum.DiagonalRightUp);

            case MovementDirectionEnum.DiagonalLeftUp:
                return(MovementDirectionEnum.DiagonalRightDown);

            case MovementDirectionEnum.DiagonalRightUp:
                return(MovementDirectionEnum.DiagonalLeftDown);

            case MovementDirectionEnum.DiagonalRightDown:
                return(MovementDirectionEnum.DiagonalLeftUp);
            }
            return(MovementDirectionEnum.Static);
        }
Exemplo n.º 4
0
        public Point GetMovement(MovementDirectionEnum movementDirectionEnum)
        {
            switch (movementDirectionEnum)
            {
            case MovementDirectionEnum.NotMoving:
                newLocation.X = 0;
                newLocation.Y = 0;
                break;

            case MovementDirectionEnum.MovingLeft:
                newLocation.X = defaultDistance * -1;
                newLocation.Y = 0;
                break;

            case MovementDirectionEnum.MovingRight:
                newLocation.X = defaultDistance;
                newLocation.Y = 0;
                break;

            case MovementDirectionEnum.MovingUp:
                newLocation.X = 0;
                newLocation.Y = defaultDistance * -1;
                break;

            case MovementDirectionEnum.MovingDown:
                newLocation.X = 0;
                newLocation.Y = defaultDistance;
                break;

            default: break;
            }
            return(newLocation);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Turns robot right
        /// </summary>
        public void GoRight()
        {
            if (_currentDirection == MovementDirectionEnum.Right)
            {
                return;
            }

            if (MovementType == MovementTypeEnum.ModifiedServo)
            {
                _ezb.Servo.SetServoPosition(ServoWheelRightModifiedPort, ModifiedServoRightReverseValue);
                _ezb.Servo.SetServoPosition(ServoWheelLeftModifiedPort, ModifiedServoLeftForwardValue);
            }
            else if (MovementType == MovementTypeEnum.HBridge)
            {
                _ezb.Digital.SetDigitalPort(HBridgeLeftWheelTriggerA, true);
                _ezb.Digital.SetDigitalPort(HBridgeLeftWheelTriggerB, false);

                _ezb.Digital.SetDigitalPort(HBridgeRightWheelTriggerA, false);
                _ezb.Digital.SetDigitalPort(HBridgeRightWheelTriggerB, true);
            }
            else if (MovementType == MovementTypeEnum.HBridgePWM)
            {
                _ezb.Digital.SetDigitalPort(HBridgeLeftWheelTriggerA, true);
                _ezb.Digital.SetDigitalPort(HBridgeLeftWheelTriggerB, false);

                _ezb.Digital.SetDigitalPort(HBridgeRightWheelTriggerA, false);
                _ezb.Digital.SetDigitalPort(HBridgeRightWheelTriggerB, true);
            }
            else if (MovementType == MovementTypeEnum.Roomba)
            {
                _ezb.Roomba.Right(_speedLeft);
            }
            else if (MovementType == MovementTypeEnum.BV4113)
            {
                _ezb.BV4113.Right();
            }
            else if (MovementType == MovementTypeEnum.ARDrone)
            {
                _ezb.Log(true, "AR Drone Movement is not supported in Mobile");
            }
            else if (MovementType == MovementTypeEnum.BrookstoneRover)
            {
                _ezb.Log(true, "Brookstone Rover is not supported in Mobile");
            }
            else if (MovementType == MovementTypeEnum.Sabertooth)
            {
                _ezb.SabertoothSerial.Right();
            }
            else if (MovementType == MovementTypeEnum.MIP)
            {
                _ezb.MIP.Right(_speedLeft);
            }

            _currentDirection = MovementDirectionEnum.Right;

            if (OnMovement != null)
            {
                OnMovement(_currentDirection);
            }
        }
Exemplo n.º 6
0
        public MovementDirectionEnum GetNonRepeatingRandomDirection(MovementDirectionEnum movement)
        {
            List <MovementDirectionEnum> allMovements = Enum.GetValues(typeof(MovementDirectionEnum)).Cast <MovementDirectionEnum>().ToList();

            allMovements.Remove(movement);
            var index            = random.Next(lowerLimit, (allMovements.Count - 1));
            var selectedMovement = allMovements[index];

            return(selectedMovement);
        }
Exemplo n.º 7
0
        public static List <short> DecompressTeleportCells(MapCell[] cells, MovementDirectionEnum dir)
        {
            var cellsTeleport = new List <short>();

            cells.Where(c => c.IsTeleportCell).ToList().ForEach(cell =>
            {
                cellsTeleport.AddTeleportCell(cell.Id, dir);
            });
            return(cellsTeleport);
        }
Exemplo n.º 8
0
        private void ProcessPlayerMovement(MovementDirectionEnum movementDirection)
        {
            Point movement = _movementStrategy.GetMovement(movementDirection);
            Point playerNewLocationPoint = _imageManager.ModifyLocationPointValues(movement, _speedMovement);

            _imageManager.SetNewLocationImage(ShooterImage, playerNewLocationPoint);
            var weaponsCarriedByPlayer = GetWeapons();

            if (weaponsCarriedByPlayer.Count > 0)
            {
                PlayerCarriesAWeapon_SetWeaponMovement_NotifyObservers(playerNewLocationPoint, weaponsCarriedByPlayer);
            }
        }
Exemplo n.º 9
0
        public Point GetNewLinearMovementPoint(MovementDirectionEnum movementDirection)
        {
            switch (movementDirection)
            {
            case MovementDirectionEnum.Down:
                locationPoint.X = 0;
                locationPoint.Y = +1;
                return(locationPoint);

            case MovementDirectionEnum.Up:
                locationPoint.X = 0;
                locationPoint.Y = -1;
                return(locationPoint);

            case MovementDirectionEnum.Left:
                locationPoint.X = -1;
                locationPoint.Y = 0;
                return(locationPoint);

            case MovementDirectionEnum.Right:
                locationPoint.X = +1;
                locationPoint.Y = 0;
                return(locationPoint);

            case MovementDirectionEnum.DiagonalLeftUp:
                locationPoint.X = -1;
                locationPoint.Y = -1;
                return(locationPoint);

            case MovementDirectionEnum.DiagonalRightUp:
                locationPoint.X = +1;
                locationPoint.Y = -1;
                return(locationPoint);

            case MovementDirectionEnum.DiagonalRightDown:
                locationPoint.X = +1;
                locationPoint.Y = +1;
                return(locationPoint);

            case MovementDirectionEnum.DiagonalLeftDown:
                locationPoint.X = -1;
                locationPoint.Y = +1;
                return(locationPoint);

            case MovementDirectionEnum.Static:
                locationPoint.X = 0;
                locationPoint.Y = 0;
                return(locationPoint);
            }
            return(locationPoint);
        }
Exemplo n.º 10
0
        public void PlayerMove(MovementDirectionEnum movementDirection)
        {
            //HERO
            //Define Behavior

            //Confirm Castle Wall Boundaries reached
            var castleInnerLimits = _castle.GetCanvasLocationAndDimensionsInnerLimits();
            MovementDirectionEnum castleWallReachedByPlayer = _imageManager.ImageIsBeyondBoundaries_Adaptor(castleInnerLimits, ShooterImage);
            //Process Movement
            var selectedMovement = (castleWallReachedByPlayer != MovementDirectionEnum.MovementClear_NoBoundariesReached)
                                   ? _movementDirectionManager.GetOppositeDirection(castleWallReachedByPlayer)
                                   : movementDirection;

            ProcessPlayerMovement(selectedMovement);
        }
Exemplo n.º 11
0
        public MovementDirectionEnum GetOppositeDirection(MovementDirectionEnum movementDirection)
        {
            switch (movementDirection)
            {
            case MovementDirectionEnum.MovingDown:
                return(MovementDirectionEnum.MovingUp);

            case MovementDirectionEnum.MovingUp:
                return(MovementDirectionEnum.MovingDown);

            case MovementDirectionEnum.MovingLeft:
                return(MovementDirectionEnum.MovingRight);

            case MovementDirectionEnum.MovingRight:
                return(MovementDirectionEnum.MovingLeft);
            }
            return(MovementDirectionEnum.NotMoving);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Robot Rolls Left (Drone flying robots)
        /// </summary>
        public void GoRollLeft()
        {
            if (_currentDirection == MovementDirectionEnum.RollLeft)
            {
                return;
            }

            if (MovementType == MovementTypeEnum.ARDrone)
            {
                _ezb.Log(true, "AR Drone Movement is not supported in Mobile");
            }

            _currentDirection = MovementDirectionEnum.RollLeft;

            if (OnMovement != null)
            {
                OnMovement(_currentDirection);
            }
        }
Exemplo n.º 13
0
 public static List <short> GetTeleportCells(this Map map, MovementDirectionEnum dir)
 {
     if (dir == MovementDirectionEnum.TOP)
     {
         return(map.CurrentMap.TopCellsTeleport);
     }
     else if (dir == MovementDirectionEnum.RIGHT)
     {
         return(map.CurrentMap.RightCellsTeleport);
     }
     else if (dir == MovementDirectionEnum.BOTTOM)
     {
         return(map.CurrentMap.BottomCellsTeleport);
     }
     else if (dir == MovementDirectionEnum.LEFT)
     {
         return(map.CurrentMap.LeftCellsTeleport);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 14
0
        public MovementDirectionEnum ApplyBehavior(BehaviorPropertiesModel behaviorPropertiesModel)
        {
            var enemyFound = behaviorEnemies.Where(a => a.EnemyName == behaviorPropertiesModel.EnemyName).FirstOrDefault();

            if (enemyFound == null)
            {
                var enemyNewInfo = new BehaviorEnemyInfoModel()
                {
                    EnemyName            = behaviorPropertiesModel.EnemyName,
                    ConsecutiveMovements = GetNonRepeatingRandomConsecutiveMovements(),
                    IterationCounter     = 0,
                };

                behaviorEnemies.Add(enemyNewInfo);
            }
            MovementDirectionEnum movementDirection = MovementDirectionEnum.NotMoving;

            foreach (var singleEnemy in behaviorEnemies)
            {
                if (singleEnemy.EnemyName == behaviorPropertiesModel.EnemyName)
                {
                    singleEnemy.IterationCounter++;
                    movementDirection = (behaviorPropertiesModel.MovementDirection.HasValue)
                                                      ? (MovementDirectionEnum)behaviorPropertiesModel.MovementDirection
                                                      : MovementDirectionEnum.NotMoving;

                    if (singleEnemy.ConsecutiveMovements == singleEnemy.IterationCounter)
                    {
                        movementDirection = _movementDirectionManager.GetNonRepeatingRandomDirection(movementDirection);
                        singleEnemy.ConsecutiveMovements = GetNonRepeatingRandomConsecutiveMovements();
                        singleEnemy.IterationCounter     = 0;
                    }
                }
            }
            return(movementDirection);
        }
Exemplo n.º 15
0
        public static List <short> AddTeleportCell(this List <short> cells, short cellId, MovementDirectionEnum dir)
        {
            short[] topCells    = new short[] { 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 36 };
            short[] rightCells  = new short[] { 28, 57, 86, 115, 144, 173, 231, 202, 260, 289, 318, 347, 376, 405, 434 };
            short[] bottomCells = new short[] { 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463 };
            short[] leftCells   = new short[] { 15, 44, 73, 102, 131, 160, 189, 218, 247, 276, 305, 334, 363, 392, 421, 450 };

            if (dir == MovementDirectionEnum.TOP && topCells.Contains(cellId))
            {
                cells.Add(cellId);
            }
            else if (dir == MovementDirectionEnum.RIGHT && rightCells.Contains(cellId))
            {
                cells.Add(cellId);
            }
            else if (dir == MovementDirectionEnum.BOTTOM && bottomCells.Contains(cellId))
            {
                cells.Add(cellId);
            }
            else if (dir == MovementDirectionEnum.LEFT && leftCells.Contains(cellId))
            {
                cells.Add(cellId);
            }
            return(cells);
        }
Exemplo n.º 16
0
        public Point GetMovement(MovementDirectionEnum movementDirection)
        {
            var randomDistance = random.Next(1, _maximumDistance);

            //if LEFT OR RIGHT MOVEMENT then zig zag is up and down
            //                          *                       *
            //                    *                         *
            //<<<<<<<<<---------------------------------------------------------------->>>>>
            //           *       *           *          *
            //      *
            //

            if (movementDirection == MovementDirectionEnum.MovingRight)
            {
                var movementToTheRight = _standardMovement * 1;
                newLocation = Process_ZigZag_UpAndDown(movementToTheRight, randomDistance);
            }

            if (movementDirection == MovementDirectionEnum.MovingLeft)
            {
                var movementToTheLeft = _standardMovement * -1;
                newLocation = Process_ZigZag_UpAndDown(movementToTheLeft, randomDistance);
            }

            // if UP OR DOWN MOVEMENT then zig zag left and right,
            //        |       *
            //     *  |
            //        |   *
            //     *  |
            // *      |
            //   *    |
            //        |   *
            //        |        *
            //        |    *
            if (movementDirection == MovementDirectionEnum.MovingUp)
            {
                var movementUp = _standardMovement * (-1);
                newLocation = Process_ZigZag_LeftAndRight(movementUp, randomDistance);
            }

            if (movementDirection == MovementDirectionEnum.MovingDown)
            {
                var movementDown = _standardMovement * (1);
                newLocation = Process_ZigZag_LeftAndRight(movementDown, randomDistance);
            }
            if (movementDirection == MovementDirectionEnum.MovingDiagonal)
            {
                //We keep things as they originally are and we do not re-set the stored previous
                //direction so if the image is constantly moving in a previously setup direction
                //when moving diagonally will keep its movement angle
                int variationX = 0, variationY = 0;
                newLocation.X = newLocation.X + variationX;
                newLocation.Y = newLocation.Y + variationY;
            }
            if (movementDirection == MovementDirectionEnum.NotMoving)
            {
                //The image will keep static with not movement at all.
                newLocation.X = 0;
                newLocation.Y = 0;
            }

            return(newLocation);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Stops the robot if moving
        /// </summary>
        public void GoStop()
        {
            if (_currentDirection == MovementDirectionEnum.Stop && _movementType != MovementTypeEnum.AutoPosition)
            {
                return;
            }

            if (MovementType == MovementTypeEnum.ModifiedServo)
            {
                if (ModifiedServoUseStopValue)
                {
                    _ezb.Servo.SetServoPosition(ServoWheelRightModifiedPort, ModifiedServoRightStopValue);
                    _ezb.Servo.SetServoPosition(ServoWheelLeftModifiedPort, ModifiedServoLeftStopValue);
                }
                else
                {
                    _ezb.Servo.ReleaseServo(ServoWheelRightModifiedPort);
                    _ezb.Servo.ReleaseServo(ServoWheelLeftModifiedPort);
                }
            }
            else if (MovementType == MovementTypeEnum.HBridge)
            {
                _ezb.Digital.SetDigitalPort(HBridgeLeftWheelTriggerA, false);
                _ezb.Digital.SetDigitalPort(HBridgeLeftWheelTriggerB, false);

                _ezb.Digital.SetDigitalPort(HBridgeRightWheelTriggerA, false);
                _ezb.Digital.SetDigitalPort(HBridgeRightWheelTriggerB, false);
            }
            else if (MovementType == MovementTypeEnum.HBridgePWM)
            {
                _ezb.Digital.SetDigitalPort(HBridgeLeftWheelTriggerA, false);
                _ezb.Digital.SetDigitalPort(HBridgeLeftWheelTriggerB, false);

                _ezb.Digital.SetDigitalPort(HBridgeRightWheelTriggerA, false);
                _ezb.Digital.SetDigitalPort(HBridgeRightWheelTriggerB, false);
            }
            else if (MovementType == MovementTypeEnum.Roomba)
            {
                _ezb.Roomba.Stop();
            }
            else if (MovementType == MovementTypeEnum.BV4113)
            {
                _ezb.BV4113.Stop();
            }
            else if (MovementType == MovementTypeEnum.ARDrone)
            {
                _ezb.Log(true, "AR Drone Movement is not supported in Mobile");
            }
            else if (MovementType == MovementTypeEnum.BrookstoneRover)
            {
                _ezb.Log(true, "Brookstone Rover is not supported in Mobile");
            }
            else if (MovementType == MovementTypeEnum.Sabertooth)
            {
                _ezb.SabertoothSerial.Stop();
            }
            else if (MovementType == MovementTypeEnum.MIP)
            {
                _ezb.MIP.Stop();
            }

            _currentDirection = MovementDirectionEnum.Stop;

            if (OnMovement != null)
            {
                OnMovement(_currentDirection);
            }
        }
Exemplo n.º 18
0
 public MovementDirectionEnum GetSelectedMovement(BeeEnvironmentBehaviorEnum selectedBehavior, Point? hunterLocationPoint = null, Point? targetLocationPoint = null)
 {
     IBehaviorCommand behaviorCommand = _movementBehaviorCommandInvoker.GetSelectedBehavioralMovement(selectedBehavior);
     MovementDirectionEnum selectedMovement = behaviorCommand.Execute(hunterLocationPoint, targetLocationPoint);
     return selectedMovement;
 }