Example #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;
                }
            }
        }
        public void TestIfCellRegionEventArgsIsSetWithCorrectStartXStartYEndXAndY()
        {
            CellRegionEventArgs testRegionEvent = new CellRegionEventArgs(1, 2, 3, 4);
            bool arePropertiesCorrect           = testRegionEvent.RegionStartX == 1 && testRegionEvent.RegionStartY == 2 &&
                                                  testRegionEvent.RegionEndX == 3 && testRegionEvent.RegionEndY == 4;

            Assert.AreEqual(arePropertiesCorrect, true, string.Format("Exprected CellRegionEvent with region start x = 1, region start y = 2, region end x = 3, region end y = 4. Received region start x = {0}, region start y = {1}, region end x = {2}, region end y = {3}", testRegionEvent.RegionStartX, testRegionEvent.RegionStartY, testRegionEvent.RegionEndX, testRegionEvent.RegionEndY));
        }
Example #3
0
        /// <summary>
        /// Called when a group of ICell objects controlled by the attached GameEngine object change their state. The default behavior is to redraw the
        /// corresponding ICellView objects maintained by this class.
        /// </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 OnCellsInRegionChangedHandler(object sender, CellRegionEventArgs e)
        {
            int startX = e.RegionStartX;
            int startY = e.RegionStartY;
            int endX   = e.RegionEndX;
            int endY   = e.RegionEndY;

            for (int indexX = startX; indexX < endX; indexX++)
            {
                for (int indexY = startY; indexY < endY; indexY++)
                {
                    this.CellViews[indexX, indexY].Draw();
                }
            }
        }
 public void TestIfCellRegionEventArgsRegionEndYCreateWithNegativeNumberWillThrowArgumentNullException()
 {
     CellRegionEventArgs testRegionEvent = new CellRegionEventArgs(1, 2, 3, -4);
 }