private bool PerformLineOperations() { ICollection <int> fullLines = new LinkedList <int>(); for (int y = 0; y < GameRules.Height; y++) { int x; for (x = 0; x < GameRules.Width; x++) { if (!_settledBlocks.ContainsKey(new Vector2Int(x, y))) { break; } } if (x == GameRules.Width) { fullLines.Add(y); } } if (fullLines.Count == 0) { return(false); } // Clear stage... foreach (var y in fullLines) { for (int x = 0; x < GameRules.Width; x++) { _settledBlocks.Remove(new Vector2Int(x, y)); LineClear?.Invoke(y); } } // Shift stage... for (int y = 0; y < GameRules.Height; y++) { var currentY = y; var freeSlotsAmountBelow = fullLines.Count(i => i < currentY); for (int x = 0; x < GameRules.Width; x++) { var index = new Vector2Int(x, y); if (_settledBlocks.TryGetValue(index, out var block)) { _settledBlocks.Remove(index); var newIndex = index + Vector2Int.down * freeSlotsAmountBelow; block.Location = newIndex; _settledBlocks[newIndex] = block; } } } return(true); }
private void PlayLineClear(int numLines) { LineClear?.Invoke(this, new IntegerEventArgs(numLines)); }