public Pattern(BinaryReader reader)
            {
                Instructions = new List <PatternInstruction>();

                int count = reader.ReadInt32();

                for (int i = 0; i < count; i++)
                {
                    PatternInstruction inst = new PatternInstruction(
                        reader.ReadBoolean(),
                        reader.ReadUInt16());

                    Instructions.Add(inst);
                }
            }
            public Pattern(VoxelObject vo)
            {
                Instructions = new List <PatternInstruction>();
                ushort currentCount = 0;
                bool   skiping      = false;

                for (int x = 0; x < vo.Width; x++)
                {
                    for (int y = 0; y < vo.Height; y++)
                    {
                        for (int z = 0; z < vo.Depth; z++)
                        {
                            Block type = vo.Blocks[z, y, x];
                            if (type == Block.AIR && !skiping)
                            {
                                if (currentCount > 0)
                                {
                                    PatternInstruction inst = new PatternInstruction(false, currentCount);
                                    Instructions.Add(inst);
                                }

                                currentCount = 0;
                                skiping      = true;
                            }
                            else if (type == Block.STONE && skiping)
                            {
                                if (currentCount > 0)
                                {
                                    PatternInstruction inst = new PatternInstruction(true, currentCount);
                                    Instructions.Add(inst);
                                }

                                currentCount = 0;
                                skiping      = false;
                            }

                            currentCount++;
                        }
                    }
                }

                if (currentCount > 0)
                {
                    PatternInstruction inst = new PatternInstruction(skiping, currentCount);
                    Instructions.Add(inst);
                }
            }
            public void ApplyPattern(int wordIndex, int letterIndex, char realLetter, char fakeLetter,
                                     PatternInstruction instruction)
            {
                switch (instruction)
                {
                case PatternInstruction.RealLetter:
                    WordsOnTent[wordIndex] = ReplaceLetterAtIndex(WordsOnTent[wordIndex], letterIndex, realLetter);
                    break;

                case PatternInstruction.FakeLetter:
                    WordsOnTent[wordIndex] = ReplaceLetterAtIndex(WordsOnTent[wordIndex], letterIndex, fakeLetter);
                    break;

                case PatternInstruction.CutSpace:
                    WordsOnTent[wordIndex] = ReplaceLetterAtIndex(WordsOnTent[wordIndex], letterIndex, CUT_SYMBOL);
                    break;
                }
            }
        public bool Load(BinaryReader reader, out VoxelObject vo)
        {
            int   width    = (int)reader.ReadUInt16();
            int   height   = (int)reader.ReadUInt16();
            int   depth    = (int)reader.ReadUInt16();
            float cubeSize = reader.ReadSingle();

            Pattern   pattern = new Pattern(reader);
            ColorData colors  = new ColorData(reader);

            vo = new VoxelObject(cubeSize);
            vo.InitBlocks(width, height, depth);

            int patternI = 0, patternCountFollowed = 0, colorI = 0;
            PatternInstruction inst = pattern.Instructions[patternI++];

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int z = 0; z < depth; z++)
                    {
                        if (patternCountFollowed == inst.Count)
                        {
                            patternCountFollowed = 0;
                            inst = pattern.Instructions[patternI++];
                        }

                        if (!inst.Skip)
                        {
                            Color color = colors.Colors[colorI++];
                            vo.Blocks[z, y, x] = new Block(Block.STONE.Material, color.R, color.G, color.B);
                        }

                        patternCountFollowed++;
                    }
                }
            }

            return(true);
        }