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; } }
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()); }