예제 #1
0
    public void EnterRoad(RoadId roadId)
    {
        if (_roadMovementComponent != null)
        {
            throw new InvalidOperationException($"Player {_playerId} is already at road {_roadMovementComponent.Road.RoadId}.");
        }

        var road = _roadStore.Find(roadId);

        if (road == null)
        {
            throw new InvalidOperationException($"Road {roadId} does not exist.");
        }

        var location = _locationStore.Find(_locationId);

        if (location == null)
        {
            throw new InvalidOperationException($"Current location {_locationId} does not exist.");
        }

        // Check that current location allows movement to this road.
        if (!location.Roads.Contains(roadId))
        {
            throw new InvalidOperationException($"Cannot move to road {roadId} from the current location {_locationId}.");
        }

        _roadMovementComponent = RoadMovementComponent.EnterRoadFrom(road, location.LocationId);
    }
예제 #2
0
        public Road?Find(RoadId roadId)
        {
            if (!_roads.ContainsKey(roadId))
            {
                return(null);
            }

            return(_roads[roadId]);
        }
예제 #3
0
 public Road(RoadId roadId, RoadPoint fromPoint, RoadPoint toPoint)
 {
     RoadId    = roadId;
     FromPoint = fromPoint;
     ToPoint   = toPoint;
 }