public bool ProceedTurn() { //checking gameOver int count = 0; foreach (Vector2Int pos in m_currentTetrimino.GetCurrentCellsPositions()) { if (!m_grid.PositionIsInsideGrid(pos)) { count++; } if (count >= m_currentTetrimino.GetCurrentCellsPositions().Count) { return(false); } } //increment turnsCount m_turnsCount++; //check if turns will add difficulty : increment level //level up = diminish stepDuration if (m_turnsCount % m_numberOfTurnToLevelUp == 0) { IncrementLevel(); } //check if there are new lines created int linesCount = m_grid.ProceedTurn(); //this will absorb current tetri GrandPointsForLines(linesCount); m_currentLines += linesCount; return(m_grid.OnInstantiateTetrimino(InstantiateNewTetrimino())); //then create the new tetri }
//returns number of lines (0 to 4) public int UpdateGrid( bool _absorbTetrimino = false) { List<int> linesYIndex = new List<int>(); //will store lines to remove List<Vector2Int> previousTetriminoCells = m_currentTetrimino.GetPreviousCellsPositions(); List<Vector2Int> newTetriminoCells = m_currentTetrimino.GetCurrentCellsPositions(); //clear old ones foreach(Vector2Int _pos in previousTetriminoCells) { if(PositionIsInsideGrid(_pos)) { m_gridTab[_pos.x, _pos.y].SetCellType(Cell.eCellType.EMPTY_CELL); m_gridTab[_pos.x, _pos.y].SetCellTetriminoType(Tetrimino.eTetriminoType.BLANK); } } //set new ones foreach(Vector2Int _pos in newTetriminoCells) { if(PositionIsInsideGrid(_pos)) { m_gridTab[_pos.x, _pos.y].SetCellType(_absorbTetrimino ? Cell.eCellType.BUSY_CELL : Cell.eCellType.TETRIMINO_CELL); m_gridTab[_pos.x, _pos.y].SetCellTetriminoType(m_currentTetrimino.GetTetriminoType()); //check lines (maybe redundant but doesn't cost much...) if(_absorbTetrimino) { if(IsMakingALine(_pos.y)) { if(!linesYIndex.Contains(_pos.y)) linesYIndex.Add(_pos.y); } } } } //find lower line to remove int lowerLineYtoRemove = m_gridSizeY; foreach (int lineIndex in linesYIndex) { if (lineIndex < lowerLineYtoRemove) lowerLineYtoRemove = lineIndex; } //then remove X time the same line for(int i = 0; i < linesYIndex.Count; i++) { RemoveLine(lowerLineYtoRemove); } RefreshRendering(); return linesYIndex.Count; }