feat: logic complete

added styling
This commit is contained in:
Mike 2024-08-06 17:03:59 -04:00
parent c8cd6c2076
commit 8398636f01
6 changed files with 29 additions and 25 deletions

Binary file not shown.

Binary file not shown.

View file

@ -38,6 +38,8 @@ function App() {
setMessage={setMessage}
setButtonText={setButtonText}
/>
<audio src="public/collect-5930.mp3" className="audio-right"></audio>
<audio src="public/incorrect.mp3" className="audio-wrong"></audio>
</>
);
}

View file

@ -9,7 +9,6 @@ export default function Card(props) {
</div>
<h2 className="card-title">{props.title}</h2>
</div>
<div className="card-back"></div>
</div>
);
}

View file

@ -24,9 +24,6 @@ class GameLogic {
handleClick(key) {
this.checkClickResult(key);
const cards = document.querySelectorAll(".card");
cards.forEach((card) => card.classList.add("flip", "card-back", "hidden"));
const tempCards = this.cards.map((card) => {
if (card.key === key) {
card.clicked = true;
@ -35,10 +32,10 @@ class GameLogic {
});
this.setCards(tempCards);
this.randomArrayOrder();
const cards = document.querySelectorAll(".card");
cards.forEach((card) => card.classList.add("flip", "hidden"));
setTimeout(() => {
cards.forEach((card) =>
card.classList.remove("flip", "card-back", "hidden"),
);
cards.forEach((card) => card.classList.remove("flip", "hidden"));
}, 1000);
}
@ -67,17 +64,19 @@ class GameLogic {
}
checkClickResult(key) {
if (!this.checkClick(key)) {
// Check if this move wins
if (this.score + 1 === this.cards.length) {
this.setMessage("You won!\n12/12 right");
this.setButtonText("Play again?");
this.resetGame();
return;
}
// go through game
if (!this.checkClick(key)) {
// Play a Sound for the right Answer
document.querySelector(".audio-right").play();
this.setScore(this.score + 1);
} else {
document.querySelector(".audio-wrong").play();
this.handleLoss();
}
}

View file

@ -13,26 +13,30 @@
}
.flip {
animation: flipCard 1s;
animation: flipCard 2.4s;
}
@keyframes flipCard {
from {
color: gray;
}
20% {
color: gray;
transform: rotateY(180deg);
background-color: black;
}
to {
rotatey: 180deg;
transform: rotateY(-180deg);
visibility: visible;
}
}
.card-front .card-back {
-webkit-backface-visibility: hidden; /* Safari */
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.card-back {
background: gray;
color: gray;
transform: rotateY(180deg);
}
.hidden img {
.hidden img,
.hidden .card-title {
visibility: hidden;
}