Esempio n. 1
0
        private void Unregister(IDispatchee dispatchee)
        {
            dispatchee.ThrowIfNull(nameof(dispatchee));
            dispatchee.UniqueId.ThrowIfEmpty(nameof(dispatchee.UniqueId));

            _uniquelyNamedDispatchees.Remove(dispatchee.UniqueId);
        }
Esempio n. 2
0
        internal Room AddDoor(int doorNumber)
        {
            IDispatchee dispatchee = null;

            while (dispatchee == null)
            {
                var tileName = FindWall();
                dispatchee = Registry.GetDispatchee(tileName);

                if (dispatchee.Name != "Wall")
                {
                    dispatchee = null;
                }
                else
                {
                    var wall = (Wall)dispatchee;
                    if (wall.IsCorner)
                    {
                        dispatchee = null;
                    }
                }
            }

            var door     = ActorBuilder.Build <Door>(dispatchee.Coordinates, Registry, doorNumber.ToString());
            var newState = door.Coordinates.ToTileState(door.UniqueId);

            return(Clone(newState));
        }
 private static void CheckType(this IDispatchee dispatchee, string expectedDispatcheeType)
 {
     if (dispatchee.Name != expectedDispatcheeType)
     {
         throw new ArgumentException($"Expected a type of [{expectedDispatcheeType}] and got [{dispatchee.Name}]");
     }
 }
Esempio n. 4
0
 private void EnsureToUnregisterExistingDispatchee(IDispatchee dispatchee, string uniqueId)
 {
     if (DispatcheeWithSameIdExists(uniqueId))
     {
         var existing = _uniquelyNamedDispatchees[uniqueId];
         if (!existing.IsSameInstance(dispatchee))
         {
             Unregister(existing);
         }
     }
 }
Esempio n. 5
0
        private Maze PlaceInMaze(IDispatchee dispatchee, Coordinate coordinates)
        {
            var cloner = (ICloner <Maze>)dispatchee;

            var state = FormatState(coordinates);
            var actor = cloner.Clone(state);

            var newState = coordinates.ToTileState(actor.UniqueId);

            return(Clone(newState));
        }
Esempio n. 6
0
        internal string Register(IDispatchee dispatchee)
        {
            dispatchee.ThrowIfNull(nameof(dispatchee));

            var uniqueId = dispatchee.UniqueId.IsNullOrEmpty() ? GenerateUniqueId(dispatchee) : dispatchee.UniqueId;

            EnsureToUnregisterExistingDispatchee(dispatchee, uniqueId);

            _uniquelyNamedDispatchees[uniqueId] = dispatchee;

            return uniqueId;
        }
Esempio n. 7
0
        private string GenerateUniqueId(IDispatchee dispatchee)
        {
            uint count = 0;
            if (_dispatcheeCounts.ContainsKey(dispatchee.Name))
            {
                count = _dispatcheeCounts[dispatchee.Name];
            }

            _dispatcheeCounts[dispatchee.Name] = ++count;

            return dispatchee.Name + count;
        }
 private static IDispatchee BuildRockFromThis(IDispatchee rock)
 {
     rock.CheckType(Rock.DispatcheeName);
     return(new Rock((Rock)rock));
 }
        private static IDispatchee BuildDoorFromThis(IDispatchee door)
        {
            door.CheckType(Door.DispatcheeName);

            return(new Door((Door)door));
        }
 private static IDispatchee BuildWallFromThis(IDispatchee wall)
 {
     wall.CheckType(Wall.DispatcheeName);
     return(new Wall((Wall)wall));
 }