Exemple #1
0
        // Returns X, Y, NeedsRemoval
        public Tuple <int, int, bool> FindValidLocation(FarmObject cabin)
        {
            // First, check if the inital location has any overlaps
            var initialOverlaps = ObjectsList.Select(x => FindAllOverlaps(x, cabin));

            if (!initialOverlaps.Any())
            {
                // And if there aren't any, return the cabin's initial X,Y
                return(new Tuple <int, int, bool>(cabin.TileX, cabin.TileY, false));
            }
            var optimalLocation = FindPossibleLocations(GenerateOptimalLocations(), cabin);

            if (optimalLocation != null)
            {
                return(optimalLocation);
            }
            // If no optimal location works, start looking everywhere

            var location = FindPossibleLocations(GenerateEntireMapLocations(), cabin);

            if (location != null)
            {
                return(location);
            }
            // If nowhere works, return nothing, no location is valid, inform the player.
            return(null);
        }
Exemple #2
0
        public void ClearLocationForCabin(int x, int y, FarmObject c)
        {
            var cabin        = new FarmObject(GameObjectTypes.Building, x, y, c.Width, c.Height);
            var overlapLists = ObjectsList.SelectMany(t => FindAllOverlaps(t, cabin, true));

            foreach (var obj in overlapLists)
            {
                if (obj.Item3.Element.Parent != null)
                {
                    obj.Item3.Element.Remove();
                }
            }
        }