From a30a666e9eef57b4dd457a73f52ffa3d73c6aaf2 Mon Sep 17 00:00:00 2001 From: haerong22 Date: Tue, 23 Mar 2021 19:59:48 +0900 Subject: [PATCH] =?UTF-8?q?react=20web=20game=20:=20=EC=A7=80=EB=A2=B0=20?= =?UTF-8?q?=EA=B0=AF=EC=88=98=20=ED=91=9C=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- react_webgame/main/MineSearch.jsx | 27 +++++++++++++++++++++++++++ react_webgame/main/Td.jsx | 4 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/react_webgame/main/MineSearch.jsx b/react_webgame/main/MineSearch.jsx index 9c2bd9ec..2ab3f0ce 100644 --- a/react_webgame/main/MineSearch.jsx +++ b/react_webgame/main/MineSearch.jsx @@ -92,6 +92,33 @@ const reducer = (state, action) => { const tableData = [...state.tableData]; tableData[action.row] = [...state.tableData[action.row]]; tableData[action.row][action.cell] = CODE.OPENED; + let around = []; // 주변 칸의 값을 담을 배열 + if (tableData[action.row - 1]) { + // 클릭한 칸의 윗줄이 있을 경우 + around = around.concat( + tableData[action.row - 1][action.cell - 1], + tableData[action.row - 1][action.cell], + tableData[action.row - 1][action.cell + 1] + ); + } + around = around.concat( + // 클릭한 칸의 좌, 우 + tableData[action.row][action.cell - 1], + tableData[action.row][action.cell + 1] + ); + if (tableData[action.row + 1]) { + // 클릭한 칸의 아랫줄이 있을 경우 + around = around.concat( + tableData[action.row + 1][action.cell - 1], + tableData[action.row + 1][action.cell], + tableData[action.row + 1][action.cell + 1] + ); + } + // 선택한 칸의 주변 칸의 갯수 + const count = around.filter((v) => + [CODE.MINE, CODE.FLAG_MINE, CODE.QUESTION_MINE].includes(v) + ).length; + tableData[action.row][action.cell] = count; return { ...state, tableData, diff --git a/react_webgame/main/Td.jsx b/react_webgame/main/Td.jsx index 6b82fb69..c8b8fd86 100644 --- a/react_webgame/main/Td.jsx +++ b/react_webgame/main/Td.jsx @@ -55,7 +55,7 @@ const getTdText = (code) => { case CODE.QUESTION: return "?"; default: - return ""; + return code || ""; } }; @@ -111,7 +111,7 @@ const Td = ({ rowIndex, cellIndex }) => { return; } }, - [tableData[rowIndex][cellIndex]] + [tableData[rowIndex][cellIndex], halted] ); return (