コード例 #1
0
ファイル: ClsFileReader.cs プロジェクト: OneSecure/cubesgame
        public static ClsLevelList readClsFile(String levelFile)
        {
            ClsLevelList levelList = new ClsLevelList();

            FileStream   levelStream = File.OpenRead(levelFile);
            BinaryReader binReader   = new BinaryReader(levelStream);

            // Read TOC
            int levelCount = (int)binReader.ReadInt64();

            long[] toc = new long[levelCount];
            for (int i = 0; i < levelCount; i++)
            {
                toc[i] = binReader.ReadInt64();
            }

            // Read Body
            for (int i = 0; i < levelCount; i++)
            {
                levelList.addLevel(
                    binReader.ReadBytes(
                        (int)binReader.ReadInt64()));
            }

            levelStream.Close();
            return(levelList);
        }
コード例 #2
0
ファイル: ClsFileWriter.cs プロジェクト: OneSecure/cubesgame
        public static void writeClsFile(String fileName, ClsLevelList levelList)
        {
            FileStream   output    = File.Create(fileName);
            BinaryWriter binWriter = new BinaryWriter(output);

            // Prepare TOC
            long levelCount = levelList.getLength();

            binWriter.Write(levelCount);
            long[] toc = new long[levelCount];

            // Write Body
            binWriter.BaseStream.Position = 8 + 8 * levelCount;

            for (int i = 0; i < levelCount; i++)
            {
                toc[i] = binWriter.BaseStream.Position;

                ClsLevel level = levelList.getLevel(i);
                byte[]   bytes = level.Bytes;
                binWriter.Write((long)bytes.Length);
                binWriter.Write(bytes);
            }

            // Write TOC
            binWriter.BaseStream.Position = 8;

            for (int i = 0; i < levelCount; i++)
            {
                binWriter.Write(toc[i]);
            }

            output.Close();
        }
コード例 #3
0
        public static ClsLevelList importBmpFile(String fileName)
        {
            ClsLevelList levelList = new ClsLevelList();

            // Read File
            FileStream levelStream = File.OpenRead(fileName);
            Bitmap     levelMap    = new Bitmap(levelStream);
            int        levelSize   = levelMap.Height;
            long       levelCount  = levelMap.Width / levelMap.Height;

            levelStream.Close();

            // Parse Bitmap
            for (int i = 0; i < levelCount; i++)
            {
                List <byte[]> bytesList = new List <byte[]>();

                for (int x = 0; x < levelSize; x++)
                {
                    for (int y = 0; y < levelSize; y++)
                    {
                        Color fieldColor = levelMap.GetPixel(x + levelSize * i, levelSize - y - 1);

                        byte[] newField = new byte[4];
                        newField[0] = ClsConst.FTYPE_UNKNOWN;
                        newField[1] = (byte)x;
                        newField[2] = (byte)y;

                        if (fieldColor.Equals(Color.FromArgb(255, 255, 255, 255)))
                        {
                            newField[0] = ClsConst.FTYPE_NORMAL;
                        }

                        if (fieldColor.Equals(Color.FromArgb(255, 0, 255, 0)))
                        {
                            newField[0] = ClsConst.FTYPE_FINISH;
                        }

                        if (fieldColor.Equals(Color.FromArgb(255, 255, 0, 0)))
                        {
                            newField[0] = ClsConst.FTYPE_START;
                        }

                        if (newField[0] != ClsConst.FTYPE_UNKNOWN)
                        {
                            bytesList.Add(newField);
                        }
                    }
                }

                levelList.addLevel(new ClsLevel(bytesList));
            }

            return(levelList);
        }