diff --git a/src/App.css b/src/App.css index b9d355d..31674db 100644 --- a/src/App.css +++ b/src/App.css @@ -1,7 +1,7 @@ #root { max-width: 1280px; margin: 0 auto; - padding: 2rem; + padding: 0; text-align: center; } diff --git a/src/App.jsx b/src/App.jsx index 5d62758..8b9eab6 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,16 +1,21 @@ -import { useState } from "react"; -import reactLogo from "./assets/react.svg"; -import viteLogo from "/vite.svg"; +import Coin from "./component/Coin"; +import Upgrade from "./component/Upgrade"; +import { useState, useEffect } from "react"; import "./App.css"; function App() { - const [count, setCount] = useState(0); - const name = "류승찬"; + const [coin, setCoin] = useState(0); + const [power, setPower] = useState(1); + + useEffect(() => { + alert(`Power가 ${power}로 업그레이드 되었습니다!`); + }, [power]); return ( - <> - 화이팅 - +
+ + +
); } diff --git a/src/component/Coin.jsx b/src/component/Coin.jsx new file mode 100644 index 0000000..da15d0a --- /dev/null +++ b/src/component/Coin.jsx @@ -0,0 +1,17 @@ +import { useRef } from "react"; + +export default function Coin({ coin, setCoin, power }) { + const div = useRef(null); + + const earn = () => { + if (div.current) div.current.style.backgroundColor = `rgba(${Math.random()*255}, ${Math.random()*255}, ${Math.random()*255}, ${Math.random()%0.5})`; + setCoin(coin + power); + }; + + return ( +
+

{coin}$

+ +
+ ); +} \ No newline at end of file diff --git a/src/component/Upgrade.jsx b/src/component/Upgrade.jsx new file mode 100644 index 0000000..add8d82 --- /dev/null +++ b/src/component/Upgrade.jsx @@ -0,0 +1,17 @@ +export default function Upgrade({ coin, setCoin, power, setPower }) { + const handleUpgrade = () => { + if (coin >= (10 * power)) { + setCoin(coin - (10 * power)); + setPower(power + 1); + } else { + alert(`${10 * power}원이 필요합니다!`); + } + }; + + return ( +
+

Power: {power}

+ +
+ ); +} \ No newline at end of file diff --git a/src/index.css b/src/index.css index 08a3ac9..4c48adc 100644 --- a/src/index.css +++ b/src/index.css @@ -13,6 +13,10 @@ -moz-osx-font-smoothing: grayscale; } +* { + box-sizing: border-box; +} + a { font-weight: 500; color: #646cff;