-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeo3.html
255 lines (213 loc) · 8.32 KB
/
geo3.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Geoguesser Game</title>
<style>
h1 {
color: #00ff00; /* Bright green */
}
body {
background-color:white;
border-radius: 10px;
text-align: center;
font-family: Arial, sans-serif;
}
#image {
width: 50%;
margin: 0 auto; /* Center the image horizontally */
}
#location-image {
width: 100%;
max-width: 500px;
height: auto;
border-radius: 10px;
border: 2px solid #333;
animation: fadeIn 1s;
}
#options {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
margin-top: 20px;
}
.option-button {
margin: 10px;
padding: 10px 20px;
font-size: 18px;
cursor: pointer;
background-color: #3498db; /* Blue */
color: #fff; /* White */
border: none;
border-radius: 5px;
transition: background-color 0.3s ease;
}
.option-button:hover {
background-color: #2980b9; /* Darker blue on hover */
}
#score {
color: #fff; /* White */
font-size: 24px;
font-weight: bold;
margin-top: 20px;
}
#location-fact {
color: #fff;
}
#location {
background-color: #000;
width: 100%;
height: auto;
}
#timer {
color: #fff; /* White */
font-size: 24px;
font-weight: bold;
margin-top: 10px;
}
#result {
color: #fff; /* White */
font-size: 20px;
font-weight: bold;
margin-top: 20px;
}
@keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
</style>
</head>
<body>
<h1>Geoguesser Game</h1>
<div id="image">
<img id="location-image" src="" alt="Guess the location">
</div>
<div id="location">
<p id="location-fact"></p>
</div>
<div id="options">
<!-- Options will be generated dynamically using JavaScript -->
</div>
<p id="score">Score: 0</p>
<p id="consecutive">Consecutive Correct Answers: 0</p>
<p id="timer">Time left: 10s</p>
<p id="result"></p>
<script>
const locations = [
{ name: 'Assam', image: 'assam.avif', fact: 'Assam is known for its tea plantations.' },
{ name: 'Bihar', image:'bihar.webp', fact: 'Bihar is the birthplace of Lord Buddha.' },
{ name: 'Jharkhand', image: 'jharkhand.avif', fact: 'Jharkhand is rich in mineral resources.' },
{ name: 'Nagaland', image: 'nagaland.webp', fact: 'Nagaland is known for its tribal culture.' },
{ name: 'Manipur', image: 'manipur.jpeg', fact: 'Manipur is famous for its classical dance forms.' },
{ name: 'Mizoram', image: 'mizoram.jpeg', fact: 'Mizoram is known for its bamboo forests.' },
{ name: 'Meghalaya', image: 'meghalaya.avif', fact: 'Meghalaya receives the highest rainfall in India.' },
{ name: 'Odisha', image: 'odisha.webp', fact: 'Odisha is home to the famous Konark Sun Temple.' },
{ name: 'Tripura', image: 'tripura.webp', fact: 'Tripura is known for its rich cultural heritage.' },
// Add more locations, images, and facts here
];
let currentLocationIndex = 0;
let score = 0;
let timer = 10;
let timerInterval;
let consecutiveCorrectAnswers = 0;
function startTimer() {
timerInterval = setInterval(() => {
timer--;
document.getElementById('timer').textContent = `Time left: ${timer}s`;
if (timer == 0) {
clearInterval(timerInterval);
showResult(false);
}
}, 1000);
}
function showResult(isCorrect) {
clearInterval(timerInterval);
if (isCorrect) {
score++;
consecutiveCorrectAnswers++;
document.getElementById('score').textContent = `Score: ${score}`;
document.getElementById('result').textContent = 'Correct!';
document.getElementById('consecutive').textContent = `Consecutive Correct Answers: ${consecutiveCorrectAnswers}`;
if (consecutiveCorrectAnswers === 5) {
// User got 5 consecutive correct answers, award 5 bonus points
consecutiveCorrectAnswers = 0; // Reset consecutiveCorrectAnswers
// Redirect to gameupdate.php
window.location.href = 'geo3.php';
return; // Stop the game
}
} else {
// User chose a wrong answer, end the game
document.getElementById('result').textContent = 'Incorrect. Game over!';
consecutiveCorrectAnswers = 0;
score = 0;
document.getElementById('score').textContent = `Score: ${score}`;
alert('Game over! Your final score: ' + score);
}
document.getElementById('location-fact').textContent = `Fun Fact: ${locations[currentLocationIndex].fact}`;
// Delay for a moment and then load the next location
setTimeout(loadNextLocation, 5000);
}
// ... (remaining code) ..
function loadNextLocation() {
if (currentLocationIndex < locations.length - 1) {
currentLocationIndex++;
} else {
// You've reached the end of the game; you can add logic here to handle it.
alert('Game over! Your final score: ' + score);
// Optionally, you can reset the game here.
currentLocationIndex = 0;
score = 0;
}
const location = locations[currentLocationIndex];
document.getElementById('location-image').src = location.image;
document.getElementById('result').textContent = '';
document.getElementById('location-fact').textContent = '';
timer = 10;
document.getElementById('timer').textContent = `Time left: ${timer}s`;
startTimer();
shuffleOptions(); // Shuffle the options each time a new location is loaded
}
function shuffleOptions() {
const options = [...locations]; // Copy the entire locations array
const correctAnswer = options[currentLocationIndex].name;
options.splice(currentLocationIndex, 1); // Remove the correct answer
shuffleArray(options); // Shuffle the remaining options
options.splice(3); // Keep only the first four options
options.push({ name: correctAnswer }); // Add the correct answer back in the options
shuffleArray(options); // Shuffle the options again
const optionsDiv = document.getElementById('options');
optionsDiv.innerHTML = ''; // Clear existing options
options.forEach((location) => {
const button = document.createElement('button');
button.className = 'option-button';
button.textContent = location.name;
button.onclick = () => checkAnswer(location.name);
optionsDiv.appendChild(button);
});
}
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]]; // Swap elements
}
}
function checkAnswer(selectedAnswer) {
const correctAnswer = locations[currentLocationIndex].name;
if (selectedAnswer === correctAnswer) {
showResult(true);
} else {
showResult(false);
}
}
// Initial load
shuffleOptions();
loadNextLocation();
</script>
</body>
</html>