-
Notifications
You must be signed in to change notification settings - Fork 0
/
memoria.html
64 lines (60 loc) · 2.66 KB
/
memoria.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jogo da memória</title>
<link rel="stylesheet" href="styleMemoria.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.min.js"></script>
</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>
const emojis = ["😅", "😅", "🤙" , "🤙", "🤬", "🤬", "🙀", "🙀", "👽", "👽",
"😴", "😴", "😝", "😝", "🤏", "🤏"]
var shuf_emojis = emojis.sort(() => (Math.random() > .5) ? 2 : -1);
for(var i = 0; i < emojis.length; i++){
let box = document.createElement('div')
box.className = 'item'
box.innerHTML = shuf_emojis[i]
box.onclick = function(){
this.classList.add('boxOpen')
setTimeout(function(){
if(document.querySelectorAll('.boxOpen').length > 1){
if(document.querySelectorAll('.boxOpen')[0].innerHTML ==
document.querySelectorAll('.boxOpen')[1].innerHTML){
document.querySelectorAll('.boxOpen')[0].classList.add
('boxMatch')
document.querySelectorAll('.boxOpen')[1].classList.add
('boxMatch')
document.querySelectorAll('.boxOpen')[1].classList.remove
('boxOpen')
document.querySelectorAll('.boxOpen')[0].classList.remove
('boxOpen')
if(document.querySelectorAll('.boxMatch').length == emojis.length){
confetti()
confetti()
confetti()
confetti()
confetti()
confetti()
confetti()
}
}else{
document.querySelectorAll('.boxOpen')[1].classList.remove
('boxOpen')
document.querySelectorAll('.boxOpen')[0].classList.remove
('boxOpen')
}
}
},500)
}
document.querySelector('.game').appendChild(box);
}
</script>
</body>
</html>