예제 #1
0
        /// <summary>
        /// Handle the explosion within two explosion radius.
        /// </summary>
        /// <param name="cell">BombCell cell.</param>
        private void HandleExplosionTwoRadius(BombCell cell)
        {
            this.HandleExplosionOneRadius(cell);

            int bombX = cell.X;
            int bombY = cell.Y;

            if (bombX - 1 >= 0)
            {
                this.MakeCellBlown(bombX - 1, bombY);
            }

            if (bombY + 1 < this.playField.PlayfieldSize)
            {
                this.MakeCellBlown(bombX, bombY + 1);
            }

            if (bombX + 1 < this.playField.PlayfieldSize)
            {
                this.MakeCellBlown(bombX + 1, bombY);
            }

            if (bombY - 1 >= 0)
            {
                this.MakeCellBlown(bombX, bombY - 1);
            }
        }
예제 #2
0
        /// <summary>
        /// Handle the explosion within five explosion radius.
        /// </summary>
        /// <param name="cell">BombCell cell.</param>
        private void HandleExplosionFiveRadius(BombCell cell)
        {
            this.HandleExplosionFourRadius(cell);

            int bombX = cell.X;
            int bombY = cell.Y;

            if (bombX - 2 >= 0 && bombY - 2 >= 0)
            {
                this.MakeCellBlown(bombX - 2, bombY - 2);
            }

            if (bombX - 2 >= 0 && bombY + 2 < this.playField.PlayfieldSize)
            {
                this.MakeCellBlown(bombX - 2, bombY + 2);
            }

            if (bombX + 2 < this.playField.PlayfieldSize && bombY + 2 < this.playField.PlayfieldSize)
            {
                this.MakeCellBlown(bombX + 2, bombY + 2);
            }

            if (bombX + 2 < this.playField.PlayfieldSize && bombY - 2 >= 0)
            {
                this.MakeCellBlown(bombX + 2, bombY - 2);
            }
        }
예제 #3
0
        public void TestIfBombWithSizeFiveExplodesAsExpected()
        {
            string testFieldSize = "6";


            Engine.FieldSizeUnitTestSetter     = new StringReader(testFieldSize);
            Engine.StartMenu.IsStartGameChosen = true;
            Engine    gameEngine = new Engine();
            Playfield testField  = Playfield.Instance;

            testField.SetFieldSize(6);
            testField.InitializeEmptyField();
            testField[4, 4] = new BombCell(5);

            PrivateObject enginePrivateInstance = new PrivateObject(gameEngine);

            enginePrivateInstance.Invoke("HandleExplosion", testField[4, 4]);
            Playfield engineField = (Playfield)enginePrivateInstance.GetFieldOrProperty("playField");
            BombCell  bomb        = new BombCell(5);

            bomb.X            = 4;
            bomb.Y            = 4;
            engineField[4, 4] = bomb;

            enginePrivateInstance.Invoke("ChangeCurrentCell", 4, 4);
            enginePrivateInstance.Invoke("HandleExplosion", engineField[4, 4]);

            Assert.AreEqual(engineField[4, 4].CellType == CellType.BlownCell, true, "Expected that the cell on coordinates 4,5 is CellType.BlownCell. Received {0} ", engineField[4, 4].CellType);
        }
예제 #4
0
        /// <summary>
        /// Handle explosion with a bomb cell.
        /// </summary>
        /// <param name="currentCell">BombCell currentCell.</param>
        private void HandleExplosion(BombCell currentCell)
        {
            this.gamePlayer.DetonatedMines++;

            switch (currentCell.BombSize)
            {
            case 1:
                this.HandleExplosionOneRadius(currentCell);
                break;

            case 2:
                this.HandleExplosionTwoRadius(currentCell);
                break;

            case 3:
                this.HandleExplosionThreeRadius(currentCell);
                break;

            case 4:
                this.HandleExplosionFourRadius(currentCell);
                break;

            case 5:
                this.HandleExplosionFiveRadius(currentCell);
                break;

            default:
                throw new NotImplementedException("Cannot handle explosion with radius more than 5.");
            }
        }
예제 #5
0
        public void CheckIfPlayfieldCellCanBeSetWithNewValue()
        {
            var playField = Playfield.Instance;

            playField.SetFieldSize(5);
            playField.InitializeEmptyField();
            BombCell bombCell = new BombCell(5);

            playField[0, 0] = bombCell;

            Assert.AreEqual(playField[0, 0].Equals(bombCell), true, string.Format("Exprected that cell in position 0,0 in the field is set as bombcell with size 5. Received {0}", playField[0, 0].Equals(bombCell)));
        }
예제 #6
0
        public void CellsTestIfBombCellIsCloned()
        {
            int      bombSize = 1;
            BombCell bombCell = new BombCell(bombSize);

            bombCell.X        = 2;
            bombCell.Y        = 3;
            bombCell.Color    = Color.White;
            bombCell.CellView = CellView.Bomb1;

            ICell clonedBombCell = bombCell.Clone();

            Assert.AreEqual(bombCell.X, clonedBombCell.X, "X coordinate has not cloned.");
            Assert.AreEqual(bombCell.Y, clonedBombCell.Y, "Y coordinate has not cloned.");
            Assert.AreEqual(bombCell.Color, clonedBombCell.Color, "Cell Color has not cloned.");
            Assert.AreEqual(bombCell.CellView, clonedBombCell.CellView, "CellView Color has not cloned.");
        }
