private void CheckLinesToClear() { if (!LinesToClear.Any()) { for (int row = 0; row < TowerData.GetLength(0); row++) { bool isCleared = true; for (int col = 0; col < TowerData.GetLength(1); col++) { if (TowerData[row, col] == BlockValue.Empty || TowerData[row, col] == BlockValue.Cleared) { isCleared = false; continue; } } if (isCleared) { LinesToClear.Add(row); ClearState = ClearState.Mark; } } MarkLinesForClear(); } }
private void MoveLinesDown() { if (LinesToClear.Any()) { Thread.Sleep(100); int linesToMove = 0; for (int row = LinesToClear.Max(); row > 0; row--) { if (LinesToClear.Contains(row)) { linesToMove++; } else { for (int col = 0; col < TowerData.GetLength(1); col++) { if (TowerData[row, col] != BlockValue.Empty) { BlockValue tempVal = TowerData[row, col]; TowerData[row, col] = BlockValue.Empty; TowerData[row + linesToMove, col] = tempVal; } } } } LinesToClear.Clear(); ClearState = ClearState.Check; } }
public List <int> ForceDown() { if (forzarBajada) { if (this.DoesFitIn(indexCurrentPiece, indexCurrentRotation, currentX, currentY + 1)) { currentY++; } else { //clavar la pieza en el lugar for (int x = 0; x < 4; x++) { for (int y = 0; y < 4; y++) { if (tetromino[indexCurrentPiece][Rotate(x, y, indexCurrentRotation)] != '.') { char letra = 'A'; letra += (char)indexCurrentPiece; field[currentX + x, currentY + y] = letra; } } } //fijarse si no hay algun tetris for (int y = 0; y < 4; y++) { if (currentY + y < fieldHeight - 1) { bool IsALine = true; for (int x = 1; x < fieldWidth - 1; x++) { if (field[x, currentY + y] == ' ') { IsALine = false; break; } } //si hay una linea cmabiarla a === y despues eliminarlas xd if (IsALine) { for (int x = 1; x < fieldWidth - 1; x++) { field[x, currentY + y] = '='; } LinesToClear.Add(currentY + y); } } } //elegir nueva pieza indexCurrentPiece = random.Next(0, 7); indexCurrentRotation = 0; currentX = fieldWidth / 2; currentY = 0; //y si la pieza no entra EN LA PANTALLA gameOver = (!this.DoesFitIn(indexCurrentPiece, indexCurrentRotation, currentX, currentY)); } } return(LinesToClear); }
public bool extra() { if (LinesToClear.Count != 0) { masAlto = LinesToClear[LinesToClear.Count - 1]; masBajo = LinesToClear[0]; for (int i = 0; i < LinesToClear.Count; i++) { int xd = LinesToClear[i]; for (int j = 1; j < fieldWidth - 1; j++) { field[j, xd] = ' '; } LineasLimpiadas++; if (LineasLimpiadas % 10 == 0) { if (speed >= 5) { speed--; } } } Score += ((1 << LinesToClear.Count) * 10); LinesToClear.Clear(); noInput = true; return(false); } if (noInput) { noInput = false; int margen = masAlto - masBajo + 1; //margen entre las lineas borradas y las q tienen q bajar for (int i = masAlto; i >= 0 + margen; i--) { for (int j = 1; j < fieldWidth - 1; j++) { field[j, i] = field[j, i - margen]; } } //cuando termina de eliminar las lineas reseteamos esto para la proxima masAlto = 0; masBajo = 0; return(false); } return(true); }
private void MarkLinesForClear() { if (LinesToClear.Any()) { foreach (int line in LinesToClear) { for (int col = 0; col < TowerData.GetLength(1); col++) { if (TowerData[line, col] != BlockValue.Cleared) { TowerData[line, col] = BlockValue.Cleared; } } } ClearState = ClearState.Clear; } }
private int ClearLines() { if (LinesToClear.Any()) { Thread.Sleep(100); foreach (int line in LinesToClear) { for (int col = 0; col < TowerData.GetLength(1); col++) { TowerData[line, col] = BlockValue.Empty; } } ClearState = ClearState.Move; } return(LinesToClear.Count()); }