/// <summary>
        /// A class that checks for unpopped baloons and adds then to a stack.
        /// If there are unpopped baloons their positions are reset. If all baloons are 
        /// popped, red baloons are created in the emprty space.
        /// </summary>
        /// <param name="board">This method accepts a new instance of the Gameboard.</param>
        public override void Apply(Gameboard board)
        {
            for (int col = 0; col < board.BoardWidth; col++)
            {
                Stack<BoardComponent> columnContents = new Stack<BoardComponent>();

                for (int row = 0; row < board.BoardHeight; row++)
                {
                    var currentComponent = board.GetElement(row, col);

                    if (currentComponent.IsActive)
                    {
                        columnContents.Push(currentComponent);
                    }
                }

                for (int row = board.BoardHeight - 1; row >= 0; row--)
                {
                    if (columnContents.Count > 0)
                    {
                        board.SetElement(row, col, columnContents.Pop());
                    }
                    else
                    {
                        BalloonMaker balloonMaker = new BalloonMaker();
                        BoardComponent poppedBalloon = balloonMaker.MakeBalloon(BaloonColor.Red);
                        poppedBalloon.IsActive = false;

                        board.SetElement(row, col, poppedBalloon);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This Method fills the board with balloons of random color.
        /// </summary>
        public void GetBalloonsOnBoard()
        {
            Random randomGenerator = new Random();

            for (int i = 0; i < this.BoardHeight; i++)
            {
                for (int j = 0; j < this.BoardWidth; j++)
                {
                    int seed = randomGenerator.Next(0, 4);
                    var balloonFactory = new BalloonMaker();

                    switch (seed)
                    {
                        case 0:
                            this.contents[i, j] = balloonFactory.MakeBalloon(BaloonColor.Red);
                            continue;
                        case 1:
                            this.contents[i, j] = balloonFactory.MakeBalloon(BaloonColor.Blue);
                            continue;
                        case 2:
                            this.contents[i, j] = balloonFactory.MakeBalloon(BaloonColor.Green);
                            continue;
                        case 3:
                            this.contents[i, j] = balloonFactory.MakeBalloon(BaloonColor.Yellow);
                            continue;
                        default:
                            throw new ArgumentException();
                    }
                }
            }
        }