Skip to content

Instantly share code, notes, and snippets.

@mohemohe
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohemohe/9218330 to your computer and use it in GitHub Desktop.
Save mohemohe/9218330 to your computer and use it in GitHub Desktop.
/// <summary>
/// 方向を返します
/// </summary>
/// <returns>0.0〜3.5までで表される方向</returns>
/// <param name="dx">x軸方向の移動量(右が正)</param>
/// <param name="dy">y軸方向の移動量(下が正)</param>
static double ReturnDirection(int dx, int dy)
{
if (dx == 0 && dy == 0) // 移動してないなら
{
return 0.0; // 当然0だよね
}
int x = Math.Abs(dx - 2); // x軸の左を3, 右を1にする(これで既に仕様通り)
int y = dy + 1; // y軸の上を0, 下を2にする(これで既に仕様通り)
if (dx == 0) // x軸方向に移動してないなら
{
return (double)y; // yだけ返してあげる
}
else if (dy == 0) // y軸方向に移動してないなら
{
return (double)x; // xだけ返してあげる
}
int min;
if (x < y) { // 小さい方をminに代入する
min = x;
}
else
{
min = y;
}
return (double)(min + 0.5); // 0.5足せば斜めの出来上がり
//// 出来上がってない
//// 具体的には北西(x=-1,y=-1で0.5を返してしまう)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment