private CollisionType ResolveMoveLeft(IFigure figure) { var collision = CollisionType.None; figure.ForEachNonEmptyCell((i, j) => { var absoluteLeft = figure.Placement.Left + i; var absoluteTop = figure.Placement.Top + j; if (absoluteLeft < 0) { collision = CollisionType.Borders; return false; } if (!_gameField.GroundView[absoluteLeft, absoluteTop].IsEmptyCell()) { collision = CollisionType.Ground; return false; } return true; }); return collision; }
public void AttachFigureToTheGround(IFigure figure) { figure.ForEachNonEmptyCell((i, j) => { var x = figure.Placement.Left + i; var y = figure.Placement.Top + j; var cell = _sprite[x, y]; if (!cell.IsEmptyCell()) throw new InvalidOperationException("can't attach figure to ground - it's already filled"); _sprite[x, y] = figure[i, j]; _peak = Math.Min(_peak, y); }); var fullRows = FindFullRows(); foreach (var rowNumber in fullRows) RemoveRow(rowNumber); var rowsDeleted = fullRows.Length; //todo: notify multiplayer that n rows were deleted }
private CollisionType ResolveMoveDown(IFigure figure) { var collision = CollisionType.None; figure.ForEachNonEmptyCell((i, j) => { var absoluteX = figure.Placement.Left + i; var absoluteY = figure.Placement.Top + j; if (absoluteY > _gameField.Size.Height - 1) { collision = CollisionType.Ground; return false; } if (absoluteY < 0) return true; if (_gameField.GroundView[absoluteX, absoluteY].IsEmptyCell()) return true; collision = CollisionType.Ground; if (figure.Placement.Top == 1) // a little bad assumpotion that figures always start at 0, and thatn moves down by 1 collision = CollisionType.Critical; return false; }); return collision; }