Example #1
0
    void Update()
    {
        if (!gameOver)
        {
            if (gameRunning)
            {
                shapeController.ReceiveInput();

                StartCoroutine(shapeController.Fall(stopped => {
                    if (stopped)
                    {
                        board.PutBlocks(shape.GetCurrentBlocks());
                        boardView.PutBlocks(shape.GetCurrentBlocks());

                        int cleanedCount;
                        var cleanedSome = board.CleanFullRows(out cleanedCount);

                        if (cleanedSome)
                        {
                            cleanAudio.Play();
                            score += cleanedCount;
                            UpdateScore();
                            shape.Speed = RecalcSpeed();
                            boardView.EraseBlocks();
                            boardView.PutBlocks(board.GetBlocks());
                        }

                        // Game over
                        if (board.IsOverflow())
                        {
                            loseAudio.Play();
                            Over();
                        }

                        shape = SpawnShape(shape.Speed);
                    }
                }));
            }


            if (Input.GetKeyDown(KeyCode.Escape))
            {
                if (gameRunning)
                {
                    Pause();
                }
                else
                {
                    Resume();
                }
            }
        }
    }
Example #2
0
    private void Update()
    {
        if (!_gameOver)
        {
            if (_gameRunning)
            {
                _shapeController.ReceiveInput();

                StartCoroutine(_shapeController.Fall(stopped =>
                {
                    if (stopped)
                    {
                        _board.PutBlocks(_shape.GetCurrentBlocks());
                        _boardView.PutBlocks(_shape.GetCurrentBlocks());

                        int cleanedCount;
                        var cleanedSome = _board.CleanFullRows(out cleanedCount);

                        if (cleanedSome)
                        {
                            _score += cleanedCount;
                            UpdateScore();
                            _shape.Speed = RecalcSpeed();
                            _boardView.EraseBlocks();
                            _boardView.PutBlocks(_board.GetBlocks());
                        }

                        if (_board.IsOverflow())
                        {
                            Over();
                        }

                        _shape = SpawnShape(_shape.Speed);
                    }
                }));
            }
        }
    }