这部分代码行为不端。我想从一组 7 种颜色的列表中绘制一个用户定义的圆圈网格,每个圆圈都有一种随机颜色。随机数生成器应该这样做。圆圈的网格画得很好,它的颜色让我很伤心。我似乎每个网格最多有两种颜色,前十种是一种颜色,其余的是第二种颜色。这很奇怪,因为代码应该循环通过颜色生成器,然后画一个圆圈并重复。请帮我找出麻烦的台词,自己花了太长时间尝试!
忽略对 JEWEL_HEIGHT 和类似的引用,它们只是与程序相关的变量名。
int columns = int.Parse(textBoxColumns.Text);
int rows = int.Parse(textBoxRows.Text);
for (int y = 0; (y < rows * 20); y += JEWEL_HEIGHT)
{
for (int x = 0; (x < columns * 20); x += JEWEL_WIDTH)
{
Color brushColor = (Color.Red);
Random randGen = new Random();
int randColor = randGen.Next(7);
if (randColor == 0)
brushColor = (Color.Red);
else if (randColor == 1)
brushColor = (Color.Orange);
else if (randColor == 2)
brushColor = (Color.Yellow);
else if (randColor == 3)
brushColor = (Color.Green);
else if (randColor == 4)
brushColor = (Color.Blue);
else if (randColor == 5)
brushColor = (Color.Indigo);
else if (randColor == 6)
brushColor = (Color.Violet);
Graphics paper = pictureBoxJewels.CreateGraphics();
SolidBrush brush = new SolidBrush(brushColor);
paper.FillEllipse(brush, x, y, JEWEL_WIDTH, JEWEL_HEIGHT);