보드게임판 데이터를 어떻게 가지고 있다가 그려줄까?
전체 배열 하나로 0 ~ 23 순서대로 칸 정보
라인별로 관리
특수칸, 기업칸들 칸 정보 따로
기업칸 표시 정보
그 외 특수 칸들
기업칸에서 1주당 가격은 계속해서 변동되는 정보이므로 서버에서 전체현황판 업데이트 이후 바뀐 수치가 렌더링 되어야 함. (+ 가격변동이 일어난 기업의 주식을 가지고 있는 모든 플레이어들의 개인현황판도 다 각각 업데이트 되어야 함) → 이걸 프론트에서 처리하는게 맞을까?
해결법: moveToken() 함수 자체를 async를 이용해 비동기 함수로 만들고 for문 끝에 await로 딜레이를 추가
const moveToken = async (주사위눈: number) => {
for (let i = 주사위눈; i > 0; i--) {
// ... 나머지 코드 ...
// 비동기 대기 (1초)
await new Promise(resolve => setTimeout(resolve, 1000));
}
};

변경 전

변경 후
const moveToken = async (주사위눈: number) => {
for (let i = 주사위눈; i > 0; i--) {
switch (direction.current) {
case 'top':
tokenCoordinates.current.y -= 6;
tokenRef.current!.style.transform = `translate(${tokenCoordinates.current.x}rem, ${tokenCoordinates.current.y}rem)`;
break;
case 'right':
tokenCoordinates.current.x += 6;
tokenRef.current!.style.transform = `translate(${tokenCoordinates.current.x}rem, ${tokenCoordinates.current.y}rem)`;
break;
case 'bottom':
tokenCoordinates.current.y += 6;
tokenRef.current!.style.transform = `translate(${tokenCoordinates.current.x}rem, ${tokenCoordinates.current.y}rem)`;
break;
case 'left':
tokenCoordinates.current.x -= 6;
tokenRef.current!.style.transform = `translate(${tokenCoordinates.current.x}rem, ${tokenCoordinates.current.y}rem)`;
break;
default:
break;
}
currentCell.current = (currentCell.current + 1) % 24;
const isCorner = currentCell.current % 6 === 0; // 0, 6, 12, 18 칸에서 방향 전환
if (isCorner) {
direction.current = changeDirection(direction.current);
}
await delay(200);
}
};
const moveToken = async (
주사위눈: number,
token: RefObject<HTMLDivElement>
) => {
const move = (x: number, y: number) => {
tokenCoordinates.current.x += x;
tokenCoordinates.current.y += y;
token.current!.style.transform = `translate(${tokenCoordinates.current.x}rem, ${tokenCoordinates.current.y}rem)`;
};
const directions = {
top: { x: 0, y: -6 },
right: { x: 6, y: 0 },
bottom: { x: 0, y: 6 },
left: { x: -6, y: 0 },
};
for (let i = 주사위눈; i > 0; i--) {
const directionData = directions[direction.current];
move(directionData.x, directionData.y);
currentCell.current = (currentCell.current + 1) % 24;
const isCorner = currentCell.current % 6 === 0; // 0, 6, 12, 18 칸에서 방향 전환
if (isCorner) {
direction.current = changeDirection(direction.current);
}
await delay(200);
}
};