Exemple #1
0
 public void ClearTiles()
 {
     for (var i = X; i < X + Parent.CellWidth; i++)
     {
         for (var j = Y; j < Y + Parent.CellHeight; j++)
         {
             Main.tile[i, j] = new Tile();
         }
     }
     TileHelper.ResetSection(X, Y, Parent.CellWidth, Parent.CellHeight);
 }
Exemple #2
0
        /// <summary>
        /// 生成格子并记录格子数值到数据库.
        /// </summary>
        /// <param name="empty"> 是否清空区域/适合修复格子 </param>
        public void GenerateCells(bool empty = true)
        {
            if (empty)
            {
                TileHelper.RemoveTiles(X, Y, Width, Height);
            }

            var style = PlotMarker.Config.PlotStyle;
            var cellX = CellWidth + style.LineWidth;
            var cellY = CellHeight + style.LineWidth;
            var numX  = (Width - style.LineWidth) / cellX;
            var numY  = (Height - style.LineWidth) / cellY;

            Width  = numX * cellX + style.LineWidth;
            Height = numY * cellY + style.LineWidth;

            //draw horizental line
            for (var y = 0; y <= numY; y++)
            {
                for (var x = 0; x < Width; x++)
                {
                    for (var t = 0; t < style.LineWidth; t++)
                    {
                        TileHelper.SetTile(X + x, Y + y * cellY + t, style.TileId, style.TilePaint);
                        TileHelper.SetWall(X + x, Y + y * cellY + t, style.WallId, style.WallPaint);
                    }
                }
            }

            //draw vertical line
            for (var x = 0; x <= numX; x++)
            {
                for (var y = 0; y < Height; y++)
                {
                    for (var t = 0; t < style.LineWidth; t++)
                    {
                        TileHelper.SetTile(X + x * cellX + t, Y + y, style.TileId, style.TilePaint);
                        TileHelper.SetWall(X + x * cellX + t, Y + y, style.WallId, style.WallPaint);
                    }
                }
            }

            TileHelper.ResetSection(X, Y, Width, Height);

            var cells = new List <Cell>();

            for (var x = 0; x < numX; x++)
            {
                for (var y = 0; y < numY; y++)
                {
                    var cell = new Cell
                    {
                        Id         = cells.Count,
                        Parent     = this,
                        X          = X + x * cellX + style.LineWidth,
                        Y          = Y + y * cellY + style.LineWidth,
                        AllowedIDs = new List <int>()
                    };
                    cells.Add(cell);
                }
            }
            Cells = cells.ToArray();
            PlotMarker.Plots.AddCells(this);
        }