示例#1
0
        /// <summary>
        /// Called when a there is a group new ICell objects being controlled by the attached GameEngine object. The default behavior is to create new
        /// corresponding CellView objects and redraw them.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="BattleFiled.GameEngine.CellRegionEventArgs" /> instance containing the event data.</param>
        protected virtual void OnCellsInRegionRedefinedHandler(object sender, CellRegionEventArgs e)
        {
            int       startX            = e.RegionStartX;
            int       startY            = e.RegionStartY;
            int       endX              = e.RegionEndX;
            int       endY              = e.RegionEndY;
            Playfield playfield         = this.Engine.PlayField;
            bool      shouldChangeColor = false;

            for (int indexX = startX; indexX < endX; indexX++)
            {
                if (endX % 2 == 0)
                {
                    shouldChangeColor = !shouldChangeColor;
                }

                for (int indexY = startY; indexY < endY; indexY++)
                {
                    ICellView view = this.CreateCellView(playfield[indexX, indexY], shouldChangeColor);
                    this.CellViews[indexX, indexY] = view;
                    view.Draw();
                    shouldChangeColor = !shouldChangeColor;
                }
            }
        }
示例#2
0
        /// <summary>Called when there is a new ICell object being controlled by the attached GameEngine object. The default behavior is to create a new
        /// corresponding CellView  and redraw it.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="BattleFiled.GameEngine.CellEventArgs" /> instance containing the event data.</param>
        protected virtual void OnCellRedefinedHandler(object sender, CellEventArgs e)
        {
            ICellView view = this.CreateCellView(e.Target, false);

            this.CellViews[e.Target.X, e.Target.Y] = view;
            view.Draw();
        }
示例#3
0
        protected override void UnbindCellFromView(ICellView cellView)
        {
            if (cellView?.Editor == null || cellView.Editor.IsDisposed)
            {
                return;
            }

            cellView.Editor.Dispose();
            ClientSession.Workbook.EditorHub.RemoveEditor(cellView.Editor);

            if (cellView is CellView htmlCellView && htmlCellView?.RootElement?.ParentElement != null)
            {
                htmlCellView.RootElement.ParentElement.RemoveChild(htmlCellView.RootElement);
            }
        }
示例#4
0
        /// <summary>
        /// Creates the ICellView object instances needed in order to visualize a provided <see cref="Playfield"/> object.
        /// </summary>
        /// <param name="playfield">The playfield to be used for generation.</param>
        /// <returns>An array of ICellView objects.</returns>
        private ICellView[,] CreateCellViews(Playfield playfield)
        {
            int  fieldSize         = playfield.PlayfieldSize;
            bool shouldChangeColor = false;

            ICellView[,] cellViews = new ICellView[fieldSize, fieldSize];

            for (int i = 0; i < playfield.PlayfieldSize; i++)
            {
                if (playfield.PlayfieldSize % 2 == 0)
                {
                    shouldChangeColor = !shouldChangeColor;
                }

                for (int j = 0; j < playfield.PlayfieldSize; j++)
                {
                    cellViews[i, j]   = this.CreateCellView(playfield[i, j], shouldChangeColor);
                    shouldChangeColor = !shouldChangeColor;
                }
            }

            return(cellViews);
        }
示例#5
0
 protected abstract void UnbindCellFromView(ICellView cellView);
 protected override void UnbindCellFromView(ICellView cellView)
 {
 }
示例#7
0
        /// <summary>
        /// Creates the ICellView object instances needed in order to visualize a provided <see cref="Playfield"/> object.
        /// </summary>
        /// <param name="playfield">The playfield to be used for generation.</param>
        /// <returns>An array of ICellView objects.</returns>
        private ICellView[,] CreateCellViews(Playfield playfield)
        {
            int fieldSize = playfield.PlayfieldSize;
            bool shouldChangeColor = false;
            ICellView[,] cellViews = new ICellView[fieldSize, fieldSize];

            for (int i = 0; i < playfield.PlayfieldSize; i++)
            {
                if (playfield.PlayfieldSize % 2 == 0)
                {
                    shouldChangeColor = !shouldChangeColor;
                }

                for (int j = 0; j < playfield.PlayfieldSize; j++)
                {
                    cellViews[i, j] = this.CreateCellView(playfield[i, j], shouldChangeColor);
                    shouldChangeColor = !shouldChangeColor;
                }
            }

            return cellViews;
        }