Skip to content

Commit

Permalink
feat: implementando jogo de memória
Browse files Browse the repository at this point in the history
  • Loading branch information
ulyssesq committed Dec 14, 2023
1 parent a9201ec commit 407b967
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.tabSize": 4,
"liveServer.settings.port": 5501
}
18 changes: 18 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./src/styles/global.css">
<link rel="stylesheet" href="./src/styles/main.css">
<title>Jogo da Memória</title>
</head>
<body>
<div class="container">
<h2>JOGO DA MEMÓRIA</h2>
<div class="game"></div>
<button class="reset" onclick="window.location.reload()">RESET GAME</button>
</div>
<script defer src="./src/scripts/engine.js"></script>
</body>
</html>
44 changes: 44 additions & 0 deletions src/scripts/engine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const emojis = [
"🐒","🐒","🐻","🐻","🐘","🐘","🐇","🐇","🦖","🦖", "🐊","🐊","🦈","🦈","🐷","🐷"
];

let openCards = [];

let shuffleEmojis = emojis.sort(() => Math.random() > 0.5 ? 2 : -1);

for(let i = 0; i < emojis.length; i++){
let box = document.createElement("div");
box.className = "item";
box.innerHTML = shuffleEmojis[i];
box.onclick = handleClick;
document.querySelector(".game").appendChild(box);
}

function handleClick() {
if (openCards.length < 2) {
this.classList.add("boxOpen");
openCards.push(this);
}

if (openCards.length == 2) {
setTimeout(checkMatch, 500);
}
}

function checkMatch() {
if (openCards[0].innerHTML === openCards[1].innerHTML) {
openCards[0].classList.add("boxMatch");
openCards[1].classList.add("boxMatch");
}
else {
openCards[0].classList.remove("boxOpen");
openCards[1].classList.remove("boxOpen");
}

openCards = [];

if (document.querySelectorAll(".boxMatch").length == emojis.length) {
alert("Você venceu!");
}
}

7 changes: 7 additions & 0 deletions src/styles/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
outline: none;
font-family: monospace;
}
91 changes: 91 additions & 0 deletions src/styles/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #fc1e8a;
user-select: none;
}

.container {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
gap: 30px;
background: linear-gradient(
325deg,
#03301e 0%,
#7303c0 30%,
#ec38bc 70%,
#fdeff9 100%
);
padding: 40px 60px;
}

h2 {
font-size: 2em;
color: #fff;
text-transform: uppercase;
letter-spacing: 0.1em;
}

.reset {
padding: 15px 20px;
width: 100%;
color: #000;
background-color: #fff;
border: none;
font-size: 1.5em;
letter-spacing: 0.1em;
text-transform: uppercase;
cursor: pointer;
font-weight: 600;
}

.reset:focus {
color: #ec38bc;
background-color: #262809;
}

.game {
width: 430px;
height: 430px;
display: flex;
flex-wrap: wrap;
gap:10px;
transform-style: preserve-3d;
perspective: 500px;
}

.item {
position: relative;
width: 100px;
height: 100px;
display: flex;
align-items: center;
justify-content: center;
background-color: #fff;
font-size: 3em;
transform: rotateY(180deg);
transition: 0.25s;
}

.item::after {
content: "";
position: absolute;
inset: 0;
background: #404040;
transition: 0.25s;
transform: rotateY(0deg);
backface-visibility: hidden;
}

.item.boxOpen {
transform: rotateY(0deg);
}

.boxOpen::after,
.boxMatch::after {
transform: rotateY(180deg);
}

0 comments on commit 407b967

Please sign in to comment.