public LocationType[,] GetMapArray(string map, CartesianSize size) { var line = map .Split(';') .Where(x => !string.IsNullOrWhiteSpace(x)) .ToList() .Skip(2) .ToList(); var regex = new Regex(@"[A-Z0-9\s]{1,}"); var mat = new string[line.Count][]; for (var x = 0; x < line.Count; x++) { mat[x] = line[x] .Split('|') .Where(p => regex.IsMatch(p)) .ToArray() .Skip(1) .ToArray(); } var realMat = new LocationType[(int)size.SizeX, (int)size.SizeY]; for (int x = 0; x < size.SizeX; x++) { for (int y = 0; y < size.SizeY; y++) { realMat[x, y] = GetLocationType(mat[y][x]); } } return(realMat); }
private Location[] getLocations(CartesianPointer position, CartesianSize mapSize, string map, int minCapacity, int maxCapacity) { var locations = new List <Location>(); var matrixSize = _converter.GetMatrixSize(map); var blockSize = _converter.GetBlockSize(mapSize, matrixSize); var mapArray = _converter.GetMapArray(map, matrixSize); var center = new CartesianPointer(matrixSize.SizeX / 2.0, matrixSize.SizeY / 2.0); for (var x = 0; x < matrixSize.SizeX; x++) { for (var y = 0; y < matrixSize.SizeY; y++) { if (mapArray[x, y] != LocationType.Default) { var pontoCentral = _converter.GetGlobalPointer(blockSize, position, mapSize, matrixSize, center, x, y); var l = new Location { Size = blockSize, Capacity = _rd.Next(minCapacity, maxCapacity), LocationType = mapArray[x, y], Occupation = 0, Position = pontoCentral }; if (l.Inside(_env)) { locations.Add(l); } } } } return(locations.ToArray()); }
public CartesianPointer GetGlobalPointer(CartesianSize blockSize, CartesianPointer position, CartesianSize mapSize, CartesianSize matrixSize, CartesianPointer center, int x, int y) { var deslocamentoLocal = new CartesianPointer(x - center.X, y - center.Y); var porcentagem = new CartesianSize(mapSize.SizeX / matrixSize.SizeX, mapSize.SizeY / matrixSize.SizeY); var deslocamentoGlobal = new CartesianPointer(deslocamentoLocal.X * porcentagem.SizeX, deslocamentoLocal.Y * porcentagem.SizeY); var ponto = new CartesianPointer(deslocamentoGlobal.X + position.X, deslocamentoGlobal.Y + position.Y); var pontoCentral = new CartesianPointer(ponto.X + blockSize.SizeX / 2.0, ponto.Y + blockSize.SizeY / 2.0); return(pontoCentral); }
static void Main(string[] args) { var file = File.ReadAllText(@"C:\Users\lucas.fernandes\Desktop\mapa1.txt") .Replace(@"\n", "") .Replace(@"\r", ""); var mapGlobalSize = new CartesianSize(1024, 768); var mapLocalSize = new CartesianSize(108, 96); var pontoReferencia = new CartesianPointer(-100, -100); var b = new EnvironmentBuilder(mapGlobalSize) .PlotMap(file, mapLocalSize, pontoReferencia); var threadId = Thread.CurrentContext.ContextID.ToString(); var h = new Helpers(new GetTaskStub(threadId, null), null, null, null, null, null); }
public CartesianSize GetBlockSize(CartesianSize size, CartesianSize matrixSize) { return(new CartesianSize(size.SizeX / matrixSize.SizeX, size.SizeY / matrixSize.SizeY)); }
public EnvironmentBuilder PlotMap(string map, CartesianSize size, CartesianPointer position) { _currentMap = _converter.GetMapName(map); _locations.Add(_currentMap, getLocations(position, size, map, 0, 2)); return(this); }
public EnvironmentBuilder(CartesianSize size) { _env = new VirtualEnvironment(size); _converter = new EnvironmentBuilderConverters(); }