示例#1
0
        public static Map.Map LoadFromString(string stringMap)
        {
            var map = new Map.Map();

            var rows = stringMap.Split("\n").Select(s => s.Trim()).ToArray();

            for (int y = 0; y < rows.Length; y++)
            {
                for (int x = 0; x < rows[y].Length; x++)
                {
                    CellType type   = rows[y][x] == 'X' ? CellType.Block : CellType.Classic;
                    int      weight = 0;
                    if (type == CellType.Classic && int.TryParse(rows[y][x].ToString(), out int result))
                    {
                        weight = result;
                    }
                    map.AddCell(new Cell(type, new Coordinates(x, y), weight == 0 ? 1 : weight));
                }
            }

            return(map);
        }