コード例 #1
0
        public void Start()
        {
            #region Validation
            if (_gameStatus != GameStatus.ReadyToStart)
            {
                throw new InvalidOperationException("Only game with status 'ReadyToStart' can be started");
            }
            #endregion

            _gameStatus      = GameStatus.InProgress;
            Field.EmptyCells = _gameLogic.CountEmptyCells();
            // Тут можна використати const чи readonly значення
            if (Field.EmptyCells < 6)
            {
                throw new InvalidOperationException("Can't start game,not enought empty cells");
            }

            int generateBigBubbles   = 3;
            int generateSmallBubbles = 3;

            Cell[] bigBubbles = _bubbleGenerationStrategy.GenerateBigBubbles(Field, generateBigBubbles);
            PlaceBubblesOnField(bigBubbles);
            Field.EmptyCells -= generateBigBubbles;

            Cell[] smallBubbles = _bubbleGenerationStrategy.GenerateSmallBubbles(Field, generateSmallBubbles);
            PlaceBubblesOnField(smallBubbles);

            OnScoreChange(this, EventArgs.Empty);
            OnNextTurn(this, EventArgs.Empty);
            OnDraw(this, EventArgs.Empty);
        }
コード例 #2
0
        public void NextTurn(bool generateBubbles)
        {
            Turn++;

            if (generateBubbles)
            {
                BubbleRaizing();

                int generateSmallBubbles = (Field.EmptyCells > 2) ? 3 : Field.EmptyCells;

                if (Field.EmptyCells == 0)
                {
                    OnGameOver();
                    return;
                }

                Cell[] smallBubbles = _bubbleGenerationStrategy.GenerateSmallBubbles(Field, generateSmallBubbles);
                foreach (var bubble in smallBubbles)
                {
                    Field.Cells[bubble.Row, bubble.Column].Contain = bubble.Contain;
                    Field.Cells[bubble.Row, bubble.Column].Color   = bubble.Color;
                }
            }

            OnNextTurn();
        }
コード例 #3
0
        public void Start()
        {
            #region Validation
            if (_gameStatus != GameStatus.ReadyToStart)
            {
                throw new InvalidOperationException("Only game with status 'ReadyToStart' can be started");
            }
            #endregion

            _gameStatus = GameStatus.InProgress;
            Field.CountEmptyCells();

            if (Field.EmptyCells < 2 * _difficulty)
            {
                throw new InvalidOperationException("Can't start game! Not enought empty cells");
            }

            Cell[] bigBubbles = _bubbleGenerationStrategy.GenerateBigBubbles(Field, _difficulty);
            Field.PlaceBubbles(bigBubbles);
            Field.EmptyCells -= _difficulty;

            Cell[] smallBubbles = _bubbleGenerationStrategy.GenerateSmallBubbles(Field, _difficulty);
            Field.PlaceBubbles(smallBubbles);

            OnDraw(this, EventArgs.Empty);
        }
コード例 #4
0
        public void NextTurn(bool generateBubbles)
        {
            Turn++;

            if (generateBubbles)
            {
                RaizeSmallBubbles();

                int generateSmallBubbles = (Field.EmptyCells > _difficulty - 1) ? _difficulty : Field.EmptyCells;

                if (Field.EmptyCells == 0)
                {
                    OnGameOver();
                    return;
                }

                Cell[] smallBubbles = _bubbleGenerationStrategy.GenerateSmallBubbles(Field, generateSmallBubbles);
                Field.PlaceBubbles(smallBubbles);
            }

            OnDraw();
            OnTurnChange();
        }