[C#] 纯文本查看 复制代码
/// <summary>
/// 给list赋值,得到点击位置周围相同的星星
/// </summary>
/// <param name="x">横坐标</param>
/// <param name="y">纵坐标</param>
/// <param name="dirction">判断的放向</param>
/// <param name="flag"></param>
void GetAround(int x, int y, Direction dirction = Direction.Null, int flag = 1)
{
if (starsColor[x, y] == StarColor.White)
return;
if (dirction == Direction.Null)
{
list.Clear();
list.Add(new StarInfo(x, y, starsColor[x, y], 1));
starsFlag[x, y] = 1;
if (x == 0 && y == 0)
{
GetAround(x, y, Direction.Right);
GetAround(x, y, Direction.Down);
}
else if (x == 0 && y == 9)
{
GetAround(x, y, Direction.Right);
GetAround(x, y, Direction.Up);
}
else if (x == 9 && y == 0)
{
GetAround(x, y, Direction.Left);
GetAround(x, y, Direction.Down);
}
else if (x == 9 && y == 9)
{
GetAround(x, y, Direction.Left);
GetAround(x, y, Direction.Up);
}
else if (x == 0)
{
GetAround(x, y, Direction.Up);
GetAround(x, y, Direction.Right);
GetAround(x, y, Direction.Down);
}
else if (x == 9)
{
GetAround(x, y, Direction.Left);
GetAround(x, y, Direction.Down);
GetAround(x, y, Direction.Up);
}
else if (y == 0)
{
GetAround(x, y, Direction.Right);
GetAround(x, y, Direction.Left);
GetAround(x, y, Direction.Down);
}
else if (y == 9)
{
GetAround(x, y, Direction.Left);
GetAround(x, y, Direction.Up);
GetAround(x, y, Direction.Right);
}
else
{
GetAround(x, y, Direction.Up);
GetAround(x, y, Direction.Down);
GetAround(x, y, Direction.Left);
GetAround(x, y, Direction.Right);
}
}
else if (dirction == Direction.Up)
{
for (int i = 0; i < list.Count; i++)
{
if (x == list[i].X && y - 1 == list[i].Y && starsColor[x, y - 1] == list[i].Color)
{
return;
}
}
if (starsColor[x, y] == starsColor[x, y - 1])
{
list.Add(new StarInfo(x, y - 1, starsColor[x, y - 1], 1));
starsFlag[x, y - 1] = 1;
if (x == 0 && y == 0)
{
GetAround(x, y - 1, Direction.Right);
}
else if (x == 9 && y == 0)
{
GetAround(x, y - 1, Direction.Left);
}
else if (x == 0 && y == 9)
{
GetAround(x, y - 1, Direction.Right);
GetAround(x, y - 1, Direction.Up);
}
else if (x == 9 && y == 9)
{
GetAround(x, y - 1, Direction.Up);
GetAround(x, y - 1, Direction.Left);
}
else if (x == 0)
{
if (y - 1 > 0)
{
GetAround(x, y - 1, Direction.Up);
}
GetAround(x, y - 1, Direction.Right);
}
else if (x == 9)
{
GetAround(x, y - 1, Direction.Left);
if (y - 1 > 0)
{
GetAround(x, y - 1, Direction.Up);
}
}
else if (y == 0)
{
GetAround(x, y - 1, Direction.Left);
GetAround(x, y - 1, Direction.Right);
}
else if (y == 9)
{
GetAround(x, y - 1, Direction.Left);
GetAround(x, y - 1, Direction.Right);
if (y - 1 > 0)
{
GetAround(x, y - 1, Direction.Up);
}
}
else
{
GetAround(x, y - 1, Direction.Left);
GetAround(x, y - 1, Direction.Right);
if (y - 1 > 0)
{
GetAround(x, y - 1, Direction.Up);
}
}
return;
}
else return;
}
else if (dirction == Direction.Down)
{
for (int i = 0; i < list.Count; i++)
{
if (x == list[i].X && y + 1 == list[i].Y && starsColor[x, y + 1] == list[i].Color)
{
return;
}
}
if (starsColor[x, y] == starsColor[x, y + 1])
{
list.Add(new StarInfo(x, y + 1, starsColor[x, y + 1], 1));
starsFlag[x, y + 1] = 1;
if (x == 0 && y == 0)
{
GetAround(x, y + 1, Direction.Right);
GetAround(x, y + 1, Direction.Down);
}
else if (x == 9 && y == 0)
{
GetAround(x, y + 1, Direction.Left);
GetAround(x, y + 1, Direction.Down);
}
else if (x == 0 && y == 9)
{
GetAround(x, y + 1, Direction.Right);
}
else if (x == 9 && y == 9)
{
GetAround(x, y + 1, Direction.Left);
}
else if (x == 0)
{
GetAround(x, y + 1, Direction.Right);
if (y + 1 < 9)
{
GetAround(x, y + 1, Direction.Down);
}
}
else if (x == 9)
{
GetAround(x, y + 1, Direction.Left);
if (y + 1 < 9)
{
GetAround(x, y + 1, Direction.Down);
}
}
else if (y == 0)
{
GetAround(x, y + 1, Direction.Left);
GetAround(x, y + 1, Direction.Right);
GetAround(x, y + 1, Direction.Down);
}
else if (y == 9)
{
GetAround(x, y + 1, Direction.Left);
GetAround(x, y + 1, Direction.Right);
}
else
{
if (y + 1 <= 9)
{
GetAround(x, y + 1, Direction.Left);
GetAround(x, y + 1, Direction.Right);
}
if (y + 1 < 9)
{
GetAround(x, y + 1, Direction.Down);
}
} return;
}
else return;
}
else if (dirction == Direction.Left)
{
for (int i = 0; i < list.Count; i++)
{
if (x - 1 == list[i].X && y == list[i].Y && starsColor[x - 1, y] == list[i].Color)
{
return;
}
}
if (starsColor[x, y] == starsColor[x - 1, y])
{
list.Add(new StarInfo(x - 1, y, starsColor[x - 1, y], 1));
starsFlag[x - 1, y] = 1;
if (x == 0 && y == 0)
{
GetAround(x - 1, y, Direction.Down);
}
else if (x == 9 && y == 0)
{
GetAround(x - 1, y, Direction.Left);
GetAround(x - 1, y, Direction.Down);
}
else if (x == 0 && y == 9)
{
GetAround(x - 1, y, Direction.Up);
}
else if (x == 9 && y == 9)
{
GetAround(x - 1, y, Direction.Up);
GetAround(x - 1, y, Direction.Left);
}
else if (x == 0)
{
GetAround(x - 1, y, Direction.Up);
GetAround(x - 1, y, Direction.Down);
}
else if (x == 9)
{
GetAround(x - 1, y, Direction.Left);
GetAround(x - 1, y, Direction.Down);
GetAround(x - 1, y, Direction.Up);
}
else if (y == 0)
{
if (x - 1 > 0)
{
GetAround(x - 1, y, Direction.Left);
}
GetAround(x - 1, y, Direction.Down);
}
else if (y == 9)
{
if (x - 1 > 0)
{
GetAround(x - 1, y, Direction.Left);
}
GetAround(x - 1, y, Direction.Up);
}
else
{
if (x - 1 > 0)
{
GetAround(x - 1, y, Direction.Left);
}
GetAround(x - 1, y, Direction.Up);
GetAround(x - 1, y, Direction.Down);
} return;
}
else return;
}
else if (dirction == Direction.Right)
{
for (int i = 0; i < list.Count; i++)
{
if (x + 1 == list[i].X && y == list[i].Y && starsColor[x + 1, y] == list[i].Color)
{
return;
}
}
if (starsColor[x, y] == starsColor[x + 1, y])
{
list.Add(new StarInfo(x + 1, y, starsColor[x + 1, y], 1));
starsFlag[x + 1, y] = 1;
if (x == 0 && y == 0)
{
GetAround(x + 1, y, Direction.Right);
GetAround(x + 1, y, Direction.Down);
}
else if (x == 9 && y == 0)
{
GetAround(x + 1, y, Direction.Down);
}
else if (x == 0 && y == 9)
{
GetAround(x + 1, y, Direction.Right);
GetAround(x + 1, y, Direction.Up);
}
else if (x == 9 && y == 9)
{
GetAround(x + 1, y, Direction.Up);
}
else if (x == 0)
{
GetAround(x + 1, y, Direction.Up);
GetAround(x + 1, y, Direction.Right);
GetAround(x + 1, y, Direction.Down);
}
else if (x == 9)
{
GetAround(x + 1, y, Direction.Down);
GetAround(x + 1, y, Direction.Up);
}
else if (y == 0)
{
if (x + 1 < 9)
{
GetAround(x + 1, y, Direction.Right);
}
GetAround(x + 1, y, Direction.Down);
}
else if (y == 9)
{
if (x + 1 < 9)
{
GetAround(x + 1, y, Direction.Right);
}
GetAround(x + 1, y, Direction.Up);
}
else
{
GetAround(x + 1, y, Direction.Down);
GetAround(x + 1, y, Direction.Up);
if (x + 1 < 9)
{
GetAround(x + 1, y, Direction.Right);
}
} return;
}
else return;
}
if (flag == 1)
{
DrawBox(list);
}
}