You didn't tell us in which way your method
CheckHorizontal(..)
does not work and I find it not very intuitive to read, so I'll just show you how I would do it:
Declare an array of X/Y-tuples which describe the translation from the position at which the method currently "looks at" to the next position, for 0°, 45°, 90° and 135°. For the tuples I'd use a custom class to avoid the "Item1", "Item2" property-names of the inbuilt Tuple<,> class. I'm setting the origin of the coordinate system in the lower left corner.
array directionSteps = { {0, -1}, {1, -1}, {1, 0}, {1, 1} }
The remainder explained in comments:
int xCenter = ...
int yCenter = ...
int tileColor = ...
foreach (directionStep in directionSteps)
{
int matchingTiles = 1;
for (int directionUpDown = -1; directionUpDown <= 1; directionUpDown += 2)
{
int xStep = directionStep.X * directionUpDown;
int yStep = directionStep.Y * directionUpDown;
for (int distance = 1; distance <= 5; distance++)
{
int x = xCenter + xStep * distance;
int y = yCenter + yStep * distance;
if (IsOutsideOfGrid(x, y))
break;
if (Grid[x, y] == tileColor)
matchingTiles++;
else
break;
}
}
if (matchingTiles >= 4)
}