예제 #1
0
        static void Main(string[] args)
        {
            List <Bulb> firstBulbs = new List <Bulb>()
            {
                new GreenBulb(),
                new OrangeBulb(),
                new GreenBulb(),
            };
            TrafficLighter firstTrafficLighter = new TrafficLighter(firstBulbs);

            List <Bulb> secondBulbs = new List <Bulb>()
            {
                new GreenBulb(),
                new OrangeBulb(),
                new GreenBulb(),
            };
            TrafficLighter secondTrafficLighter = new TrafficLighter(secondBulbs);

            RoadIntersection roadIntersection = new RoadIntersection();

            roadIntersection.Subscribe(firstTrafficLighter, "daily", 0);
            roadIntersection.Subscribe(secondTrafficLighter, "daily", 1);
            roadIntersection.Start(30000);

            roadIntersection.ChangeBehaviour("orangePulse");
            roadIntersection.Start();
        }
예제 #2
0
        private void DeleteIntersectionObject(RoadIntersection intersection)
        {
            GameObject intersectionToBeDeleted = _intersectionObjects.Find(intersectionObject => intersectionObject.GetComponent <RoadIntersectionComponent>().RoadIntersection.ID == intersection.ID);

            if (intersectionToBeDeleted)
            {
                _intersectionObjects.Remove(intersectionToBeDeleted);
                Destroy(intersectionToBeDeleted);
            }
        }
예제 #3
0
        public void GetFenceLocationsTest()
        {
            List <Coord> locations = _block.GetFenceLocations().ToList();

            Assert.IsEmpty(locations);

            _nwIntersection = new RoadIntersection(RoadNumbers.Seventh, RoadNames.Guthrow, new List <Coord>()
            {
                new Coord(0, 0),
                new Coord(0, 1),
                new Coord(1, 0),
                new Coord(1, 1),
            });
            _swIntersection = new RoadIntersection(RoadNumbers.Eighth, RoadNames.MatrinLuthorKingJr, new List <Coord>()
            {
                new Coord(3, 40),
                new Coord(3, 41),
                new Coord(4, 40),
                new Coord(4, 41),
            });
            _neIntersection = new RoadIntersection(RoadNumbers.Seventh, RoadNames.Guthrow, new List <Coord>()
            {
                new Coord(55, 0),
                new Coord(55, 1),
                new Coord(56, 0),
                new Coord(56, 1),
            });
            _seIntersection = new RoadIntersection(RoadNumbers.Eighth, RoadNames.MatrinLuthorKingJr, new List <Coord>()
            {
                new Coord(50, 50),
                new Coord(50, 51),
                new Coord(51, 50),
                new Coord(51, 51),
            });

            _block    = new Block(_nwIntersection, _swIntersection, _seIntersection, _neIntersection);
            locations = _block.GetFenceLocations().ToList();
            Assert.IsNotEmpty(locations);

            _swIntersection = new RoadIntersection(RoadNumbers.Eighth, RoadNames.MatrinLuthorKingJr, new List <Coord>()
            {
                new Coord(3, 70),
                new Coord(3, 71),
                new Coord(4, 70),
                new Coord(4, 71),
            });

            _block    = new Block(_nwIntersection, _swIntersection, _seIntersection, _neIntersection);
            locations = _block.GetFenceLocations().ToList();
            Assert.IsNotEmpty(locations);
        }
예제 #4
0
        private void CreateIntersectionObject(RoadIntersection intersection)
        {
            GameObject intersectionObject = Instantiate(roadIntersectionObjectPrefab, roadIntersectionObjectsParent.transform);

            intersectionObject.GetComponent <RoadIntersectionComponent>().RoadIntersection = intersection;

            intersectionObject.transform.position = intersection.Position;

            Vector3 scale = new Vector3(crawlerRoadWidth * 2, intersectionObject.transform.localScale.y, crawlerRoadWidth * 2);

            intersectionObject.transform.localScale = scale;

            _intersectionObjects.Add(intersectionObject);
        }
예제 #5
0
        private void BeginTurn()
        {
            _timeSinceTurnBegan = 0.0f;

            RoadIntersection nextIntersection = _path[_nextIntersectionIndex];

            Vector3 delVector = _path[_nextIntersectionIndex + 1].Position - nextIntersection.Position;

            _p0 = _position;
            _p1 = nextIntersection.Position;
            _p2 = (delVector.normalized * turnRadius) + nextIntersection.Position;

            _turnDuration = CalculateQuadBezierLength(_p0, _p1, _p2) / speed;

            _currentState = State.Turning;
        }