예제 #7
0
    private void DoSetBomb()
    {
        if (curBombCount >= bombMaxCount)
        {
            return;
        }
        var bmodel = GameObject.Instantiate(bombTemplate, map.parent);

        bmodel.gameObject.SetActive(true);
        bmodel.anchoredPosition = role.anchoredPosition;
        bmodel.SetParent(map);
        curBombCount++;
        var bomb = new BombCell(bmodel, x, y, curBombMaxLength);
        var fire = FindWidget <RectTransform>(bombTemplate.transform, "fire");

        dBombs.Add(bomb.ID, bomb);
        var id = bomb.ID;
        var cx = x;
        var cy = y;

        DelayDoSth(3, () =>
        {
            if (!dBombs.ContainsKey(id))
            {
                return;
            }
            curBombCount--;
            dBombs.Remove(id);
            var insfire = GameObject.Instantiate(fire, map);
            insfire.anchoredPosition = bmodel.anchoredPosition;
            insfire.gameObject.SetActive(true);
            DelayDoSth(0.1f, () =>
            {
                DoFire(insfire, insfire, insfire, insfire, 1, bomb.maxLength, cx, cy);
                DelayDoSth(0.1f, () =>
                {
                    DisableObj(insfire.gameObject);
                });
            });

            DisableObj(bmodel.gameObject);
        });
    }
예제 #8
0
        public void CheckIfFieldToStringMethodReturnsCorrectString()
        {
            var playField = Playfield.Instance;

            playField.SetFieldSize(5);
            playField.InitializeEmptyField();
            BombCell bombCellOne   = new BombCell(1);
            BombCell bombCellTwo   = new BombCell(2);
            BombCell bombCellThree = new BombCell(3);
            BombCell bombCellFour  = new BombCell(4);
            BombCell bombCellFive  = new BombCell(5);

            playField[0, 0] = bombCellOne;
            playField[1, 1] = bombCellTwo;
            playField[2, 2] = bombCellThree;
            playField[3, 3] = bombCellFour;
            playField[4, 4] = bombCellFive;
            string playfieldStringExpected = playField.ToString();

            Assert.AreEqual(playfieldStringExpected.Equals(playField.ToString()), true, string.Format("Exprected that cell in position 0,0 in the field is set as bombcell with size 5. Received {0} ", playfieldStringExpected));
        }
예제 #9
0
        public MainWindow()
        {
            InitializeComponent();

            Random      rnd   = new Random();
            List <Cell> cells = new List <Cell>();
            List <Cell> bombs = new List <Cell>();


            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    cells.Add(new EmptyCell(ref BattleGrid, new Point(i, j)));
                }
            }

            for (int i = 0; i < 10; i++)
            {
                var x     = rnd.Next(10);
                var y     = rnd.Next(10);
                var fined = bombs.Find(item => item.Position.X == x && item.Position.Y == y);
                if (fined == null)
                {
                    var fres = cells.Find(item => item.Position.X == x && item.Position.Y == y);
                    var r    = cells.Remove(fres);

                    var bomb = new BombCell(ref BattleGrid, new Point(x, y));
                    bombs.Add(bomb);
                    cells.Add(bomb);
                }
                else
                {
                    i--;
                }
            }


            foreach (var bomb in bombs)
            {
                List <Cell> envCells = new List <Cell>();


                envCells.Add(cells.Find(item => (item.Position.X == bomb.Position.X - 1) && (item.Position.Y == bomb.Position.Y)));
                envCells.Add(cells.Find(item => (item.Position.X == bomb.Position.X + 1) && (item.Position.Y == bomb.Position.Y)));
                envCells.Add(cells.Find(item => (item.Position.X == bomb.Position.X) && (item.Position.Y == bomb.Position.Y + 1)));
                envCells.Add(cells.Find(item => (item.Position.X == bomb.Position.X) && (item.Position.Y == bomb.Position.Y - 1)));
                envCells.Add(cells.Find(item => (item.Position.X == bomb.Position.X - 1) && (item.Position.Y == bomb.Position.Y - 1)));
                envCells.Add(cells.Find(item => (item.Position.X == bomb.Position.X - 1) && (item.Position.Y == bomb.Position.Y + 1)));
                envCells.Add(cells.Find(item => (item.Position.X == bomb.Position.X + 1) && (item.Position.Y == bomb.Position.Y - 1)));
                envCells.Add(cells.Find(item => (item.Position.X == bomb.Position.X + 1) && (item.Position.Y == bomb.Position.Y + 1)));

                foreach (var item in envCells)
                {
                    if (item != null && item.GetType() == typeof(NumCell))
                    {
                        ((NumCell)item).Num = ((NumCell)item).Num + 1;
                    }
                    else if (item != null && item.GetType() == typeof(EmptyCell))
                    {
                        var point = item.Position;
                        var r     = cells.Remove(item);
                        cells.Add(new NumCell(ref BattleGrid, point, 1));
                    }
                }
            }

            cells.Sort((a, b) =>
            {
                if (a.Position.Y < b.Position.Y)
                {
                    return(-1);
                }
                else if (a.Position.Y == b.Position.Y && a.Position.X < b.Position.X)
                {
                    return(-1);
                }
                else if (a.Position.Y == b.Position.Y && a.Position.X == b.Position.X)
                {
                    return(0);
                }
                else
                {
                    return(1);
                }
            });

            foreach (var item in cells)
            {
                item.Draw();
            }
        }
예제 #10
0
        public void CellsTestExceptionWhenBombSizeIsLessThanMaxAllowed()
        {
            var bombCell = new BombCell();

            bombCell.BombSize = 6;
        }
예제 #11
0
        public void CellsTestIfBombCellYIsPositive()
        {
            var cellBomb = new BombCell();

            cellBomb.Y = -1;
        }
예제 #12
0
        public void CellsTestIfBombCellXIsPositive()
        {
            var bombCell = new BombCell();

            bombCell.X = -1;
        }