Example #1
0
    void Update()
    {
        if (_currentFigure == null)
        {
            GameObject figure = _tetrisCollection.GetRandomFigure();
            _currentFigure = _tetrisGraphic.DrawFigure(figure);


            if (!_tetrisGrid.CheckForCollisionWithFigureOrFloor(_currentFigure))
            {
                _userInterface.LoadMainMenu();
            }
        }

        #region Input
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            _figureMovement.MoveFigureHorizontally(_currentFigure, -1);
        }
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            _figureMovement.MoveFigureHorizontally(_currentFigure, 1);
        }
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            _figureMovement.RotateFigure(_currentFigure);
        }
        if (Input.GetKey(KeyCode.Escape))
        {
            _userInterface.PrintMenu();
        }
        #endregion

        if (_counter >= 1)
        {
            if (_figureMovement.FallFigure(_currentFigure))
            {
                _tetrisGrid.DeleteFullRows();
                _currentFigure = null;
            }

            _counter = 0;
        }

        _counter += Speed * Time.deltaTime;
    }