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(); } } }
public Tuple <int, int, bool> FindPossibleLocations(IEnumerable <Tuple <int, int> > locations, FarmObject cabin) { Tuple <int, int, bool> optimalCabinLocation = null; var listOfPotentialCabins = locations.Select(x => new FarmObject(GameObjectTypes.Building, x.Item1, x.Item2, 5, 3)); // Cabin X , Y, List of Overlaps with X, Y, FarmObject @ overlap var overlapsByCabinLocations = listOfPotentialCabins.Select(c => new Tuple <int, int, IEnumerable <Tuple <int, int, FarmObject> > >(c.TileX, c.TileY, ObjectsList.SelectMany(x => FindAllOverlaps(x, c)))); foreach (var possibleCabinLocation in overlapsByCabinLocations) { var possible = true; foreach (var overlap in possibleCabinLocation.Item3) { var farmObject = overlap.Item3; if (!farmObject.CanBeRemoved) { possible = false; break; } } if (possible) { var needsRemoval = possibleCabinLocation.Item3.Any(); optimalCabinLocation = new Tuple <int, int, bool>(possibleCabinLocation.Item1, possibleCabinLocation.Item2, needsRemoval); break; } } return(optimalCabinLocation); }