Beispiel #1
0
    // Start is called before the first frame update
    void Start()
    {
        _panelRT      = (RectTransform)GetComponent("RectTransform");
        _smallPanelRT = (RectTransform)NextTetrominoPanel.GetComponent("RectTransform");
        _refTile      = (GameObject)Resources.Load("Tile");

        _panelWidth       = _panelRT.sizeDelta.x;
        _panelHeight      = _panelRT.sizeDelta.y;
        _smallPanelWidth  = _smallPanelRT.sizeDelta.x;
        _smallPanelHeight = _smallPanelRT.sizeDelta.y;

        _tileWidth       = _panelWidth / 10;
        _tileHeight      = _panelHeight / 20;
        _smallTileWidth  = 20;
        _smallTileHeight = 20;

        _gameBoard = new TetrisGameBoard(_panelWidth, _panelHeight, _tileWidth, _tileHeight);
        _random    = new System.Random();

        _gameover = false;

        _nextTetrominoEnum = GetRandomTetromino();
        _nextTetromino     = SmallTetrominoFromEnum(_nextTetrominoEnum);
        _nextTetromino.UpdateTilesPositions();
        SpawnNewTetromino();
    }
Beispiel #2
0
    Tetromino TetrominoFromEnum(TetrominoesEnum te)
    {
        switch (te)
        {
        case TetrominoesEnum.I:
            return(new TetrominoI(NewTile, _panelWidth, _panelHeight, _tileWidth, _tileHeight));

        case TetrominoesEnum.J:
            return(new TetrominoJ(NewTile, _panelWidth, _panelHeight, _tileWidth, _tileHeight));

        case TetrominoesEnum.L:
            return(new TetrominoL(NewTile, _panelWidth, _panelHeight, _tileWidth, _tileHeight));

        case TetrominoesEnum.O:
            return(new TetrominoO(NewTile, _panelWidth, _panelHeight, _tileWidth, _tileHeight));

        case TetrominoesEnum.S:
            return(new TetrominoS(NewTile, _panelWidth, _panelHeight, _tileWidth, _tileHeight));

        case TetrominoesEnum.T:
            return(new TetrominoT(NewTile, _panelWidth, _panelHeight, _tileWidth, _tileHeight));

        case TetrominoesEnum.Z:
            return(new TetrominoZ(NewTile, _panelWidth, _panelHeight, _tileWidth, _tileHeight));

        default:
            throw new Exception();
        }
    }
Beispiel #3
0
    void SpawnNewTetromino()
    {
        _tetromino = TetrominoFromEnum(_nextTetrominoEnum);

        for (int i = 0; i < 4; i++)
        {
            UnityEngine.Object.Destroy(_nextTetromino.Tiles[i]);
        }

        _nextTetrominoEnum = GetRandomTetromino();
        _nextTetromino     = SmallTetrominoFromEnum(_nextTetrominoEnum);
        _nextTetromino.UpdateTilesPositions();
    }