-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
131 lines (116 loc) · 3.02 KB
/
Copy pathindex.html
File metadata and controls
131 lines (116 loc) · 3.02 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Memory Flip Game</title>
<style>
body {
margin: 0;
font-family: 'Segoe UI', sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: linear-gradient(to right, #1e3c72, #2a5298);
color: white;
}
.game-board {
display: grid;
grid-template-columns: repeat(4, 100px);
grid-gap: 15px;
padding: 20px;
background-color: rgba(255, 255, 255, 0.1);
border-radius: 20px;
box-shadow: 0 0 25px rgba(0,0,0,0.5);
}
.card {
width: 100px;
height: 100px;
perspective: 800px;
cursor: pointer;
}
.inner-card {
position: relative;
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: transform 0.6s ease;
}
.flipped .inner-card {
transform: rotateY(180deg);
}
.front, .back {
position: absolute;
width: 100%;
height: 100%;
border-radius: 10px;
backface-visibility: hidden;
display: flex;
align-items: center;
justify-content: center;
font-size: 2rem;
background: #fff;
color: #333;
box-shadow: 0 4px 6px rgba(0,0,0,0.2);
}
.front {
background-color: #444;
color: white;
}
.back {
transform: rotateY(180deg);
background-color: #00ffcc;
}
.card:hover .front {
background-color: #888;
transition: 0.3s;
}
</style>
</head>
<body>
<div class="game-board" id="gameBoard"></div>
<script>
const emojis = ["🔥", "⚡", "🌟", "💎", "🎯", "🎮", "🚀", "👑"];
const gameBoard = document.getElementById('gameBoard');
let cards = [...emojis, ...emojis]; // duplicate for pairs
let flipped = [];
let lockBoard = false;
// shuffle
cards.sort(() => 0.5 - Math.random());
cards.forEach((emoji) => {
const card = document.createElement('div');
card.classList.add('card');
card.innerHTML = `
<div class="inner-card">
<div class="front">?</div>
<div class="back">${emoji}</div>
</div>
`;
card.addEventListener('click', () => flipCard(card, emoji));
gameBoard.appendChild(card);
});
function flipCard(card, emoji) {
if (lockBoard) return;
if (card.classList.contains('flipped')) return;
card.classList.add('flipped');
flipped.push({card, emoji});
if (flipped.length === 2) {
lockBoard = true;
const [first, second] = flipped;
if (first.emoji === second.emoji) {
flipped = [];
lockBoard = false;
} else {
setTimeout(() => {
first.card.classList.remove('flipped');
second.card.classList.remove('flipped');
flipped = [];
lockBoard = false;
}, 1000);
}
}
}
</script>
</body>
</html>