From e2c013191143f5bca39c08dd8b862b718af9d7c2 Mon Sep 17 00:00:00 2001 From: mlnwns Date: Tue, 7 May 2024 14:10:42 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=8B=A8=EC=96=B4=20=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=EB=A7=88=EB=8B=A4=20=EB=B0=B0=EC=97=B4=EC=97=90=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=EB=90=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.css | 42 ----------------------- src/App.jsx | 98 ++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 66 insertions(+), 74 deletions(-) delete mode 100644 src/App.css diff --git a/src/App.css b/src/App.css deleted file mode 100644 index b9d355d..0000000 --- a/src/App.css +++ /dev/null @@ -1,42 +0,0 @@ -#root { - max-width: 1280px; - margin: 0 auto; - padding: 2rem; - text-align: center; -} - -.logo { - height: 6em; - padding: 1.5em; - will-change: filter; - transition: filter 300ms; -} -.logo:hover { - filter: drop-shadow(0 0 2em #646cffaa); -} -.logo.react:hover { - filter: drop-shadow(0 0 2em #61dafbaa); -} - -@keyframes logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} - -@media (prefers-reduced-motion: no-preference) { - a:nth-of-type(2) .logo { - animation: logo-spin infinite 20s linear; - } -} - -.card { - padding: 2em; -} - -.read-the-docs { - color: #888; -} diff --git a/src/App.jsx b/src/App.jsx index b8b8473..328dd6b 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,35 +1,69 @@ -import { useState } from 'react' -import reactLogo from './assets/react.svg' -import viteLogo from '/vite.svg' -import './App.css' +import { useState, useEffect } from "react"; +import WordInput from "./components/WordInput"; +import WordArea from "./components/WordArea"; -function App() { - const [count, setCount] = useState(0) +const fruits = [ + "apple", + "banana", + "cherry", + "avocado", + "blueberry", + "coconut", + "grape", + "lime", + "kiwi", + "lemon", + "mango", + "peach", + "pear", + "strawberry", + "watermelon", + "tomato", + "melon", +]; + +const App = () => { + const [words, setWords] = useState([]); + const [isGameOver, setIsGameOver] = useState(false); + + useEffect(() => { + if (isGameOver) return; + + const wordAdder = setInterval(() => { + if (words.length < 10) { + const newWord = fruits[Math.floor(Math.random() * fruits.length)]; + setWords((prevWords) => [...prevWords, newWord]); + } else { + setIsGameOver(true); + alert("게임 종료!"); + clearInterval(wordAdder); + } + }, 2000); + + return () => clearInterval(wordAdder); + }, [words, isGameOver]); + + const handleWordSubmit = (inputWord) => { + setWords(words.filter((word) => word !== inputWord)); + }; + + const resetGame = () => { + setWords([]); + setIsGameOver(false); + }; + + useEffect(() => { + if (isGameOver) { + resetGame(); + } + }, [isGameOver]); return ( - <> -
- - Vite logo - - - React logo - -
-

Vite + React

-
- -

- Edit src/App.jsx and save to test HMR -

-
-

- Click on the Vite and React logos to learn more -

- - ) -} - -export default App +
+ + +
+ ); +}; + +export default App;