Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐ŸŒˆย ์นด๋“œ๊ฒŒ์ž„ ๋ฆฌํŒฉํ† ๋ง/๐Ÿฐํ† ์‹ฌ์•„ ์–ด๋”จ๋‹ˆ?!๐Ÿฐ #11

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0073c89
chores: gitignore
urjimyu Jun 9, 2023
24010ac
init
urjimyu Jun 9, 2023
ae43d0d
init
urjimyu Jun 9, 2023
3e015bf
init
urjimyu Jun 9, 2023
bbd1753
init
urjimyu Jun 9, 2023
e85e362
init
urjimyu Jun 9, 2023
96a0cf2
chore: gitignore updated
urjimyu Jun 9, 2023
06b6871
chore: created file for images
urjimyu Jun 9, 2023
3f3735b
chore: export ์ฒ˜๋ฆฌ
urjimyu Jun 9, 2023
ec66594
feat: created Button component
urjimyu Jun 9, 2023
13906e3
feat: created Header component
urjimyu Jun 9, 2023
67818da
feat: created Button component
urjimyu Jun 9, 2023
2626b3e
style: setting styles
urjimyu Jun 9, 2023
fca6110
style: add jpg image
urjimyu Jun 10, 2023
745ee08
chore: updated theme colors
urjimyu Jun 10, 2023
a573991
feat: added Header and Card in mainpage
urjimyu Jun 10, 2023
33fcf69
chore: fixed color
urjimyu Jun 10, 2023
767efdf
chores: ํ•„์š”์—†๋Š” ๋‚ด์šฉ ์‚ญ์ œ
urjimyu Jun 10, 2023
2ff1953
style: style updated
urjimyu Jun 10, 2023
4cb8914
delete: ํฐํŠธ ํŒŒ์ผ ์‚ญ์ œ
urjimyu Jun 10, 2023
0d129ba
feat: using atoms in Header
urjimyu Jun 10, 2023
6bdc48d
feat: created atom file for score and level
urjimyu Jun 10, 2023
ac38414
style: updated card style
urjimyu Jun 10, 2023
3df3753
feat: ์ด๋ฏธ์ง€ ํŒŒ์ผ์— isCorrect, isFlipped ์ถ”๊ฐ€
urjimyu Jun 10, 2023
aed3146
chore: ์Šคํƒ€์ผ ์ˆ˜์ •
urjimyu Jun 10, 2023
9ee9afc
feat: ๋ ˆ๋ฒจ์— ๋งž๊ฒŒ ์นด๋“œ ์„ž์–ด์„œ ๋„์›Œ์ฃผ๊ธฐ
urjimyu Jun 10, 2023
d6338ac
chore: ๋ชจ๋‘ ์†Œ๋ฌธ์ž๋กœ ๋ณ€๊ฒฝ
urjimyu Jun 10, 2023
1c1a338
style: added flip animation
urjimyu Jun 10, 2023
fdf7c20
feat: ํด๋ฆญ์‹œ ์นด๋“œ ๋’ค์ง‘์–ด์ง€๋„๋ก ์ˆ˜์ •์ค‘
urjimyu Jun 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

todo/.DS_Store

cardgame/src/.DS_Store

.DS_Store
14 changes: 14 additions & 0 deletions week3-ts/cardGameTS/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': 'warn',
},
}
24 changes: 24 additions & 0 deletions week3-ts/cardGameTS/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
12 changes: 12 additions & 0 deletions week3-ts/cardGameTS/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ํ† ์‹ฌ์•„ ์–ด๋”จ๋‹ˆ</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
31 changes: 31 additions & 0 deletions week3-ts/cardGameTS/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "cardgamets",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.12.1",
"recoil": "^0.7.7",
"styled-components": "^6.0.0-rc.3"
},
"devDependencies": {
"@types/react": "^18.0.37",
"@types/react-dom": "^18.0.11",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"@vitejs/plugin-react": "^4.0.0",
"eslint": "^8.38.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.3.4",
"typescript": "^5.0.2",
"vite": "^4.3.9"
}
}
1 change: 1 addition & 0 deletions week3-ts/cardGameTS/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions week3-ts/cardGameTS/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from "react";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import GlobalStyle from "./styles/GlobalStyle";
import { theme } from "./styles/theme";
import { ThemeProvider } from "styled-components";

