<aside> 💡

좌우 이동기능도 만들어보자

그러나 마찬가지로 문제 발생

void moveLeft(int& curX, int& curY) {
	int nextX = curX - 1;
	int nextY = curY;
	if (checkBoundary(nextY, nextX)) {
		curX--;
	}
}

void moveRight(int& curX, int& curY) {
	int nextX = curX + 1;
	int nextY = curY;
	if (checkBoundary(nextY, nextX)) {
		curX++;
	}
}

	while (true) {
		timer++;

		if (GetKeyInput() == 75) {
			cout << "left key is pressed\\n";
			moveLeft(curBlock_startX, curBlock_startY);
		}

		if (GetKeyInput() == 77) {
			cout << "right key is pressed\\n";
			moveRight(curBlock_startX, curBlock_startY);
		}

수정 후 코드

void MoveLeft(int& curX, int& curY) {
	int nextX = curX - 1;
	int nextY = curY;
	if (CheckBoundary(nextY, nextX)) {
		curX--;
	}
}

void MoveRight(int& curX, int& curY) {
	int nextX = curX + 1;
	int nextY = curY;
	if (CheckBoundary(nextY, nextX)) {
		curX++;
	}
}

void HandleKeyInput() {
	if (GetKeyInput() == 75) {
		cout << "left key is pressed\\n";
		KeyManager::GetInstance().LeftKeyPressed();
	}

	if (GetKeyInput() == 77) {
		cout << "right key is pressed\\n";
		KeyManager::GetInstance().RightKeyPressed();
	}
}

void ApplyKeyMove() {
	if (KeyManager::GetInstance().IsLeftKeyPressed()) {
		MoveLeft(curBlock_startX, curBlock_startY);
	}

	else if (KeyManager::GetInstance().IsRightKeyPressed()) {
		MoveRight(curBlock_startX, curBlock_startY);
	}
}