コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        private int ClearLine()
        {
            int count = 0;

            for (int y = 0; y < FieldBlocks.GetLength(0); ++y)
            {
                bool line = true;

                for (int x = 0, max = FieldBlocks.GetLength(1); x < max; ++x)
                {
                    if (FieldBlocks[y, x] == Defs.Blocks.EmptyField)
                    {
                        line = false;
                        break;
                    }
                }

                if (line)
                {
                    ++count;

                    for (int x = 0, max = FieldBlocks.GetLength(1); x < max; ++x)
                    {
                        FieldBlocks[y, x] = Defs.Blocks.EmptyField;
                    }
                }
            }
            return(count);
        }
コード例 #2
0
        public void BuildForm(StringWriter htmlWriter, StringWriter jsWriter)
        {
            switch (FormType)
            {
            case AjaxFormType.FormPost:
                htmlWriter.Write(
                    "<form method=\"{0}\" action=\"{1}\" id=\"{2}\" name=\"{3}\" enctype=\"{4}\" class=\"{5}\" " +
                    "recordid=\"{6}\" formpart=\"form\"><input type=\"hidden\" name=\"RecordID\" value=\"{6}\" />" +
                    "<input type=\"hidden\" name=\"FormName\" value=\"{3}\" />",
                    FormMethod, FormAction, FormID, HttpUtility.HtmlEncode(FormName),
                    FormEncType == AjaxFormEncType.None ? "application/x-www-form-urlencoded" : "multipart/form-data",
                    CssClass, RecordID);
                FieldBlocks.Sort(RankedObject.SortByRank);
                fieldBlocks.BuildHTML(FormType, htmlWriter, jsWriter);
                htmlWriter.Write("</form>");
                break;

            case AjaxFormType.FullAjax:
                htmlWriter.Write("<div id=\"{0}\" class=\"{1}\" name=\"{2}\" recordid=\"{3}\" formpart=\"form\">",
                                 FormID, CssClass, FormName, RecordID);
                FieldBlocks.Sort(RankedObject.SortByRank);
                fieldBlocks.BuildHTML(FormType, htmlWriter, jsWriter);
                htmlWriter.Write("</div>");
                break;
            }
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="blocks"></param>
        /// <param name="blockX"></param>
        /// <param name="blockY"></param>
        /// <returns></returns>
        public bool IsHitBlock(Defs.Blocks[,] blocks, int blockX, int blockY)
        {
            for (int y = 0; y < blocks.GetLength(0); ++y)
            {
                for (int x = 0, max = blocks.GetLength(1); x < max; ++x)
                {
                    if (blocks[y, x] == Defs.Blocks.EmptyField)
                    {
                        continue;
                    }

                    if (y + blockY > FieldBlocks.GetLength(0) - 1)
                    {
                        return(true);
                    }

                    if (x + blockX > FieldBlocks.GetLength(1) - 1)
                    {
                        return(true);
                    }

                    if (x + blockX < 0)
                    {
                        return(true);
                    }

                    if (FieldBlocks[y + blockY, x + blockX] != Defs.Blocks.EmptyField)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #4
0
        public FieldData(int width, int height, FieldBlocks[] data)
        {
            if (data.Length != width * height)
            {
                throw new ArgumentException("Invalid data array size");
            }

            this.width = width;
            this.height = height;

            this.data = data;
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        private void CloseUpBlocks()
        {
            for (int y = FieldBlocks.GetLength(0) - 1; y >= 0; --y)
            {
                bool exit = true;

                for (int yy = y; yy >= 0; --yy)
                {
                    for (int x = 0, max = FieldBlocks.GetLength(1); x < max; ++x)
                    {
                        if (FieldBlocks[yy, x] != Defs.Blocks.EmptyField)
                        {
                            exit = false;
                            break;
                        }
                    }
                }

                if (exit)
                {
                    return;
                }

                bool line = true;

                for (int x = 0, max = FieldBlocks.GetLength(1); x < max; ++x)
                {
                    if (FieldBlocks[y, x] != Defs.Blocks.EmptyField)
                    {
                        line = false;
                        break;
                    }
                }

                if (line)
                {
                    for (int yy = y; yy >= 1; --yy)
                    {
                        for (int x = 0, max = FieldBlocks.GetLength(1); x < max; ++x)
                        {
                            FieldBlocks[yy, x] = FieldBlocks[yy - 1, x];
                        }
                    }
                    ++y;
                }
            }
        }
コード例 #6
0
ファイル: Field.cs プロジェクト: weeeBox/atomic-bomberman-xna
        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;
                    }
                    }
                }
            }
        }
