Exemplo n.º 1
0
        internal static void WriteServerInfo(NetOutgoingMessage message, ServerInfo info)
        {
            // name
            message.Write(info.name);

            // scheme
            Scheme scheme = info.scheme;

            // scheme: name
            message.Write(scheme.name);

            // scheme: field data
            FieldData fieldData = scheme.fieldData;

            message.Write(fieldData.GetWidth());
            message.Write(fieldData.GetHeight());

            FieldBlocks[] blocks = fieldData.GetDataArray();
            for (int i = 0; i < blocks.Length; ++i)
            {
                byte block = (byte)blocks[i];
                message.Write(block);
            }

            // scheme: player locations
            PlayerLocationInfo[] playerLocations = scheme.GetPlayerLocations();
            message.Write((byte)playerLocations.Length);
            for (int i = 0; i < playerLocations.Length; ++i)
            {
                message.Write((byte)playerLocations[i].x);
                message.Write((byte)playerLocations[i].y);
                message.Write((byte)playerLocations[i].team);
            }
        }
Exemplo n.º 2
0
        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.º 3
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;
                    }
                    }
                }
            }
        }