Пример #1
0
        public static DefaultMazeGenerator FromStream(Stream input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            int i, maxSize = 1;
            DefaultMazeGenerator mgen;

            using (var reader = new BinaryReader(input)) {
                int dimensions = reader.ReadInt32();
                mgen = new DefaultMazeGenerator(dimensions);
                var sizes = new int[dimensions];
                for (i = 0; i < dimensions; i++)
                {
                    maxSize *= sizes[i] = reader.ReadInt32();
                }
                mgen.SetSize(sizes);
                for (i = 0; i < maxSize; i++)
                {
                    mgen.GetCell(CoordIndexer.FromIndex(mgen, i)).Flag = reader.ReadInt32();
                }
            }
            return(mgen);
        }
Пример #2
0
        public void ToStream(Stream output)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            int maxSize = 1;

            foreach (int size in sizes)
            {
                maxSize *= size;
            }
            using (var writer = new BinaryWriter(output)) {
                writer.Write(dimensions);
                foreach (int c in sizes)
                {
                    writer.Write(c);
                }
                for (int i = 0; i < maxSize; i++)
                {
                    writer.Write(GetCell(CoordIndexer.FromIndex(this, i)).Flag);
                }
            }
        }