Пример #1
0
    public void Parse(string axisName, string axis, ref byte[] dstAxis, ref int dimension)
    {
        string[] m     = axis.Split();
        bool     error = false;
        string   s;
        int      i;

        dimension = 0;
        bb.Reset();
        for (i = 0; i < m.Length; i++)
        {
            s = m[i].Trim();
            if (s.Length > 0)
            {
                string[] h = s.Split(',');
                string   k;
                int      j;

                bb.Append((byte)h.Length);
                dimension++;

                for (j = 0; j < h.Length; j++)
                {
                    k = h[j].Trim();
                    if (k.Length < 1)
                    {
                        Console.WriteLine("*** [" + name + "]:" + puzzleStart + ":" + axisName + " axis: garbage sequence on index " + (i + 1));
                        error = true;
                    }
                    else
                    {
                        try {
                            byte v;

                            v = (byte)int.Parse(k);
                            if (v < 0 || v > 100)
                            {
                                throw new Exception("");
                            }

                            bb.Append(v);
                        } catch {
                            Console.WriteLine("*** [" + name + "]:" + puzzleStart + ":" + axisName + " axis: garbage number (index " + (i + 1) + ")");
                            error = true;
                        }
                    }
                }
            }
        }

        if (error)
        {
            dstAxis = null;
        }
        else
        {
            dstAxis = bb.ToBytes();
        }
    }
Пример #2
0
    public void Write(string name, string file)
    {
        ByteBuilder bb  = new ByteBuilder(1024);
        PDB         pdb = new PDB(name);
        string      key;
        Puzzle      puzzle;

        if (fileInvalid)
        {
            Environment.Exit(1);
        }

        for (int i = 0; i < list.Count; i++)
        {
            key    = (string)list.GetKey(i);
            puzzle = (Puzzle)list.GetByIndex(i);

            bb.Reset();
            bb.Append(1);
            bb.Append((byte)puzzle.width);
            bb.Append((byte)puzzle.height);
            bb.Append(key);
            bb.Append(0);
            bb.Append(puzzle.author);
            bb.Append(0);
            bb.Append(puzzle.site);
            bb.Append(0);
            bb.Append(puzzle.xAxis);
            bb.Append(puzzle.yAxis);
            Console.WriteLine("---> Adding [" + key + "] (" + puzzle.width + " x " + puzzle.height + ")");
            pdb.AddRecord(bb.ToBytes());
        }

        Console.WriteLine("---> " + list.Count + " puzzl" + ((list.Count == 1) ? "e" : "es") + " added");
        pdb.Write(file);
    }