I am trying to change the color of a ball randomly however when I try to use the color variable to become the color of the solid brush it says that it is unassigned. "Use of unassigned local variable 'ballColour'"
xPos = xPos + GAP_SIZE;
int colour = rand.Next(1, 40);
Color ballColour;
if (colour >= 1 && colour <= 9)
{
ballColour = Color.Blue;
}
else if (colour >= 10 && colour <= 19)
{
ballColour = Color.Orange;
}
else if (colour >= 20 && colour <= 29)
{
ballColour = Color.Green;
}
else if (colour >= 30 && colour <= 39)
{
ballColour = Color.Red;
}
else if (colour == 40)
{
ballColour = Color.Purple;
}
SolidBrush ballColourBrush = new SolidBrush(ballColour); //This is the one that returns the error.
paper.FillEllipse(ballColourBrush, xPos, yPos, BALL_SIZE, BALL_SIZE);
xPos = xPos + BALL_SIZE;
Aucun commentaire:
Enregistrer un commentaire