fCraft.Level.ReadLevel C# (CSharp) Method

ReadLevel() private method

private ReadLevel ( FileStream fs ) : void
fs System.IO.FileStream
return void
        void ReadLevel( FileStream fs ) {
            blocks = new byte[widthX][][];
            GZipStream zip = new GZipStream( fs, CompressionMode.Decompress );
            for( int x = 0; x < widthX; x++ ) {
                blocks[x] = new byte[widthY][];
                for( int y = 0; y < widthY; y++ ) {
                    blocks[x][y] = new byte[height];
                    zip.Read( blocks[x][y], 0, (int)height );
                }
            }
        }

Usage Example

Example #1
0
        public static Level Load(string fileName)
        {
            FileStream fs    = null;
            Level      level = null;

            if (!File.Exists(fileName))
            {
                Logger.LogError("Level.Load: Specified file does not exist: " + fileName);
                return(null);
            }

            try {
                fs = File.OpenRead(fileName);
                if (level.ReadHeader(fs))
                {
                    level.ReadLevel(fs);
                    return(level);
                }
                else
                {
                    return(null);
                }
            } catch (Exception) {
                Logger.LogError("Level.Load: Error trying to read from file: " + fileName);
                return(null);
            } finally {
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }