public void ApplyGravity() { var newRows = new List<BlockRow>(); var lowerRow = _rows.FirstOrDefault(); foreach(var higherRow in _rows.Skip(1)) { if (higherRow == null || lowerRow == null) return; var newHigherRow = new BlockRow(); var newLowerRow = new BlockRow(); var higherRowEnumerator = higherRow.Cells.GetEnumerator(); var lowerRowEnumerator = lowerRow.Cells.GetEnumerator(); int x_position = 0; while(higherRowEnumerator.MoveNext() || lowerRowEnumerator.MoveNext()) { if (lowerRowEnumerator.Current && higherRowEnumerator.Current) newHigherRow.AddBlock(x_position); if (lowerRowEnumerator.Current || higherRowEnumerator.Current) newLowerRow.AddBlock(x_position); x_position++; } newRows.Add(newLowerRow); lowerRow = newHigherRow; } _rows = newRows; }
public BlockBoard(IEnumerable<IEnumerable<bool>> grid) { _rows = new List<BlockRow>(); foreach (var row in grid) { var blockRow = new BlockRow(row.Count()); var yPosition = 0; foreach (var cell in row) { if (cell) blockRow.AddBlock(yPosition); yPosition++; } _rows.Add(blockRow); } }
public void ApplyGravity() { var newRows = new List <BlockRow>(); var lowerRow = _rows.FirstOrDefault(); foreach (var higherRow in _rows.Skip(1)) { if (higherRow == null || lowerRow == null) { return; } var newHigherRow = new BlockRow(); var newLowerRow = new BlockRow(); var higherRowEnumerator = higherRow.Cells.GetEnumerator(); var lowerRowEnumerator = lowerRow.Cells.GetEnumerator(); int x_position = 0; while (higherRowEnumerator.MoveNext() || lowerRowEnumerator.MoveNext()) { if (lowerRowEnumerator.Current && higherRowEnumerator.Current) { newHigherRow.AddBlock(x_position); } if (lowerRowEnumerator.Current || higherRowEnumerator.Current) { newLowerRow.AddBlock(x_position); } x_position++; } newRows.Add(newLowerRow); lowerRow = newHigherRow; } _rows = newRows; }
public BlockBoard(IEnumerable <IEnumerable <bool> > grid) { _rows = new List <BlockRow>(); foreach (var row in grid) { var blockRow = new BlockRow(row.Count()); var yPosition = 0; foreach (var cell in row) { if (cell) { blockRow.AddBlock(yPosition); } yPosition++; } _rows.Add(blockRow); } }