public FieldDataView(FieldData data, Style style)
            : base(style.width, style.height)
        {
            AddView(new RectView(0, 0, width, height, Color.Gray, Color.Black));

            float iw = style.iw;
            float ih = style.ih;

            RectView rect = new RectView(0.5f * (width - iw), 0.5f * (height - ih), iw, ih, Color.Green, Color.Green);
            AddView(rect);

            float cw = iw / data.GetWidth();
            float ch = ih / data.GetHeight();

            for (int y = 0; y < data.GetHeight(); ++y)
            {
                for (int x = 0; x < data.GetWidth(); ++x)
                {
                    FieldBlocks block = data.Get(x, y);
                    Color color;

                    switch (block)
                    {
                        case FieldBlocks.Brick:
                            color = COLOR_BRICK;
                            break;
                        case FieldBlocks.Solid:
                            color = COLOR_SOLID;
                            break;

                        default:
                            continue;
                    }

                    float cx = x * cw;
                    float cy = y * ch;

                    rect.AddView(new RectView(cx, cy, cw, ch, color, color));
                }
            }
        }
Exemplo n.º 2
0
        private void SetupField(FieldData data, int brickDensity = -1)
        {
            int width = data.GetWidth();
            int height = data.GetHeight();

            cells = new FieldCellArray(width, height);

            movableCells = new LinkedList<MovableCell>();

            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    FieldBlocks block = data.Get(x, y);
                    switch (block)
                    {
                        case FieldBlocks.Blank:
                        {
                            break;
                        }

                        case FieldBlocks.Brick:
                        {
                            if (brickDensity == -1 || MathHelp.NextInt(100) <= brickDensity)
                            {
                                AddCell(new BrickCell(x, y));
                            }
                            break;
                        }

                        case FieldBlocks.Solid:
                        {
                            AddCell(new SolidCell(x, y));
                            break;
                        }

                        default:
                        {
                            Debug.Assert(false, "Unsupported cell type: " + block);
                            break;
                        }
                    }
                }
            }
        }