public static SimpleCellMap FromText(Stream stream, char start, char stop, char wall, char empty) { List <string> lines = ReadTextStream(stream, new List <char>() { wall, empty, start, stop }, empty); Console.WriteLine("map file:"); foreach (var line in lines) { Console.WriteLine(line); } Console.WriteLine(); if (lines.Count == 0) { throw new ArgumentException("Nothing was read from stream"); } int width = lines[0].Length; int height = lines.Count; SimpleCellMap map = new SimpleCellMap(width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (lines[y][x] == wall) { map[x, y] = false; } else if (lines[y][x] == empty) { map[x, y] = true; } else if (lines[y][x] == start) { map[x, y] = true; map.DefaultStart = new Vector2Int(x, y); } else if (lines[y][x] == stop) { map[x, y] = true; map.DefaultStop = new Vector2Int(x, y); } else { throw new ArgumentException("Stream contains unknown chars"); } } } return(map); }
private void CreateMap() { string text = File.ReadAllText("complex.cmap"); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(text)); _cellMap = StringMapBuilder.FromText(stream, 'S', 'E', 'X', '.'); _hpaStar = new HpaStarAlgorithm(); _hpaStar.Initialize(_cellMap, 8); }