Beispiel #1
0
        private IEnumerator SpawnTetromino(bool useHoldPiece)
        {
            // Create the first tetromino
            if (_tetrominosFactory == null)
            {
                _tetrominosFactory = GetComponent <ITetrominosFactory>();
            }

            if (!useHoldPiece)
            {
                _currentTetromino = _tetrominosFactory.GetNextPiece(0, 3);
                _isHoldPiece      = false;
            }
            else
            {
                // Play this as a
                _soundController.PlayHoldTetromino();

                int previousHoldPieceType = _holdController.Hold(_currentTetromino.PieceType);
                if (previousHoldPieceType > Utils.TetrominoUtils.NoPiece)
                {
                    _currentTetromino = _tetrominosFactory.GetNextPiece(previousHoldPieceType, 0, 3);
                }
                else
                {
                    _currentTetromino = _tetrominosFactory.GetNextPiece(0, 3);
                }

                _isHoldPiece = true;
            }

            if (CanPlaceTetrominoWithWallKick(_currentTetromino))
            {
                ClearTetromino(_currentTetromino);

                // Show the tetromino
                _ghostTetromino = Utils.TetrominoUtils.CloneTetromino(_currentTetromino);

                UpdateGhostTetromino(_currentTetromino, _ghostTetromino);
                DrawGhostTetromino(_ghostTetromino);
                DrawTetromino(_currentTetromino);

                yield return(StartCoroutine(MoveTetromino()));
            }
            else
            {
                yield return(StartCoroutine(ShowGameOver()));
            }
        }