Пример #1
0
        private Map AsciiMapToMap(AsciiMap ascii, int x, int y)
        {
            var scaleFactor = 100;

            var map = new Map();
            map.NullHeight = Convert.ToInt32(Math.Floor(ascii.NoDataValue / scaleFactor));
            map.Height = y;
            map.Width = x;

            map.Tiles = new Tile[y, x];

            decimal xScaleFactor = ascii.Columns / x;
            decimal yScaleFactor = ascii.Rows / y;

            for (int i = 0; i < y; i++)
            {
                for (int j = 0; j < x; j++)
                {
                    // for each item grab the interpolated value.

                    // x = the column
                    // y = the row

                    int itemX = Convert.ToInt32(Math.Floor(j * xScaleFactor));
                    int itemY = Convert.ToInt32(Math.Floor(i * yScaleFactor));

                    map.Tiles[i, j] = new Tile();

                    map.Tiles[i, j].Elevation = Convert.ToInt32(ascii.Data[itemY, itemX] / scaleFactor);
                }
            }

            return map;
        }
Пример #2
0
        private void ExportToCsv(Map map, string filename)
        {
            StringBuilder sb = new StringBuilder();

            for (int row = 0; row < map.Height; row++)
            {
                for (int column = 0; column < map.Width; column++)
                {
                    sb.Append((int)map.Tiles[row, column].Type);

                    if (column != map.Width - 1 || row != map.Height - 1)
                    {
                        sb.Append(",");
                    }

                }
                sb.AppendLine();
            }

            File.WriteAllText(filename, sb.ToString());
        }
Пример #3
0
 public void Export(Map map, string filename)
 {
     ExportToCsv(map, filename);
 }