Skip to content

Commit

Permalink
feat: 성공 후 레벨 전환 시 플레이 상태 초기화 안 되는 문제 해결, 물음표 상태에서 open 시 물음표 마크가 남는 …
Browse files Browse the repository at this point in the history
…현상 해결
  • Loading branch information
Bumang-Cyber committed Mar 13, 2024
1 parent a0c623c commit 06f31a4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/components/Game/TileMapPanel/Tile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const Tile = ({ item, tileMapArr, onSetTileMap, rowIndex, colIndex }: TileProps)
}

if (isQuestioned) {
console.log(isFlagged, isMined, isOpened, isQuestioned, mineNearby, "?ITEM");
return (
<TileContainer $color={tileColor} $isOpened={isOpened} onClick={tileLeftClickHandler} onContextMenu={tileRightClickHandler}>
<QuestionIcon className="icon" />
Expand Down
12 changes: 8 additions & 4 deletions src/hooks/useLevelSwitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { change } from "@store/levelSlice";
import { type RootState } from "@store/index";
import { type LevelKeyType, type LevelValueType } from "@/types/level";
import { levels } from "@/constants/level";
import usePlayingSwitch from "./usePlayingSwitch";

const useLevelSwitch = () => {
// useLevelSwitch 훅으로 정리하기 (커스텀 레벨까지)
const { playingSwitchHandler } = usePlayingSwitch();
const dispatchLevel = useDispatch();
const currentLevel = useSelector((state: RootState) => {
return state.levels.value;
Expand All @@ -17,11 +18,14 @@ const useLevelSwitch = () => {

const currentLevelStatus = levelValues.find(({ Y, TITLE }) => TITLE === currentLevel && Y)!;

const levelSwitchHandler = (name: LevelKeyType) => {
if (name === "Custom") {
const levelSwitchHandler = (level: LevelKeyType) => {
if (level === "Custom") {
// 커스텀 훅 정리하기
// useLevelSwitch 훅으로 정리하기 (커스텀 레벨까지)
return;
} else {
dispatchLevel(change(name));
playingSwitchHandler("stale");
dispatchLevel(change(level));
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useTileSwitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const useTileSwitch = ({ item, tileMapArr, onSetTileMap, rowIndex, colIndex }: u
return;
}

detectByBfs(rowIndex, colIndex, tileMapArr);
detectByBfs(rowIndex, colIndex, copy);
onSetTileMap(copy);
};

Expand Down
1 change: 1 addition & 0 deletions src/utils/detectByBfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Queue } from "./queue";
const detectByBfs = (Y: number, X: number, tileMapArr: TileType[][]) => {
const queue = new Queue();

tileMapArr[Y][X].isQuestioned = false;
queue.enqueue([Y, X]);
while (queue.getLength() !== 0) {
const cur = queue.dequeue();
Expand Down

0 comments on commit 06f31a4

Please sign in to comment.