那么我如何才能从特定距离获得某个点的x,y坐标?如何从特定距离获得x,y坐标
所以
public static Location2D DistanceToXY(Location2D current, Directions dir, int steps) {
ushort x = current.X;
ushort y = current.Y;
for (int i = 0; i < steps; i++) {
switch (dir) {
case Directions.North:
y--;
break;
case Directions.South:
y++;
break;
case Directions.East:
x++;
break;
case Directions.West:
x--;
break;
case Directions.NorthWest:
x--;
y--;
break;
case Directions.SouthWest:
x--;
y++;
break;
case Directions.NorthEast:
x++;
y--;
break;
case Directions.SouthEast:
x++;
x++;
break;
}
}
return new Location2D(x, y);
}
就是我在这里做什么是正确的?
取决于在你走什么方向 – 2012-02-18 06:11:12
难道这取决于你在行进的方向? – Oleksi 2012-02-18 06:11:31
你的意思是哪些地点可以使用?如果是这样,你可以递归地做。 – Ovilia 2012-02-18 06:19:20