public void MarkArea(MapLocation from, MapLocation to, long fillValue, bool inclusive) { var difference = from - to; // Check where we need to fill in the gap if (difference.Abs() > 1) { var incrementor = difference.Normalized().Abs(); // If the requested location is going in the negative direction then we need our incrementor // to also be pointing in the negative direction. if (difference > 0) { incrementor *= -1; } // If we're not inclusive then we want to step back one more (chances are our actual position is out of bounds) if (!inclusive) { to -= incrementor; } // We do not want to mark the current location "to" because that's our new headlocation for (MapLocation i = from + incrementor; !i.SameAs(to); i += incrementor) { Debug.WriteLine("Marking: " + i + " with " + fillValue); _map[i.Row, i.Column] = fillValue; } } }
public void MarksMapSpaceFillsMapCorrectlyInclusive() { var headLocation = new MapLocation(50, 50); var newLocation = new MapLocation(50, 54); var fillValue = 1; var inclusive = true; var map = new Map(gameConfig.MapConfig); var mapMarker = new MapMarker(map); var incrementor = new MapLocation(0, 1); map[headLocation] = -1; mapMarker.MarkArea(headLocation, newLocation, fillValue, inclusive); Assert.Equal(map[newLocation], 0); Assert.Equal(map[headLocation], -1); for (MapLocation i = headLocation + incrementor; !i.SameAs(newLocation); i += incrementor) { Assert.Equal(map[i], fillValue); } }