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} setMessage={setMessage}
setButtonText={setButtonText} 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> </div>
<h2 className="card-title">{props.title}</h2> <h2 className="card-title">{props.title}</h2>
</div> </div>
<div className="card-back"></div>
</div> </div>
); );
} }

View file

@ -24,9 +24,6 @@ class GameLogic {
handleClick(key) { handleClick(key) {
this.checkClickResult(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) => { const tempCards = this.cards.map((card) => {
if (card.key === key) { if (card.key === key) {
card.clicked = true; card.clicked = true;
@ -35,10 +32,10 @@ class GameLogic {
}); });
this.setCards(tempCards); this.setCards(tempCards);
this.randomArrayOrder(); this.randomArrayOrder();
const cards = document.querySelectorAll(".card");
cards.forEach((card) => card.classList.add("flip", "hidden"));
setTimeout(() => { setTimeout(() => {
cards.forEach((card) => cards.forEach((card) => card.classList.remove("flip", "hidden"));
card.classList.remove("flip", "card-back", "hidden"),
);
}, 1000); }, 1000);
} }
@ -67,17 +64,19 @@ class GameLogic {
} }
checkClickResult(key) { checkClickResult(key) {
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)) { 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;
}
// Play a Sound for the right Answer
document.querySelector(".audio-right").play();
this.setScore(this.score + 1); this.setScore(this.score + 1);
} else { } else {
document.querySelector(".audio-wrong").play();
this.handleLoss(); this.handleLoss();
} }
} }

View file

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