import MainPage from "./pages/MainPage";

function App() {
return (
<ThemeProvider theme={theme}>
<GlobalStyle />
<BrowserRouter>
<Routes>
<Route path="/" element={<MainPage />} />
</Routes>
</BrowserRouter>
</ThemeProvider>
);
}

export default App;
74 changes: 74 additions & 0 deletions week3-ts/cardGameTS/src/assets/images/TOSIM.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const TOSIM = [
{
id: 1,
alt: "์‚ฌ๋ž‘-ํ† ์‹ฌ",
src: "https://item.kakaocdn.net/do/3247f87329f1a29e692a5f3e39c2c82382f3bd8c9735553d03f6f982e10ebe70",
flipped: false,
correct: false,
},
{
id: 2,
alt: "์กฐ์•„ํ•ฉ๋‹ˆ๋‹ค-ํ† ์‹ฌ",
src: "https://item.kakaocdn.net/do/3247f87329f1a29e692a5f3e39c2c8234022de826f725e10df604bf1b9725cfd",
flipped: false,
correct: false,
},
{
id: 3,
alt: "๋ฆฌ๋“ฌ-ํ† ์‹ฌ",
src: "https://item.kakaocdn.net/do/3247f87329f1a29e692a5f3e39c2c82341d1a2caccd0c566eab28b91e2e5d306",
flipped: false,
correct: false,
},
{
id: 4,
alt: "๋ณผ์‚ด-ํ† ์‹ฌ",
src: "https://item.kakaocdn.net/do/9c67797af35b26ee079c69b8d3c748648f324a0b9c48f77dbce3a43bd11ce785",
flipped: false,
correct: false,
},
{
id: 5,
alt: "ํ•˜ํŠธ-ํ† ์‹ฌ",
src: "https://item.kakaocdn.net/do/9c67797af35b26ee079c69b8d3c748649f17e489affba0627eb1eb39695f93dd",
flipped: false,
correct: false,
},
{
id: 6,
alt: "์—ด์ฐฝ-ํ† ์‹ฌ",
src: "https://item.kakaocdn.net/do/9c67797af35b26ee079c69b8d3c748644022de826f725e10df604bf1b9725cfd",
flipped: false,
correct: false,
},
{
id: 7,
alt: "์‘์›-ํ† ์‹ฌ",
src: "https://item.kakaocdn.net/do/9c67797af35b26ee079c69b8d3c74864a88f7b2cbb72be0bdfff91ad65b168ab",
flipped: false,
correct: false,
},
{
id: 8,
alt: "์น˜ํ‚จ-ํ† ์‹ฌ",
src: "https://item.kakaocdn.net/do/9c67797af35b26ee079c69b8d3c74864ac8e738cb631e72fdb9a96b36413984e",
flipped: false,
correct: false,
},
{
id: 9,
alt: "ํœด์‹-ํ† ์‹ฌ",
src: "https://item.kakaocdn.net/do/9c67797af35b26ee079c69b8d3c74864960f4ab09fe6e38bae8c63030c9b37f9",
flipped: false,
correct: false,
},
{
id: 10,
alt: "๋ฝ€๋ฝ€-ํ† ์‹ฌ",
src: "https://item.kakaocdn.net/do/9c67797af35b26ee079c69b8d3c74864effd194bae87d73dd00522794070855d",
flipped: false,
correct: false,
},
];

export default TOSIM;
1 change: 1 addition & 0 deletions week3-ts/cardGameTS/src/assets/images/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as tosim_background } from "./tosim_background.jpg";
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions week3-ts/cardGameTS/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions week3-ts/cardGameTS/src/components/common/Button/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import styled from "styled-components";
import { theme } from "../../../styles/theme";

const Button = styled.button`
width: 15%;
padding: 15px 0;

background-color: ${theme.colors.white_300};
color: ${theme.colors.pink_300};
font-family: "UhBeeJJIBBABBA";

border-radius: 20px;
box-shadow: ${({ theme }) => theme.shadow.type_1};
font-weight: 500;
`;

