33,007
社区成员
发帖
与我相关
我的任务
分享
private int CheckLine(Point A, Point B, HashSet<int> Map)
{
int x1 = A.X; int y1 = A.Y; int x2 = B.X; int y2 = B.Y; int re = 0;
float increx = 0; float increy = 0; float x = 0; float y = 0;
int steps = 0; int i = 0;
if (Math.Abs(x2 - x1) > Math.Abs(y2 - y1))
{
steps = Math.Abs(x2 - x1);
}
else
{
steps = Math.Abs(y2 - y1);
}
increx = (float)(x2 - x1) / steps;
increy = (float)(y2 - y1) / steps;
x = x1;
y = y1;
for (i = 1; i <= steps; i++)
{
//putpixel(x,y,color); //在(x,y)处,以color色画点
if (!CheckMap(Map, (int)x, (int)y))
{ re++; }
x += increx;
y += increy;
}
return re;
}
private int CheckLine( Point A, Point B)
{
int re = 0;
int Dx = Math.Abs(B.X - A.X);
int Dy = Math.Abs(B.Y - A.Y);
while (Dx >= 0)
{
int YY = 0;
int x = A.X + Dx * Math.Sign(B.X - A.X);
while (Dy >= 0)
{
int y = A.Y + Dx * Math.Sign(B.Y - A.Y);
//输出结果
Console.writeLine("格子"+x+","+y+"命中");
bool IsFinish =false;
if (A.X != B.X)
{
IsFinish = Math.Abs((double)YY) > Math.Abs((double)(A.Y - B.Y) / (double)(A.X - B.X));
if (IsFinish)
{
break;
}
}
YY++;
Dy--;
}
Dx --;
}
return re;
}