public void AddDoesntOverWriteTest() { BasicMap newMap = new BasicMap(8, 8, 1, Distance.MANHATTAN); for (int i = 0; i < 8; i++) { newMap.SetTerrain(_factory.Generic(new Coord(i, i), '#')); } newMap.Add(_map); for (int i = 0; i < _map.Width; i++) { for (int j = 0; j < _map.Height; j++) { BasicTerrain t1 = _map.GetTerrain <BasicTerrain>(new Coord(i, j)); BasicTerrain t2 = newMap.GetTerrain <BasicTerrain>(new Coord(i, j)); if (i == j) { Assert.AreEqual('#', t2.Glyph); } else { Assert.AreEqual(t1.Glyph, t2.Glyph); } } } }
public void AddToLocationTest() { BasicMap largeMap = new BasicMap(18, 18, 1, Distance.MANHATTAN); largeMap.Add(_map, new Coord(_map.Width, _map.Height)); for (int i = 0; i < _map.Width; i++) { for (int j = 0; j < _map.Height; j++) { BasicTerrain t1 = _map.GetTerrain <BasicTerrain>(new Coord(i, j)); BasicTerrain t2 = largeMap.GetTerrain <BasicTerrain>(new Coord(i + _map.Width, j + _map.Height)); Assert.AreEqual(t1.Glyph, t2.Glyph); } } }
public static BasicMap Rotate(this BasicMap m, Coord origin, int radius, int degrees) { BasicMap rotated = new BasicMap(m.Width, m.Height, 1, Distance.EUCLIDEAN); //only rotating the bottom right corner, and not even rotating it correctly if (degrees % 90 == 0) { //this rotates more than just the circle - bug, deal with it later rotated.Add(m.RotateDiscreet(degrees)); } else { BasicMap map = m.RotateDiscreet(360); while (degrees > 45) { degrees -= 90; //rotates more than just this circle - bug - deal with it later map = m.RotateDiscreet(90); } while (degrees <= -45) { degrees += 90; //rotates more than just the circle - bug, fix later map = m.RotateDiscreet(270); } double radians = Calculate.DegreesToRadians(degrees); for (int x = -radius; x < radius; x++) { for (int y = -radius; y < radius; y++) { if (radius > Math.Sqrt(x * x + y * y)) { int xPrime = (int)(x * Math.Cos(radians) - y * Math.Sin(radians)); int yPrime = (int)(x * Math.Sin(radians) + y * Math.Cos(radians)); Coord source = new Coord(x, y) + origin; Coord target = new Coord(xPrime, yPrime) + origin; BasicTerrain terrain = map.GetTerrain <BasicTerrain>(source); if (terrain != null && rotated.Contains(target)) { rotated.SetTerrain(_factory.Copy(terrain, target)); } } } } } return(rotated); }
public static void Add(this BasicMap m, BasicMap map) => m.Add(map, new Coord(0, 0));