コード例 #7
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));
                }
            }
        }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="blocks"></param>
        /// <param name="blockX"></param>
        /// <param name="blockY"></param>
        public void ClearBlock(Defs.Blocks[,] blocks, int blockX, int blockY)
        {
            for (int y = 0; y < blocks.GetLength(0); ++y)
            {
                for (int x = 0, max = blocks.GetLength(1); x < max; ++x)
                {
                    if (blocks[y, x] == Defs.Blocks.EmptyField)
                    {
                        continue;
                    }

                    if (y + blockY > FieldBlocks.GetLength(0) - 1 || x + blockX > FieldBlocks.GetLength(1) - 1)
                    {
                        continue;
                    }

                    FieldBlocks[y + blockY, x + blockX] = Defs.Blocks.EmptyField;
                }
            }
        }
コード例 #9
0
        //////////////////////////////////////////////////////////////////////////////

        #region Server Info

        internal static ServerInfo ReadServerInfo(NetIncomingMessage message)
        {
            // name
            String name = message.ReadString();

            // scheme
            Scheme scheme = new Scheme();

            // scheme: name
            scheme.name = message.ReadString();

            // scheme: field data
            int fieldWidth  = message.ReadInt32();
            int fieldHeight = message.ReadInt32();

            FieldBlocks[] fieldDataArray = new FieldBlocks[fieldWidth * fieldHeight];
            for (int i = 0; i < fieldDataArray.Length; ++i)
            {
                fieldDataArray[i] = (FieldBlocks)message.ReadByte();
            }
            scheme.fieldData = new FieldData(fieldWidth, fieldHeight, fieldDataArray);

            // scheme: player locations
            int locationsCount = message.ReadByte();

            PlayerLocationInfo[] playerLocations = new PlayerLocationInfo[locationsCount];
            for (int i = 0; i < locationsCount; ++i)
            {
                int x    = message.ReadByte();
                int y    = message.ReadByte();
                int team = message.ReadByte();

                playerLocations[i] = new PlayerLocationInfo(i, x, y, team);
            }
            scheme.playerLocations = playerLocations;

            ServerInfo info = new ServerInfo(name, message.SenderEndPoint);

            info.scheme = scheme;
            return(info);
        }
コード例 #10
0
        public void Set(int x, int y, FieldBlocks block)
        {
            int index = y * width + x;

            data[index] = block;
        }
コード例 #11
0
        internal static ServerInfo ReadServerInfo(NetIncomingMessage message)
        {
            // name
            String name = message.ReadString();

            // scheme
            Scheme scheme = new Scheme();

            // scheme: name
            scheme.name = message.ReadString();

            // scheme: field data
            int fieldWidth = message.ReadInt32();
            int fieldHeight = message.ReadInt32();
            FieldBlocks[] fieldDataArray = new FieldBlocks[fieldWidth * fieldHeight];
            for (int i = 0; i < fieldDataArray.Length; ++i)
            {
                fieldDataArray[i] = (FieldBlocks)message.ReadByte();
            }
            scheme.fieldData = new FieldData(fieldWidth, fieldHeight, fieldDataArray);

            // scheme: player locations
            int locationsCount = message.ReadByte();
            PlayerLocationInfo[] playerLocations = new PlayerLocationInfo[locationsCount];
            for (int i = 0; i < locationsCount; ++i)
            {
                int x = message.ReadByte();
                int y = message.ReadByte();
                int team = message.ReadByte();

                playerLocations[i] = new PlayerLocationInfo(i, x, y, team);
            }
            scheme.playerLocations = playerLocations;

            ServerInfo info = new ServerInfo(name, message.SenderEndPoint);
            info.scheme = scheme;
            return info;
        }
コード例 #12
0
 public void Set(int x, int y, FieldBlocks block)
 {
     int index = y * width + x;
     data[index] = block;
 }