mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2024-12-26 14:20:43 -05:00
feat: logic complete
added styling
This commit is contained in:
parent
c8cd6c2076
commit
8398636f01
6 changed files with 29 additions and 25 deletions
BIN
memory-game/mg-frontend/public/collect-5930.mp3
Normal file
BIN
memory-game/mg-frontend/public/collect-5930.mp3
Normal file
Binary file not shown.
BIN
memory-game/mg-frontend/public/incorrect.mp3
Normal file
BIN
memory-game/mg-frontend/public/incorrect.mp3
Normal file
Binary file not shown.
|
@ -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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ export default function Card(props) {
|
|||
</div>
|
||||
<h2 className="card-title">{props.title}</h2>
|
||||
</div>
|
||||
<div className="card-back"></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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.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)) {
|
||||
// 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);
|
||||
} else {
|
||||
document.querySelector(".audio-wrong").play();
|
||||
this.handleLoss();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue