예제 #1
0
        public void MapObjectPlaceInGoodPosition(Map map, int left, int top, int width, int height, Func <Point, bool> isGoodPosFn, DiceRoller roller, Func <Point, MapObject> createFn)
        {
            // find all good positions.
            List <Point> goodList = null;

            Point p = new Point();

            for (int x = left; x < left + width; x++)
            {
                p.X = x;
                for (int y = top; y < top + height; y++)
                {
                    p.Y = y;

                    if (isGoodPosFn(p) && map.GetMapObjectAt(x, y) == null)
                    {
                        if (goodList == null)
                        {
                            goodList = new List <Point>();
                        }
                        goodList.Add(p);
                    }
                }
            }

            // pick a good position at random and put the object there.
            if (goodList == null)
            {
                return;
            }
            int       iValid = roller.Roll(0, goodList.Count);
            MapObject mapObj = createFn(goodList[iValid]);

            if (mapObj != null)
            {
                map.PlaceMapObjectAt(mapObj, goodList[iValid]);
            }
        }
예제 #2
0
 public void MapObjectPlaceInGoodPosition(Map map, Rectangle rect, Func <Point, bool> isGoodPosFn, DiceRoller roller, Func <Point, MapObject> createFn)
 {
     MapObjectPlaceInGoodPosition(map, rect.Left, rect.Top, rect.Width, rect.Height, isGoodPosFn, roller, createFn);
 }
예제 #3
0
 public bool ActorPlace(DiceRoller roller, int maxTries, Map map, Actor actor, int left, int top, int width, int height)
 {
     return(ActorPlace(roller, maxTries, map, actor, left, top, width, height, null));
 }
예제 #4
0
 public bool ActorPlace(DiceRoller roller, int maxTries, Map map, Actor actor, Predicate <Point> goodPositionFn)
 {
     return(ActorPlace(roller, maxTries, map, actor, 0, 0, map.Width, map.Height, goodPositionFn));
 }
예제 #5
0
 public bool ActorPlace(DiceRoller roller, int maxTries, Map map, Actor actor)
 {
     return(ActorPlace(roller, maxTries, map, actor, null));
 }