Example #1
0
        public ToyRobotDetailViewModel Execute(int axisX, int axisY, int[,] MatrixRobot, FacingOrientation currentOrientation)
        {
            var indexDirection = (int)currentOrientation;

            indexDirection = indexDirection - 1;

            if (indexDirection < 0)
            {
                indexDirection = System.Enum.GetValues(typeof(FacingOrientation)).Cast <int>().Max();
            }
            FacingOrientation newDirection = (FacingOrientation)indexDirection;

            return(new ToyRobotDetailViewModel
            {
                AxisX = axisX,
                AxisY = axisY,
                Facing = newDirection.ToString()
            });
        }
Example #2
0
        public ToyRobotDetailViewModel Execute(int axisX, int axisY, int[,] MatrixRobot, FacingOrientation currentOrientation)
        {
            int indexToMove = 1;
            var newDirection = currentOrientation;
            int currentRow = axisY, currentColumn = axisX;

            if (currentOrientation == FacingOrientation.WEST ||
                currentOrientation == FacingOrientation.SOUTH)
            {
                indexToMove = -1;
            }

            //north and south --> move between rows
            if (newDirection == FacingOrientation.NORTH ||
                newDirection == FacingOrientation.SOUTH)
            {
                currentRow = axisY + indexToMove;
            }
            else
            {
                //west and east --> move between columns
                currentColumn = axisX + indexToMove;
            }

            return(new ToyRobotDetailViewModel
            {
                AxisX = currentColumn,
                AxisY = currentRow,
                Facing = newDirection.ToString()
            });
        }
Example #3
0
        private ToyRobotDetailViewModel GenerateMovement(int[,] matrixRobot,
                                                         int currentRow,
                                                         int currentColumn,
                                                         FacingOrientation currentfacing,
                                                         FacingDirection facingDirection)
        {
            int indexToMove    = 1;
            var newDirection   = currentfacing;
            int indexDirection = 0;

            switch (facingDirection)
            {
            //case FacingDirection.Move:

            //    break;
            case FacingDirection.LEFT:
                indexDirection = (int)Currentfacing;
                indexDirection = indexDirection - 1;
                if (indexDirection < 0)
                {
                    indexDirection = System.Enum.GetValues(typeof(FacingOrientation)).Cast <int>().Max();
                }

                newDirection = (FacingOrientation)indexDirection;
                break;

            case FacingDirection.RIGHT:

                var maxEnum = System.Enum.GetValues(typeof(FacingOrientation)).Cast <int>().Max();

                indexDirection = (int)Currentfacing;
                indexDirection = indexDirection + 1;
                if (indexDirection > maxEnum)
                {
                    indexDirection = 0;
                }

                newDirection = (FacingOrientation)indexDirection;
                break;

            default:

                if (Currentfacing == FacingOrientation.WEST ||
                    Currentfacing == FacingOrientation.SOUTH)
                {
                    indexToMove = -1;
                }

                //north and south --> move between rows
                if (newDirection == FacingOrientation.NORTH ||
                    newDirection == FacingOrientation.SOUTH)
                {
                    currentRow = currentRow + indexToMove;
                }
                else
                {
                    //west and east --> move between columns
                    currentColumn = currentColumn + indexToMove;
                }

                break;
            }



            //TODO validate correct position

            return(new ToyRobotDetailViewModel
            {
                AxisX = currentColumn,
                AxisY = currentRow,
                Facing = newDirection.ToString()
            });
        }
 void Start()
 {
     currentFacingOrientation = FacingOrientation.FACING_RIGHT;
 }
Example #5
0
        public ToyRobotDetailViewModel Execute(int axisX, int axisY, int[,] MatrixRobot, FacingOrientation currentOrientation)
        {
            var firtCommandCoord = CommandNameRecieved.Split((new char[] { ',' }));

            if (!validation.ValidNumber(firtCommandCoord[0]))
            {
                throw new Exception(validation.Errors);
            }
            if (!validation.ValidNumber(firtCommandCoord[1]))
            {
                throw new Exception(validation.Errors);
            }

            if (!validation.ValidPosition(Convert.ToInt32(firtCommandCoord[0]), Convert.ToInt32(firtCommandCoord[1]), MatrixRobot))
            {
                throw new Exception(validation.Errors);
            }


            return(new ToyRobotDetailViewModel
            {
                Facing = firtCommandCoord[2].ToString(),
                AxisX = Convert.ToInt32(firtCommandCoord[0]),
                AxisY = Convert.ToInt32(firtCommandCoord[1])
            });
        }
Example #6
0
        private void Awake()
        {
            this.WarnIfMultipleInstances();

            _transform = this.transform;
            _facingOrientation = new FacingOrientation
            {
                priority = this.turnRequestPriority,
                turnSpeed = this.turnSpeed
            };

            //Get the speed source
            _speedSource = this.As<IDefineSpeed>();
            if (_speedSource == null)
            {
                Debug.LogError("A speed source component is required to steer.");
                this.enabled = false;
            }

            //Resolve the mover
            _mover = this.As<IMoveUnits>();
            if (_mover == null)
            {
                var fact = this.As<IMoveUnitsFactory>();
                var charController = this.GetComponent<CharacterController>();
                if (fact != null)
                {
                    _mover = fact.Create();
                }
                else if (charController != null)
                {
                    _mover = new CharacterControllerMover(charController);
                }
                else if (this.rigidbody != null)
                {
                    _mover = new RigidBodyMover(_transform, this.rigidbody);
                }
                else
                {
                    _mover = new DefaultMover(_transform);
                }
            }

            _unit = this.GetComponent<UnitComponent>();
            _steeringComponents = new List<SteeringComponent>();
            _minimumSpeedToTurnSquared = this.minimumSpeedToTurn * this.minimumSpeedToTurn;
            _stopped = true;
        }