export default Button;
113 changes: 113 additions & 0 deletions week3-ts/cardGameTS/src/components/common/Card/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import Button from "../Button";
import * as Styled from "./style";
import { tosim_background } from "../../../assets/images";
import TOSIM from "../../../assets/images/TOSIM";
import { useEffect, useState } from "react";
import { useRecoilState } from "recoil";
import { LevelState, ScoreState } from "../../../recoil/atom";

//๋ฒ„ํŠผ์— ๋งž๋Š” ์นด๋“œ ๊ฐœ์ˆ˜ ๋„์›Œ์ฃผ๋Š” ํ•จ์ˆ˜(๊ฐœ์ˆ˜ + ๋žœ๋ค ์ง€์ •)
const EASY = 10;
const NORMAL = 14;
const HARD = 18;

interface CardItemProps {
id: number;
alt: string;
src: string;
correct: boolean;
flipped: boolean;
}

//์นด๋“œ ๋žœ๋ค์œผ๋กœ ์„ž๊ธฐ
const shuffleCards = (cardList: CardItemProps[]) => {
for (let i = cardList.length - 1; i > 0; i--) {
// eslint-disable-next-line prefer-const
let j = Math.floor(Math.random() * (i + 1));
[cardList[i], cardList[j]] = [cardList[j], cardList[i]];
}
};

//์นด๋“œ ๋‘ ๊ฐœ ๋ˆŒ๋ ธ์„ ๋•Œ๋งˆ๋‹ค ์ •๋‹ต์—ฌ๋ถ€ ํŒ๋‹จํ•˜๋Š” useEffect ํ•จ์ˆ˜

export const Card = () => {
const [level, setLevel] = useRecoilState(LevelState);
const [score, setScore] = useRecoilState(ScoreState);

const [cardList, setCardList] = useState<CardItemProps[]>(TOSIM);
const [flippedCards, setFlippedCards] = useState<number[]>([]);

const [isReset, setIsReset] = useState(false);

const toggleCardFlip = (card: CardItemProps) => {
if (flippedCards.length === 2) {
return;
}

// const updatedCard = { ...card, flipped: !card.flipped };
// if (!card.flipped && !card.correct) {
// return { ...card, flipped: true };
// }
// setCardList([])
};

//์„ž์€ ์นด๋“œ ์ค‘์—์„œ ๋ ˆ๋ฒจ์— ๋งž๋Š” ๊ฐœ์ˆ˜๋งŒํผ ์ž˜๋ผ์ฃผ๊ณ  ๋งŒ๋“ค๊ธฐ
const createCards = (level: number) => {
let newCardList = TOSIM.slice(0, level / 2);
newCardList = [...newCardList, ...newCardList];
setCardList(newCardList);
shuffleCards(cardList);

return cardList.map((card, index) => (
<Styled.CardItem
key={index}
correct={card.correct ? 1 : 0}
flipped={card.flipped ? 1 : 0}
>
{card.flipped ? (
<Styled.CardImgFront
className="cardFront flipped"
src={card.src}
alt={card.alt}
onClick={() => toggleCardFlip(card)}
/>
) : (
<Styled.CardImgBack
className="cardBack"
src={tosim_background}
alt="ํ† ์‹ฌ์นด๋“œ-๋’ท๋ฉด"
onClick={() => {
toggleCardFlip(card);
}}
/>
)}
</Styled.CardItem>
));
};

const onLevelClicked = (cardNums: number) => {
setLevel(cardNums);
setIsReset(true);
shuffleCards(TOSIM);
};

//๋ฆฌ์…‹ ์ฒ˜๋ฆฌํ•ด์ฃผ๋Š” useEffect(setIsReset ๊ฑฐ์ง“์œผ๋กœ ๋ฐ”๊ฟ”๋†”์•ผ ํ•จ)
useEffect(() => {
setLevel(level);
}, [level]);

useEffect(() => {
setIsReset(false);
}, [isReset]);

return (
<Styled.CardSection>
<Styled.Buttons>
<Button onClick={() => onLevelClicked(EASY)}>EASY</Button>
<Button onClick={() => onLevelClicked(NORMAL)}>NORMAL</Button>
<Button onClick={() => onLevelClicked(HARD)}>HARD</Button>
</Styled.Buttons>
<Styled.CardItemsSection>{createCards(level)}</Styled.CardItemsSection>
</Styled.CardSection>
);
};
Loading