void KS_sample(NORMAL &player, NORMAL board[][19])
{
bool isleftMove = true;
bool isrightMove = true;
bool isupMove = true;
bool isdownMove = true;
if (player.state == 1)
{
if ((GetKeyState(VK_LEFT) & 0x8000) && player.x >= 5)
{
for (int i = 0; i < 13; ++i)
{
for (int j = 0; j < 19; ++j)
{
if (board[i][j].y <= player.y + 35 &&
player.y + 40 - 35 <= board[i][j].y + 50 &&
board[i][j].state == 1 &&
-4 <= player.x - (board[i][j].x + 50) &&
4 >= player.x - (board[i][j].x + 50))
{
isleftMove = false;
break;
}
}
if (!isleftMove)
break;
}
if (isleftMove)
{
player.x -= 5;
}
}
if ((GetKeyState(VK_RIGHT) & 0x8000) && player.x + 50 <= 955)
{
for (int i = 0; i < 13; ++i)
{
for (int j = 0; j < 19; ++j)
{
if (board[i][j].y <= player.y + 35 &&
player.y + 40 - 35 <= board[i][j].y + 50 &&
board[i][j].state == 1 &&
-4 <= (board[i][j].x) - (player.x + 40) &&
4 >= (board[i][j].x) - (player.x + 40))
{
isrightMove = false;
break;
}
}
if (!isrightMove)
break;
}
if (isrightMove)
{
player.x += 5;
}
}
if ((GetKeyState(VK_UP) & 0x8000) && player.y >= 5)
{
for (int i = 0; i < 13; ++i)
{
for (int j = 0; j < 19; ++j)
{
if (board[i][j].x <= player.x + 35 &&
player.x + 40 - 35 <= board[i][j].x + 50 &&
board[i][j].state == 1 &&
-4 <= (player.y) - (board[i][j].y + 50) &&
4 >= (player.y) - (board[i][j].y + 50))
{
isupMove = false;
break;
}
}
if (!isupMove)
break;
}
if (isupMove)
{
player.y -= 5;
}
}
if ((GetKeyState(VK_DOWN) & 0x8000) && player.y + 50 <= 655)
{
for (int i = 0; i < 13; ++i)
{
for (int j = 0; j < 19; ++j)
{
if (board[i][j].x <= player.x + 35 &&
player.x + 40 - 35 <= board[i][j].x + 50 &&
board[i][j].state == 1 &&
-4 <= (board[i][j].y) - (player.y + 40) &&
4 >= (board[i][j].y) - (player.y + 40))
{
isdownMove = false;
break;
}
}
if (!isdownMove)
break;
}
if (isdownMove)
{
player.y += 5;
}
}
}
}
------------------------------
요렇게 바꿔줌
bool check(NORMAL& player, NORMAL board[][19], string direction)
{
int height = player.y;
int width = player.x;
if (direction == "right") width += 40;
if (direction == "down") height += 40;
if (direction == "left") width -= 5;
if (direction == "right") width += 5;
if (direction == "up") height -= 5;
if (direction == "down") height += 5;
int y = height / 50;
int x = width / 50;
if (x >= 19 && y >= 13)
return false;
if (board[y][x].state == 1)
return false;
return true;
}
void KS_sample1(NORMAL &player, NORMAL board[][19])
{
if (player.state == 1) {
if ((GetKeyState(VK_LEFT) & 0x8000) && check(player, board, "left")) player.x = max(player.x - 5, 5);
if ((GetKeyState(VK_RIGHT) & 0x8000) && check(player, board, "right")) player.x = min(player.x + 5, 955 - 50);
if ((GetKeyState(VK_UP) & 0x8000) && check(player, board, "up")) player.y = max(player.y - 5, 5);
if ((GetKeyState(VK_DOWN) & 0x8000) && check(player, board, "down")) player.y = min(player.y + 5, 656 - 50);
}
}
잘했지?
존나 극혐성격 가진듯. 이딴걸 자랑이라고
Enum을 씁시당
주석 없는 클-린 코드 인정합니다.
다만 몇몇 매직 넘버만 어케 했으면 더 좋았을 듯
펜져님 말처럼 Enum ㄱㄱ
리팩토링