Esempio n. 1
0
        public void Test_WhenRobotIsFacingWestAndInstructedToTurnRight_ItShouldFaceNorthDirection()
        {
            //arrange
            IDirectionChanger directionChanger  = new DirectionChanger();
            Direction         expectedDirection = Direction.North;

            //act
            Direction resultDirection = directionChanger.GetDirection(Direction.West, Rotation.Clockwise);

            //assert
            Assert.AreEqual(resultDirection, expectedDirection);
        }
Esempio n. 2
0
        public void Test_WhenRobotIsFacingSouthAndInstructedToTurnLeft_ItShouldFaceEastDirection()
        {
            //arrange
            IDirectionChanger directionChanger  = new DirectionChanger();
            Direction         expectedDirection = Direction.East;

            //act
            Direction resultDirection = directionChanger.GetDirection(Direction.South, Rotation.Anticlockwise);

            //assert
            Assert.AreEqual(resultDirection, expectedDirection);
        }
Esempio n. 3
0
    public void ScrambleDirections()
    {
        for (int i = 0; i < _legalPositions.Length; ++i)
        {
            if (_legalPositions[i].CurrentDirectionChanger == null)
            {
                Vector3          spawnLocation    = new Vector3(_legalPositions[i].x, _legalPositions[i].y, 0);
                GameObject       obj              = GameObject.Instantiate(_directionChangerPrefab, spawnLocation, Quaternion.identity);
                DirectionChanger directionChanger = obj.GetComponent <DirectionChanger>();
                _legalPositions[i].CurrentDirectionChanger = directionChanger;
            }

            _legalPositions[i].CurrentDirectionChanger.NewDirection = RandomHeading();
        }
    }
Esempio n. 4
0
    public void OnEndDrag(PointerEventData eventData)
    {
        if (_newDirectionManager.CanPlaceNewDirections())
        {
            Vector3 spawnLocation = Camera.main.ScreenToWorldPoint(eventData.position);
            NewDirectionManager.LegalPosition positionToTest;
            positionToTest.x = Mathf.FloorToInt(spawnLocation.x + 0.5f);
            positionToTest.y = Mathf.FloorToInt(spawnLocation.y + 0.5f);

            int positionIndex = Array.FindIndex(_newDirectionManager.LegalPositions, p => p.x == positionToTest.x && p.y == positionToTest.y);
            if (positionIndex != -1)
            {
                DirectionChanger directionChanger = null;

                if (_newDirectionManager.LegalPositions[positionIndex].CurrentDirectionChanger != null)
                {
                    directionChanger = _newDirectionManager.LegalPositions[positionIndex].CurrentDirectionChanger;
                }
                else
                {
                    spawnLocation.x = positionToTest.x;
                    spawnLocation.y = positionToTest.y;
                    spawnLocation.z = 0;

                    GameObject obj = GameObject.Instantiate(_directionChangerPrefab, spawnLocation, Quaternion.identity);
                    directionChanger = obj.GetComponent <DirectionChanger>();

                    _newDirectionManager.LegalPositions[positionIndex].CurrentDirectionChanger = directionChanger;
                }

                if (directionChanger != null)
                {
                    directionChanger.NewDirection = _heading;
                }

                _newDirectionManager.HasBeenPlaced(gameObject);
                _isBeingDragged = false;
            }
            else
            {
                transform.position = _startPos;
            }
        }
    }
Esempio n. 5
0
    private void OnTriggerStay2D(Collider2D other)
    {
        if (_paused)
        {
            return;
        }

        if (_nextDirectionChanger == other.gameObject)
        {
            DirectionChanger       directionChanger       = other.gameObject.GetComponent <DirectionChanger>();
            TwoWayDirectionChanger twoWayDirectionChanger = other.gameObject.GetComponent <TwoWayDirectionChanger>();
            bool    changingDirection = false;
            Heading newHeading        = Heading.Max;

            if (directionChanger != null && directionChanger.IsFromDirection(_heading))
            {
                changingDirection = true;
                newHeading        = directionChanger.NewDirection;
            }
            else if (twoWayDirectionChanger != null)
            {
                changingDirection = true;
                newHeading        = twoWayDirectionChanger.GetOtherDirection(_heading);
            }

            if (changingDirection)
            {
                float dist = Vector3.Distance(other.transform.position, transform.position);
                if (dist < Delta || dist > _prevDist)
                {
                    _heading           = newHeading;
                    transform.position = other.transform.position;
                    dist = 0;
                    _nextDirectionChanger = null;
                }
                _prevDist = dist;

                transform.rotation = Quaternion.Lerp(_heading.ToQuaternion(), newHeading.ToQuaternion(), 1 - dist);
            }
        }
    }