那麼我如何才能從特定距離獲得某個點的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