onClick(event, props.setScore, props.score)}
+ onClick={(event) =>
+ onClick(event, props.clicked, props.setScore, props.score)
+ }
data-cardname={props.title}
>
@@ -19,8 +21,9 @@ function Image(props) {
return
;
}
-function onClick(event, setScore, score) {
+function onClick(event, clicked, setScore, score) {
// implement something to handle the things ID
setScore(score + 1);
+ clicked = true;
console.log(event.currentTarget.dataset.cardname);
}
diff --git a/memory-game/mg-frontend/src/components/footer.jsx b/memory-game/mg-frontend/src/components/footer.jsx
new file mode 100644
index 0000000..1334832
--- /dev/null
+++ b/memory-game/mg-frontend/src/components/footer.jsx
@@ -0,0 +1,7 @@
+export default function Footer() {
+ return (
+
+ );
+}
diff --git a/memory-game/mg-frontend/src/components/gameboard.jsx b/memory-game/mg-frontend/src/components/gameboard.jsx
index 8b9403b..03f1b2d 100644
--- a/memory-game/mg-frontend/src/components/gameboard.jsx
+++ b/memory-game/mg-frontend/src/components/gameboard.jsx
@@ -4,29 +4,50 @@ import "../styles/gameboard.css";
export default function GameBoard(props) {
const [cards, setCards] = useState([]);
+
useEffect(() => {
fetchCards({ setCards });
}, []);
return (
-
- {cards.map((item) => {
- return (
-
- );
- })}
-
+ <>
+ {props.gameStarted ? (
+
+ {cards.map((item) => {
+ console.log(item.topic, item.clicked);
+ return (
+
+ );
+ })}
+
+ ) : null}
+ >
);
}
async function fetchCards({ setCards }) {
- const cards = await fetch("http://localhost:8000/");
- setCards(await cards.json());
+ const cards = await fetch("http://localhost:8000/cards");
+ const jsonCards = await cards.json();
+
+ let gameCards = await jsonCards.map((c) => {
+ return { ...c, clicked: false, key: crypto.randomUUID() };
+ });
+
+ setCards(gameCards);
+}
+
+function shuffleCards(arr) {
+ for (let i = arr.length - 1; i > 0; i--) {
+ let j = Math.floor(Math.random() * (i + 1));
+ [arr[i], arr[j]] = [arr[j], arr[i]];
+ return arr;
+ }
}
diff --git a/memory-game/mg-frontend/src/components/scoreboard.jsx b/memory-game/mg-frontend/src/components/scoreboard.jsx
index fa14822..3203b78 100644
--- a/memory-game/mg-frontend/src/components/scoreboard.jsx
+++ b/memory-game/mg-frontend/src/components/scoreboard.jsx
@@ -2,9 +2,13 @@ import "../styles/scoreboard.css";
export default function Scoreboard(props) {
return (
-
-
SCORE: {props.score}
-
HIGH SCORE: {props.highscore}
-
+ <>
+ {props.gameStarted ? (
+
+
SCORE: {props.score}
+
HIGH SCORE: {props.highscore}
+
+ ) : null}
+ >
);
}
diff --git a/memory-game/mg-frontend/src/styles/button.css b/memory-game/mg-frontend/src/styles/button.css
new file mode 100644
index 0000000..3143038
--- /dev/null
+++ b/memory-game/mg-frontend/src/styles/button.css
@@ -0,0 +1,59 @@
+:root {
+ /* Grays */
+ --lightest-gray: 208, 21%, 93%;
+ --lighter-gray: 210, 16%, 76%;
+ --light-gray: 208, 12%, 58%;
+ --dark-gray: 207, 12%, 43%;
+ --darker-gray: 209, 15%, 28%;
+
+ --dark-blue: 246, 87%, 30%;
+ --blue: 219, 100%, 57%;
+ --light-blue: 219, 100%, 69%;
+
+ --green: 158, 95%, 34%;
+ --green-hover: 158, 95%, 28%;
+}
+
+.btn {
+ border-radius: 0.4rem;
+ padding: 1rem;
+ cursor: pointer;
+ text-decoration: none;
+ display: inline-block;
+ border: none;
+ font-size: 1.2rem;
+ flex: 1;
+}
+
+.btn:hover {
+ /* background-color: hsl(var(--dark-gray)); */
+}
+
+.normal-btn {
+ background-color: hsl(var(--light-gray));
+ transition:
+ background-color 500ms ease-in-out,
+ color 500ms ease-in-out;
+}
+
+.normal-btn:hover {
+ background-color: hsl(var(--dark-gray));
+ color: hsl(var(--lighter-gray));
+}
+
+.submit-btn {
+ background-color: hsl(var(--green));
+ transition: background-color 600ms;
+}
+
+.submit-btn:hover {
+ background-color: hsl(var(--green-hover));
+}
+
+.clear-btn {
+ background-color: hsl(var(--lighter-gray));
+ transition: background-color 600ms;
+}
+.clear-btn:hover {
+ background-color: hsl(var(--light-gray));
+}