-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrafic.html
More file actions
411 lines (378 loc) · 14.7 KB
/
trafic.html
File metadata and controls
411 lines (378 loc) · 14.7 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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Traffic Law Trivia</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.4/gsap.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body, html {
height: 100%;
font-family: Arial, sans-serif;
color: white;
background-image: url('Indian-Polity.jpg');
overflow: hidden;
}
#game-screen, #end-screen {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
z-index: 10;
}
.content {
background: rgba(0, 0, 0, 0.7);
padding: 2rem;
border-radius: 10px;
text-align: center;
max-width: 800px;
width: 90%;
position: relative;
z-index: 1;
}
h1 {
font-size: 2.5rem;
margin-bottom: 1rem;
}
.btn {
background: #e50914;
color: white;
border: none;
padding: 0.8rem 1.5rem;
font-size: 1rem;
cursor: pointer;
margin: 0.5rem;
border-radius: 5px;
transition: background-color 0.3s;
}
.btn:hover {
background-color: #f40612;
}
.options {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
margin-top: 1rem;
}
.info-bar {
display: flex;
justify-content: space-between;
margin-bottom: 1rem;
}
#hint {
font-style: italic;
margin-top: 1rem;
}
.animation-element {
position: absolute;
z-index: 0;
}
#gavel {
width: 100px;
height: 100px;
top: 20px;
left: 20px;
}
#scale {
width: 120px;
height: 120px;
bottom: 20px;
right: 20px;
}
#book {
width: 80px;
height: 80px;
top: 50%;
left: 10px;
}
@media (max-width: 600px) {
h1 {
font-size: 1.8rem;
}
.btn {
font-size: 0.9rem;
padding: 0.6rem 1.2rem;
}
.animation-element {
width: 60px;
height: 60px;
}
}
#end-screen {
display: none; /* Initially hidden */
background-image: url('Indian-Polity.jpg');
background-size: cover;
background-position: center;
}
#final-score {
font-size: 2rem;
margin-bottom: 1rem;
}
.end-buttons {
display: flex;
justify-content: center;
gap: 1rem;
margin-top: 1rem;
}
.back-container {
z-index: 20; /* Ensure it's above the end screen */
}
.back-container {
display: flex;
justify-content: flex-start;
position: fixed;
top: 50%;
left: 20px;
transform: translateY(-50%);
width: auto;
z-index: 20; /* Ensure it's above the end screen */
}
.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>
</head>
<body>
<div id="game-screen">
<svg class="animation-element" id="gavel" viewBox="0 0 24 24">
<path fill="currentColor" d="M2.81,14.12L5.64,11.29L9.35,15L6.52,17.83L2.81,14.12M17.69,8.89L13.98,5.18L17.69,1.47L21.4,5.18L17.69,8.89M3.86,9.64L9.22,4.28L13.45,8.5L8.09,13.86L3.86,9.64M20.39,15.56L16.66,11.83L18.83,9.66L22.55,13.38L20.39,15.56M10.41,20.98L6.69,17.26L8.86,15.09L12.58,18.81L10.41,20.98Z" />
</svg>
<svg class="animation-element" id="scale" viewBox="0 0 24 24">
<path fill="currentColor" d="M12,3C10.73,3 9.6,3.8 9.18,5H3V7H4.95L2,14C1.53,16 3,17 5.5,17C8,17 9.56,16 9,14L6.05,7H9.17C9.5,7.85 10.15,8.5 11,8.83V20H2V22H22V20H13V8.82C13.85,8.5 14.5,7.85 14.82,7H17.95L15,14C14.53,16 16,17 18.5,17C21,17 22.56,16 22,14L19.05,7H21V5H14.83C14.4,3.8 13.27,3 12,3M12,5A1,1 0 0,1 13,6A1,1 0 0,1 12,7A1,1 0 0,1 11,6A1,1 0 0,1 12,5M5.5,10.25L7,14H4L5.5,10.25M18.5,10.25L20,14H17L18.5,10.25Z" />
</svg>
<svg class="animation-element" id="book" viewBox="0 0 24 24">
<path fill="currentColor" d="M18,22A2,2 0 0,0 20,20V4C20,2.89 19.1,2 18,2H12V9L9.5,7.5L7,9V2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18Z" />
</svg>
<div class="content">
<div class="info-bar">
<div>Score: <span id="score">0</span></div>
<div>Time: <span id="timer">30</span>s</div>
</div>
<h1 id="question"></h1>
<div class="options" id="options"></div>
<button id="hint-btn" class="btn">Get Hint</button>
<p id="hint"></p>
</div>
</div>
<div id="end-screen">
<div class="content">
<h1>Quiz Completed!</h1>
<div id="final-score"></div>
<div class="end-buttons">
<a href="index.html" class="btn">Back to Home</a>
<button id="play-again" class="btn">Play Again</button>
</div>
</div>
</div>
<!-- Back Button -->
<div class="back-container">
<a href="second.html" class="back-button">Back</a>
</div>
<script>
const questions = [
{
question: "What is the primary purpose of traffic laws?",
options: ["To regulate vehicle manufacturing", "To ensure the safety and orderly flow of traffic", "To enforce environmental standards", "To manage public transportation"],
correct: 1,
hint: "These laws aim to protect road users and maintain order on the roads."
},
{
question: "What does a red traffic light indicate?",
options: ["Speed up", "Stop", "Proceed with caution", "Yield to pedestrians"],
correct: 1,
hint: "This signal requires all vehicles to come to a complete halt."
},
{
question: "What is the legal blood alcohol concentration (BAC) limit for driving in most jurisdictions?",
options: ["0.05%", " 0.08%", " 0.10%", "0.15%"],
correct: 1,
hint: "This limit is commonly used in many countries to determine legal intoxication while driving."
}
,
{
question: "Which of the following is a common traffic violation?",
options: ["Following too closely (tailgating)", "Using turn signals", " Yielding to pedestrians", "Stopping at a stop sign"],
correct: 0,
hint: "This dangerous practice involves driving too close to the vehicle in front."
}
,
{
question: "What should a driver do when approaching a roundabout?",
options: ["Speed through without stopping", "Give way to vehicles already in the roundabout", "Stop and wait for a green light", "Enter without yielding"],
correct: 1,
hint: "This practice ensures smooth flow of traffic in a roundabout."
}
,
{
question: "What does a yellow traffic light mean?",
options: ["Proceed with caution", "Stop immediately", "Go faster", "Prepare to stop"],
correct: 3,
hint: "This signal warns drivers of an impending change to red."
},
{
question: "What is the legal requirement for seat belts?",
options: ["Optional for all passengers", "Mandatory for drivers only", "Mandatory for all passengers in the vehicle", "Only required for children"],
correct: 2,
hint: "This safety measure is required for everyone in the vehicle in most jurisdictions."
},
{
question: "What does a solid white line on the road indicate?",
options: [" Lane change permitted", "Lane change prohibited", "No parking", "Pedestrian crossing"],
correct: 1,
hint: "This road marking restricts certain movements between lanes."
}
,
{
question: "What is the purpose of traffic signs?",
options: ["To provide entertainment", "To convey important information and instructions to drivers", "To advertise businesses,", " To mark property boundaries"],
correct: 1,
hint: "These visual aids help guide and inform road users."
}
,
{
question: "What action should a driver take if they encounter an emergency vehicle with flashing lights?",
options: ["Speed up and get out of the way", "Pull over to the side and stop", "Ignore it and continue driving", "Follow closely behind"],
correct: 1,
hint: "This action allows emergency vehicles to pass safely and quickly."
}
];
let currentQuestion = 0;
let score = 0;
let timeLeft = 30;
let timer;
const questionEl = document.getElementById('question');
const optionsEl = document.getElementById('options');
const scoreEl = document.getElementById('score');
const timerEl = document.getElementById('timer');
const hintBtn = document.getElementById('hint-btn');
const hintEl = document.getElementById('hint');
const gavel = document.getElementById('gavel');
const scale = document.getElementById('scale');
const book = document.getElementById('book');
hintBtn.addEventListener('click', showHint);
let totalQuestions = questions.length;
function startGame() {
document.getElementById('game-screen').style.display = 'flex';
document.getElementById('end-screen').style.display = 'none';
currentQuestion = 0;
score = 0;
loadQuestion();
updateScore();
startTimer();
animateElements();
}
function endGame() {
clearInterval(timer);
document.getElementById('game-screen').style.display = 'none';
document.getElementById('end-screen').style.display = 'flex';
document.getElementById('final-score').textContent = `Your Score: ${score} / ${totalQuestions}`;
}
function loadQuestion() {
const question = questions[currentQuestion];
questionEl.textContent = question.question;
optionsEl.innerHTML = '';
hintEl.textContent = '';
question.options.forEach((option, index) => {
const button = document.createElement('button');
button.textContent = option;
button.classList.add('btn');
button.addEventListener('click', () => checkAnswer(index));
optionsEl.appendChild(button);
});
gsap.from(questionEl, {duration: 0.5, opacity: 0, y: -50});
gsap.from(optionsEl.children, {duration: 0.5, opacity: 0, y: 50, stagger: 0.1});
}
function checkAnswer(selectedIndex) {
const question = questions[currentQuestion];
if (selectedIndex === question.correct) {
score++;
updateScore();
gsap.to(scoreEl, {duration: 0.3, scale: 1.2, yoyo: true, repeat: 1});
}
currentQuestion++;
if (currentQuestion < questions.length) {
loadQuestion();
resetTimer();
} else {
endGame();
}
}
function showHint() {
hintEl.textContent = questions[currentQuestion].hint;
gsap.from(hintEl, {duration: 0.5, opacity: 0, y: 20});
}
function updateScore() {
scoreEl.textContent = score;
}
function startTimer() {
timeLeft = 30;
timer = setInterval(() => {
timeLeft--;
timerEl.textContent = timeLeft;
if (timeLeft <= 0) {
clearInterval(timer);
currentQuestion++;
if (currentQuestion >= questions.length) {
currentQuestion = 0;
}
loadQuestion();
resetTimer();
}
}, 1000);
}
function resetTimer() {
clearInterval(timer);
startTimer();
}
function animateElements() {
gsap.to(gavel, {
duration: 5,
rotation: 360,
x: "random(-50, 50)",
y: "random(-50, 50)",
repeat: -1,
yoyo: true,
ease: "sine.inOut"
});
gsap.to(scale, {
duration: 4,
rotation: -360,
x: "random(-30, 30)",
y: "random(-30, 30)",
repeat: -1,
yoyo: true,
ease: "sine.inOut"
});
gsap.to(book, {
duration: 6,
rotation: 720,
x: "random(-40, 40)",
y: "random(-40, 40)",
repeat: -1,
yoyo: true,
ease: "sine.inOut"
});
}
document.getElementById('play-again').addEventListener('click', startGame);
startGame();
</script>
</body>
</html>