private List <SlotController> GetLineForDestroy(string lineType, int lineIndex) { if (lineType != HORIZONTAL_LINE && lineType != VERTICAL_LINE) { throw new Exception("Incorrect type of line, use const strings of this class"); } var lineList = new List <SlotController>(); var isCreatingLine = false; for (int i = 1; i < FieldSize; i++) { var currentX = lineType == HORIZONTAL_LINE ? i : lineIndex; var currentY = lineType == VERTICAL_LINE ? i : lineIndex; var deltaX = lineType == HORIZONTAL_LINE ? 1 : 0; var deltaY = lineType == VERTICAL_LINE ? 1 : 0; SlotController currentSlot = GetSlotByPosition(currentX, currentY); if (currentSlot.IsSameTypeNeighborWith(currentX - deltaX, currentY - deltaY)) { if (currentSlot.IsSameTypeNeighborWith(currentX + deltaX, currentY + deltaY) && !isCreatingLine) //add current and prev if next same { isCreatingLine = true; lineList.Add(currentSlot); lineList.Add(GetSlotByPosition(currentX - deltaX, currentY - deltaY)); } else if (isCreatingLine) { lineList.Add(currentSlot); } } else { isCreatingLine = false; } } if (!(lineList.Count == 0 || lineList.Count > 2)) { throw new Exception("Invalid line item count"); } if (lineList.Any(slot => slot.TrashController.IsAbleToFall())) { return(new List <SlotController>()); } return(lineList); }