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

MISSION6 / 곽민준 #43

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/reset.min.css"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
</head>
Expand Down
42 changes: 0 additions & 42 deletions src/App.css

This file was deleted.

98 changes: 66 additions & 32 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.jsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
)
}

export default App
<div className="center-container">
<WordArea words={words} />
<WordInput onWordSubmit={handleWordSubmit} />
</div>
);
};

export default App;
12 changes: 12 additions & 0 deletions src/components/WordArea.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// components/WordArea.js
const WordArea = ({ words }) => {
return (
<div className="word-area">
{words.map((word, index) => (
<div key={index}>{word}</div>
))}
</div>
);
};

export default WordArea;
15 changes: 15 additions & 0 deletions src/components/WordInput.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const WordInput = ({ onWordSubmit }) => {
const handleSubmit = (e) => {
e.preventDefault();
onWordSubmit(e.target.elements.wordInput.value);
e.target.elements.wordInput.value = "";
};

return (
<form onSubmit={handleSubmit}>
<input name="wordInput" className="word-input" type="text" />
</form>
);
};

export default WordInput;
78 changes: 18 additions & 60 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,68 +1,26 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
.word-input {
padding: 0.7rem 30rem 0.7rem 1rem;
margin-top: 3rem;
text-align: left;
}

body {
margin: 0;
.center-container {
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
flex-direction: column;
align-items: center;
}

h1 {
font-size: 3.2em;
line-height: 1.1;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
.word-area {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
width: 100%;
background-color: rgb(178, 199, 237);
height: 24rem;
width: 100%;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
.word-area div {
margin: 0 1rem;
}