Exemple #1
0
        public static ObjectsLayer FromFile(string filename)
        {
            ObjectsLayer obj;
            List<List<int>> tempobj = new List<List<int>>();

            using (StreamReader reader = new StreamReader("Content/"+filename))
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine().Trim() ;

                    List<int> row = new List<int>();
                    string[] cells = line.Split(' ');

                    foreach (string c in cells)
                    {
                        row.Add(int.Parse(c));
                    }

                    tempobj.Add(row);
                }
            }

            int width = tempobj[0].Count;
            int height = tempobj.Count;

            obj = new ObjectsLayer(width, height);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    obj.SetCellIndex(x, y, tempobj[y][x]);
                }
            }

            return obj;
        }