예제 #6
0
        public void SetUp()
        {
            List <Coord> points = new List <Coord>()
            {
                new Coord(1, 1),
                new Coord(1, 2),
                new Coord(2, 1),
                new Coord(2, 2)
            };

            _nwIntersection = new RoadIntersection(RoadNumbers.TwentyFirst, RoadNames.Neumann, points);

            points = new List <Coord>()
            {
                new Coord(5, 2),
                new Coord(6, 2),
                new Coord(5, 3),
                new Coord(6, 3)
            };

            _neIntersection = new RoadIntersection(RoadNumbers.TwentyFirst, RoadNames.Olive, points);


            points = new List <Coord>()
            {
                new Coord(6, 8),
                new Coord(7, 8),
                new Coord(6, 9),
                new Coord(7, 9)
            };

            _seIntersection = new RoadIntersection(RoadNumbers.TwentySecond, RoadNames.Neumann, points);


            points = new List <Coord>()
            {
                new Coord(4, 6),
                new Coord(5, 6),
                new Coord(4, 7),
                new Coord(5, 7)
            };

            _swIntersection = new RoadIntersection(RoadNumbers.TwentySecond, RoadNames.Olive, points);

            _block = new Block(_nwIntersection, _swIntersection, _seIntersection, _neIntersection);
        }
        public void NewRoadIntersectionTest()
        {
            List <Coord> points = new List <Coord>();

            for (int i = 0; i < 15; i++)
            {
                for (int j = 0; j < 25; j++)
                {
                    points.Add(new Coord(i, j));
                }
            }
            RoadIntersection intersection = new RoadIntersection(RoadNumbers.Eighteenth, RoadNames.Anaheim, points);

            Assert.AreEqual(new Coord(0, 0), intersection.NorthWestCorner);
            Assert.AreEqual(new Coord(0, 24), intersection.SouthWestCorner);
            Assert.AreEqual(new Coord(14, 0), intersection.NorthEastCorner);
            Assert.AreEqual(new Coord(14, 24), intersection.SouthEastCorner);
        }
예제 #8
0
        private void MoveStraight()
        {
            RoadIntersection nextIntersection = _path[_nextIntersectionIndex];

            Vector3 newPos = _position = Vector3.MoveTowards(_position, nextIntersection.Position, speed * Time.deltaTime);

            newPos.y           = yLevel;
            transform.position = newPos;

            if (_nextIntersectionIndex + 1 == _path.Count)
            {
                if (transform.position == nextIntersection.Position)
                {
                    // This is the last intersection and we've reached it
                    _currentState = State.Ended;
                }
            }
            else if (Vector3.Distance(_position, nextIntersection.Position) <= turnRadius)
            {
                BeginTurn();
            }
        }
예제 #9
0
        private void UpdateEndPoint(RaycastHit hit)
        {
            switch (hit.collider.tag)
            {
            case "BuildingConnectionCollider":
                _endNodeType = NewNodeType.BuildingConnection;

                // Snap to building connector
                _endNodePosition = hit.collider.transform.parent.position;

                // Store the snapped connector
                BuildingRoadConnectionComponent buildingConnectionComponent = hit.collider.transform.parent.gameObject.GetComponent <BuildingRoadConnectionComponent>();
                _endNodeData = buildingConnectionComponent.RoadConnection;

                break;

            case "RoadIntersectionCollider":
                _endNodeType = NewNodeType.Intersection;

                // Snap to existing intersection
                _endNodePosition = hit.collider.transform.parent.position;

                // Store the snapped node
                RoadIntersectionComponent roadIntersectionComponent = hit.collider.transform.parent.gameObject.GetComponent <RoadIntersectionComponent>();
                _endNodeData = roadIntersectionComponent.RoadIntersection;

                break;

            case "RoadPointCollider":
                _endNodeType = NewNodeType.Point;

                // Snap to road point
                _endNodePosition = hit.collider.transform.parent.position;

                // Store the snapped point
                RoadPointComponent roadPointComponent = hit.collider.transform.parent.gameObject.GetComponent <RoadPointComponent>();
                _endNodeData = roadPointComponent.RoadPoint;

                break;

            case "Floor":
                _endNodeType = NewNodeType.Position;

                // End node will be a new node
                // Do length snapping

                if (lengthSnapping != 0)
                {
                    Vector3 offset = hit.point - _startNodePosition;

                    float newMagnitude = Mathf.Round(offset.magnitude / lengthSnapping) * lengthSnapping;

                    Vector3 newOffset = offset.normalized * newMagnitude;
                    _endNodePosition = _startNodePosition + newOffset;
                }
                else
                {
                    _endNodePosition = hit.point;
                }

                _endNodeData = new RoadPosition(_endNodePosition);

                break;
            }

            Vector3 newRoadEndMarkerPosition = _endNodePosition;

            newRoadEndMarkerPosition.y += 0.05f;

            endNodeMarker.transform.position = newRoadEndMarkerPosition;

            if (Mouse.current.leftButton.wasPressedThisFrame)
            {
                // Don't connect if max connections to this intersection has already been reached
                if (_endNodeType == NewNodeType.Intersection && _roadNetwork.GetConnectionCount(_endNodeData as RoadIntersection) >= (_endNodeData as RoadIntersection).MaxConnections)
                {
                    return;
                }

                // Don't connect if existing intersection requires a certain type of road and we're not drawing that
                if (_endNodeType == NewNodeType.Intersection && (_endNodeData as RoadIntersection).FixedRoadType != RoadType.Any && (_endNodeData as RoadIntersection).FixedRoadType != _roadType)
                {
                    return;
                }

                // Don't connect if building connection requires a certain type of road and we're not drawing that
                if (_endNodeType == NewNodeType.BuildingConnection && (_endNodeData as BuildingRoadConnection).FixedRoadType != RoadType.Any && (_endNodeData as BuildingRoadConnection).FixedRoadType != _roadType)
                {
                    return;
                }

                RoadIntersection lastIntersection = _roadNetwork.CreateRoad(_startNodeData, _endNodeData, _roadType);

                if (lastIntersection != null)
                {
                    // Set start node to newly created
                    _startNodeType     = NewNodeType.Intersection;
                    _startNodeData     = lastIntersection;
                    _startNodePosition = _endNodePosition;

                    startNodeMarker.transform.position = endNodeMarker.transform.position;
                }
                else
                {
                    // TODO: handle road creation failure
                }
            }
        }