Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory pair game files by Yuliiadd #517

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
removed styles from app.js
  • Loading branch information
Yuliiadd committed Sep 24, 2022
commit 4a9034d6054a0c7a79b4c0f298703d4c0dafcdb2
2 changes: 1 addition & 1 deletion submissions/YuliiaDyka/memory-pair-game/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Card {
renderCard() {
let card = document.createElement('div');
card.classList.add('card');
card.innerHTML = `<img src="img/${this.imgId}.png" alt="${this.imgId}" class="card__img">
card.innerHTML = `<img src="img/${this.imgId}.png" alt="${this.imgId}" class="back__side">
<img src="img/paw.png" alt="Front side of cards" class="front__side">`;
field.append(card);
};
Expand Down
19 changes: 6 additions & 13 deletions submissions/YuliiaDyka/memory-pair-game/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,18 @@ restart.addEventListener("click", render);
// function fliping cards & create arrays of opened cards

function flipTheCard(e) {
if (e.target.className == "game__field" || e.target.className == "card__img") return;
if (e.target.className == "game__field" || e.target.className == "back__side") return;
let frontSide = e.target;
openedCards = document.querySelectorAll(".open__card");
if (frontSide.tagName === "IMG" && openedCards.length < 2) {
let openedCard = e.target.parentElement;
openedCard.classList.add("open__card");
openedCards = document.querySelectorAll(".open__card");
let backSide = e.target.previousElementSibling;
frontSide.style.transform = "rotateY(180deg)"
backSide.style.transform = "rotateY(360deg)"
backSide.style.opacity = "100";
let backSide = frontSide.previousElementSibling;
frontSide.classList.toggle("rotate180");
backSide.classList.toggle("rotate360");
openedCardsSrc.push(backSide.src.slice(-6));
};

if (openedCards.length == 2) {
checkThePairs();
};
Expand All @@ -41,10 +39,6 @@ function flipTheCard(e) {
// checking opened cards

function checkThePairs() {
console.log(openedCards[0].firstElementChild.src);
console.log(openedCards[1].firstElementChild.src);
console.log(foldedPairs);

if (openedCards[0].firstElementChild.src == openedCards[1].firstElementChild.src && foldedPairs < 6) {
foldedPairs++;
score.textContent = foldedPairs;
Expand Down Expand Up @@ -76,12 +70,11 @@ function checkThePairs() {
restart.classList.add("btn__red");
};


} else if (openedCardsSrc[0] !== openedCardsSrc[1]) {
setTimeout(() => openedCards.forEach(card => {
card.classList.remove("open__card");
card.firstElementChild.style.transform = "rotateY(180deg)";
card.lastElementChild.style.transform = "rotateY(360deg)";
card.firstElementChild.classList.toggle('rotate360');
card.lastElementChild.classList.toggle("rotate180");
}), 500);
openedCards = document.querySelectorAll(".open__card");
openedCardsSrc = [];
Expand Down
26 changes: 22 additions & 4 deletions submissions/YuliiaDyka/memory-pair-game/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,16 @@ body {

.card {
position: relative;
transition: transform 0.5s;
transform-style: preserve-3d;
cursor: pointer;
}

.card__face.is-flipped {
transform: rotateY(180deg);
}

.card__img,
.back__side,
.front__side {
position: absolute;
max-width: 100%;
Expand All @@ -207,11 +214,10 @@ body {
top: 0;
transition: 0.2s;
backface-visibility: hidden;
cursor: pointer;
}

.card__img {
opacity: 0;
.back__side {
transform: rotateY(180deg);
}

.front__side {
Expand All @@ -223,7 +229,19 @@ body {
height: 120px;
color: white;
border-radius: 20px;
}

.rotate180 {
transform: rotateY(180deg);
}

.rotate360 {
transform: rotateY(360deg);
}

.hidden {
opacity: 0;
transition: 0.3s;
}

.footer {
Expand Down