diff --git a/app/game/diceplane.tsx b/app/game/diceplane.tsx new file mode 100644 index 0000000..c4728ea --- /dev/null +++ b/app/game/diceplane.tsx @@ -0,0 +1,77 @@ +'use client'; + +import { useState } from 'react'; + +type PlaneCell = { id: number; x: number; y: number; type: string }; + +const PLANE_SIZE = { width: 9, height: 7 } as const; + +const CELL_TYPES = ['한잔', '안주', '모두한잔', '두잔', '벌칙1', '벌칙2'] as const; + +function randomType() { + return CELL_TYPES[Math.floor(Math.random() * CELL_TYPES.length)]; +} + +/** 시계방향 둘레 칸. 모서리는 한 번만 넣어서 9x7 기준 28칸이 된다. */ +function buildPerimeter(width: number, height: number): PlaneCell[] { + const cells: PlaneCell[] = []; + let id = 0; + + for (let x = 0; x < width; x++) { + cells.push({ id: id++, x, y: 0, type: randomType() }); + } + for (let y = 1; y < height; y++) { + cells.push({ id: id++, x: width - 1, y, type: randomType() }); + } + for (let x = width - 2; x >= 0; x--) { + cells.push({ id: id++, x, y: height - 1, type: randomType() }); + } + for (let y = height - 2; y >= 1; y--) { + cells.push({ id: id++, x: 0, y, type: randomType() }); + } + + return cells; +} + +export default function DicePlane() { + const [dicePlaneArray] = useState(() => + buildPerimeter(PLANE_SIZE.width, PLANE_SIZE.height), + ); + + return ( +