int winLength = 5;
Color? CheckForWin(Label[,] board,
int col, int row, int cou, int columnI, int rowI)
{
if (cou < winLength)
{
return null;
}
// Initialize from the first cell
int colorCou = 1;
// Color of unclicked label
Color newColor = board[row, col].BackColor;
// Decrement executed before the value is used.
while (--cou > 0)
{
col += columnI;
row += rowI;
// Color of clicked label
Color clickedColor = board[row, col].BackColor;
// If label unclicked, change its color
if (newColor != clickedColor)
{
// Switched colors, so reset for this cell to be the first of the label string
colorCou = 1;
newColor = clickedColor;
}
// If there are 5 labels in a row and they are not transparent, return the winning color
else if (++colorCou == winLength && clickedColor != Color.Transparent)
{
return clickedColor;
}
}
return null;
}
}
I am confused about what the if statement cou < winLength means and why does it return nothing? Does it simply maintain that cou is under 5 and then returns a win if it is not?
Aucun commentaire:
Enregistrer un commentaire