-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"editor.tabSize": 4, | ||
"liveServer.settings.port": 5501 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |