Skip to content

Commit

Permalink
feat: 전역 상태 레벨에 따라서 tile 갯수 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Bumang-Cyber committed Mar 12, 2024
1 parent 66e8fad commit 8780f9a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
12 changes: 7 additions & 5 deletions src/components/Game/TileMapPanel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { useState } from "react";
import styled from "styled-components";
import { type LevelKeyType } from "../../../types/level";
import generateTileMap from "../../../utils/generateTileMap";
import { levels } from "../../../constants/level";

import Tile from "./Tile";
import useLevelSwitch from "../../../hooks/useLevelSwitch";

const TileMapPanel = () => {
const [currentLevel] = useState<LevelKeyType>("Beginner");
const tileMapArr = generateTileMap(levels[currentLevel].X, levels[currentLevel].Y);
const { currentLevelStatus } = useLevelSwitch();
console.log(currentLevelStatus, "currentLevelStatus");
const { X, Y } = currentLevelStatus;

const tileMapArr = generateTileMap(X, Y);
console.log(tileMapArr);

return (
Expand Down
31 changes: 30 additions & 1 deletion src/constants/level.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
export const levels = {
import { LevelKeyType } from "./../types/level";

interface LevelsProps {
Beginner: {
TITLE: LevelKeyType;
X: number;
Y: number;
MINE: number;
};
Intermediate: {
TITLE: LevelKeyType;
X: number;
Y: number;
MINE: number;
};
Expert: {
TITLE: LevelKeyType;
X: number;
Y: number;
MINE: number;
};
Custom: {
TITLE: LevelKeyType;
X: number;
Y: number;
MINE: number;
};
}

export const levels: LevelsProps = {
Beginner: {
TITLE: "Beginner",
X: 8,
Expand Down
11 changes: 0 additions & 11 deletions src/hooks/useLevelSwitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@ const useLevelSwitch = () => {
dispatchLevel(change(name));
}
};
// const xTileAmountByLevels = levelValues.map(({ X }) => ({ X }));
// const yTileAmountByLevels = levelValues.map(({ Y }) => ({ Y }));

// 최근 레벨
// 레벨들의 키
//
// 최근 레벨의 X타일 갯수
// 최근 레벨의 Y타일 갯수
// 최근 레벨의 지뢰 갯수
// dispatch (레벨 변환)
// LevelKeyType

return { currentLevel, currentLevelStatus, levelSwitchHandler, levels, levelKeys, levelValues };
};
Expand Down
4 changes: 2 additions & 2 deletions src/utils/generateTileMap.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { TileType } from "../types/tile";

const generateTileMap = (X: number, Y: number) => {
const arr = new Array(X).fill([]).map(() => {
return new Array(Y).fill(null).map(
const arr = new Array(Y).fill([]).map(() => {
return new Array(X).fill(null).map(
() =>
({
isOpened: false,
Expand Down

0 comments on commit 8780f9a

Please sign in to comment.