-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame-card.html
More file actions
347 lines (323 loc) · 11.3 KB
/
game-card.html
File metadata and controls
347 lines (323 loc) · 11.3 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nagrik Aur Samvidhan - Interactive Article to Law Matching Game</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap');
body {
font-family: 'Poppins', sans-serif;
display: flex;
flex-direction: column;
align-items: center;
background-color: #e8f4f8;
margin: 0;
padding: 20px;
min-height: 100vh;
background-image: url('Designer\ \(5\).png');
}
h1 {
color: #1a5f7a;
text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}
.game-container {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 15px;
max-width: 600px;
margin-top: 20px;
}
.card {
width: 120px;
height: 180px;
perspective: 1000px;
cursor: pointer;
}
.card-inner {
width: 100%;
height: 100%;
transition: transform 0.6s;
transform-style: preserve-3d;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
border-radius: 10px;
}
.card.flipped .card-inner {
transform: rotateY(180deg);
}
.card-front, .card-back {
width: 100%;
height: 100%;
position: absolute;
backface-visibility: hidden;
display: flex;
justify-content: center;
align-items: center;
border-radius: 10px;
font-weight: bold;
text-align: center;
padding: 10px;
box-sizing: border-box;
}
.card-front {
background-color: #20BF55;
color: white;
font-size: 24px;
}
.card-back {
background-color: #fff;
color: #1a5f7a;
transform: rotateY(180deg);
}
.card.matched .card-back {
background-color: #0B4F6C;
color: white;
}
#game-info {
display: flex;
justify-content: space-between;
width: 100%;
max-width: 600px;
margin-top: 20px;
}
#game-info div {
font-size: 1.2em;
font-weight: bold;
color: #1a5f7a;
}
button {
margin-top: 20px;
padding: 10px 20px;
font-size: 1em;
background-color: #1a5f7a;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s, transform 0.1s;
}
button:hover {
background-color: #134b60;
}
button:active {
transform: scale(0.98);
}
#difficulty {
margin-top: 20px;
}
select {
padding: 5px 10px;
font-size: 1em;
border-radius: 5px;
border: 1px solid #1a5f7a;
}
#progress-bar {
width: 100%;
max-width: 600px;
height: 20px;
background-color: #e0e0e0;
border-radius: 10px;
margin-top: 20px;
overflow: hidden;
}
#progress {
width: 0%;
height: 100%;
background-color: #4caf50;
transition: width 0.5s ease-in-out;
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
.pulse {
animation: pulse 0.5s;
}
#confetti {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 9999;
}
</style>
</head>
<body>
<h1>Nagrik Aur Samvidhan: Article to Law Matching Challenge</h1>
<div id="difficulty">
<label for="difficulty-select">Difficulty:</label>
<select id="difficulty-select">
<option value="easy">Easy</option>
<option value="medium">Medium</option>
<option value="hard">Hard</option>
</select>
</div>
<div class="game-container" id="gameContainer"></div>
<div id="progress-bar"><div id="progress"></div></div>
<div id="game-info">
<div id="score">Matches: 0</div>
<div id="moves">Moves: 0</div>
<div id="timer">Time: 0s</div>
</div>
<button id="restart-btn">Restart Game</button>
<canvas id="confetti"></canvas>
<!-- Back Button -->
<div class="back-container">
<a href="index.html" class="back-button">Back</a>
</div>
<style>
.back-container {
display: flex;
justify-content: flex-start; /* Align to the left */
position: fixed;
top: 50%; /* Vertically center */
left: 20px; /* Position slightly away from the left edge */
transform: translateY(-50%); /* Adjust to ensure it's fully vertically centered */
width: auto; /* Adjust width to content */
}
.back-button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
text-decoration: none;
border-radius: 5px;
font-size: 16px;
}
.back-button:hover {
background-color: #45a049;
}
</style>
<script>
const gameContainer = document.getElementById('gameContainer');
const scoreDisplay = document.getElementById('score');
const movesDisplay = document.getElementById('moves');
const timerDisplay = document.getElementById('timer');
const restartBtn = document.getElementById('restart-btn');
const difficultySelect = document.getElementById('difficulty-select');
const progressBar = document.getElementById('progress');
let flippedCards = [];
let matchedPairs = 0;
let moves = 0;
let gameTimer;
let seconds = 0;
let cardPairs = [];
let totalPairs = 0;
const allCardPairs = [
{ id: 1, article: "Article 14-18", law: "Right to Equality" },
{ id: 2, article: "Article 19-22", law: "Right to Freedom" },
{ id: 3, article: "Article 23-24", law: "Right against Exploitation" },
{ id: 4, article: "Article 25-28", law: "Right to Freedom of Religion" },
{ id: 5, article: "Article 29-30", law: "Cultural and Educational Rights" },
{ id: 6, article: "Article 32", law: "Right to Constitutional Remedies" },
{ id: 7, article: "Article 51A", law: "Fundamental Duties" },
{ id: 8, article: "Article 21A", law: "Right to Education" },
{ id: 9, article: "Part IV", law: "Directive Principles" }
];
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
function createCard(cardData, isArticle) {
const card = document.createElement('div');
card.className = 'card';
card.innerHTML = `
<div class="card-inner">
<div class="card-front">?</div>
<div class="card-back">${isArticle ? cardData.article : cardData.law}</div>
</div>
`;
card.addEventListener('click', flipCard);
return card;
}
function flipCard() {
if (flippedCards.length < 2 && !this.classList.contains('flipped')) {
this.classList.add('flipped');
flippedCards.push(this);
if (flippedCards.length === 2) {
moves++;
movesDisplay.textContent = `Moves: ${moves}`;
setTimeout(checkMatch, 1000);
}
}
}
function checkMatch() {
const [card1, card2] = flippedCards;
const isMatch = card1.querySelector('.card-back').textContent === card2.querySelector('.card-back').textContent &&
((card1.querySelector('.card-front').textContent === '?' && card2.querySelector('.card-front').textContent === '?') ||
(card1.querySelector('.card-front').textContent === '?' && card2.querySelector('.card-back').textContent === card1.querySelector('.card-back').textContent) ||
(card2.querySelector('.card-front').textContent === '?' && card1.querySelector('.card-back').textContent === card2.querySelector('.card-back').textContent));
if (isMatch) {
matchedPairs++;
scoreDisplay.textContent = `Matches: ${matchedPairs}`;
card1.classList.add('matched');
card2.classList.add('matched');
card1.removeEventListener('click', flipCard);
card2.removeEventListener('click', flipCard);
if (matchedPairs === totalPairs) {
clearInterval(gameTimer);
showConfetti();
setTimeout(() => alert('Congratulations! You matched all pairs!'), 500);
}
} else {
card1.classList.remove('flipped');
card2.classList.remove('flipped');
}
flippedCards = [];
}
function startGame() {
matchedPairs = 0;
moves = 0;
seconds = 0;
scoreDisplay.textContent = `Matches: ${matchedPairs}`;
movesDisplay.textContent = `Moves: ${moves}`;
timerDisplay.textContent = `Time: 0s`;
clearInterval(gameTimer);
progressBar.style.width = '0%';
const difficulty = difficultySelect.value;
const numPairs = difficulty === 'easy' ? 4 : (difficulty === 'medium' ? 6 : 8);
totalPairs = numPairs;
cardPairs = allCardPairs.slice(0, numPairs);
const cards = [...cardPairs, ...cardPairs];
shuffleArray(cards);
gameContainer.innerHTML = '';
cards.forEach(cardData => {
gameContainer.appendChild(createCard(cardData, true));
gameContainer.appendChild(createCard(cardData, false));
});
gameTimer = setInterval(() => {
seconds++;
timerDisplay.textContent = `Time: ${seconds}s`;
const progressPercentage = (matchedPairs / totalPairs) * 100;
progressBar.style.width = `${progressPercentage}%`;
}, 1000);
}
function showConfetti() {
const canvas = document.getElementById('confetti');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
function createConfetti() {
const colors = ['#ff0a00', '#ff8c00', '#ffeb00', '#00ff00', '#00bfff'];
for (let i = 0; i < 100; i++) {
ctx.beginPath();
ctx.arc(Math.random() * canvas.width, Math.random() * canvas.height, Math.random() * 5 + 5, 0, 2 * Math.PI);
ctx.fillStyle = colors[Math.floor(Math.random() * colors.length)];
ctx.fill();
}
}
createConfetti();
}
restartBtn.addEventListener('click', startGame);
window.addEventListener('resize', () => {
document.getElementById('confetti').width = window.innerWidth;
document.getElementById('confetti').height = window.innerHeight;
});
startGame();
</script>
</body>
</html>