Spaces:
Running
Running
Upload 41 files
Browse files- spring.html +1 -2
- spring.js +77 -23
spring.html
CHANGED
|
@@ -141,8 +141,7 @@
|
|
| 141 |
|
| 142 |
<!-- 音樂來源註記 -->
|
| 143 |
<div class="music-credit">
|
| 144 |
-
<p>背景音樂:
|
| 145 |
-
<p>推廣:J&B無版權音樂庫 <a href="https://bit.ly/2YfWIhw" target="_blank">https://bit.ly/2YfWIhw</a></p>
|
| 146 |
<button id="toggle-bgm" class="small-btn">音樂開/關</button>
|
| 147 |
</div>
|
| 148 |
</div>
|
|
|
|
| 141 |
|
| 142 |
<!-- 音樂來源註記 -->
|
| 143 |
<div class="music-credit">
|
| 144 |
+
<p>背景音樂:由Suno製作</p>
|
|
|
|
| 145 |
<button id="toggle-bgm" class="small-btn">音樂開/關</button>
|
| 146 |
</div>
|
| 147 |
</div>
|
spring.js
CHANGED
|
@@ -31,31 +31,40 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 31 |
let questions = [];
|
| 32 |
let startTime = Date.now();
|
| 33 |
|
| 34 |
-
// 生成平方題目
|
| 35 |
function generateQuestions() {
|
| 36 |
-
questions = [
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
}
|
| 49 |
-
|
| 50 |
-
// 隨機排列選項
|
| 51 |
-
const options = [answer, ...wrongAnswers].sort(() => Math.random() - 0.5);
|
| 52 |
-
|
| 53 |
-
questions.push({
|
| 54 |
-
question: `${base}² = ?`,
|
| 55 |
-
options: options,
|
| 56 |
-
correctAnswer: answer
|
| 57 |
-
});
|
| 58 |
-
}
|
| 59 |
}
|
| 60 |
|
| 61 |
// 顯示當前題目
|
|
@@ -264,6 +273,51 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 264 |
});
|
| 265 |
}
|
| 266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
// 初始化顯示
|
| 268 |
if (storySection) storySection.style.display = 'block';
|
| 269 |
if (quizSection) quizSection.style.display = 'none';
|
|
|
|
| 31 |
let questions = [];
|
| 32 |
let startTime = Date.now();
|
| 33 |
|
| 34 |
+
// 生成平方題目 - 使用固定題目
|
| 35 |
function generateQuestions() {
|
| 36 |
+
questions = [
|
| 37 |
+
{
|
| 38 |
+
question: "8 的平方是多少?",
|
| 39 |
+
options: [56, 64, 72, 81],
|
| 40 |
+
correctAnswer: 64
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
question: "哪個數的平方是 121?",
|
| 44 |
+
options: [10, 11, 12, 13],
|
| 45 |
+
correctAnswer: 11
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
question: "5 的平方是多少?",
|
| 49 |
+
options: [20, 30, 25, 35],
|
| 50 |
+
correctAnswer: 25
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
question: "哪個數的平方是 36?",
|
| 54 |
+
options: [6, 7, 5, 8],
|
| 55 |
+
correctAnswer: 6
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
question: "12 的平方是多少?",
|
| 59 |
+
options: [124, 132, 144, 154],
|
| 60 |
+
correctAnswer: 144
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
question: "哪個數的平方是 49?",
|
| 64 |
+
options: [6, 8, 7, 9],
|
| 65 |
+
correctAnswer: 7
|
| 66 |
}
|
| 67 |
+
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
}
|
| 69 |
|
| 70 |
// 顯示當前題目
|
|
|
|
| 273 |
});
|
| 274 |
}
|
| 275 |
|
| 276 |
+
// 前往下一試煉按鈕事件
|
| 277 |
+
const nextTrialBtn = document.getElementById('next-trial');
|
| 278 |
+
if (nextTrialBtn) {
|
| 279 |
+
nextTrialBtn.addEventListener('click', function() {
|
| 280 |
+
window.location.href = 'valley.html';
|
| 281 |
+
});
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
// 音樂控制
|
| 285 |
+
const bgmAudio = document.getElementById('bgm');
|
| 286 |
+
const toggleBgmBtn = document.getElementById('toggle-bgm');
|
| 287 |
+
|
| 288 |
+
if (bgmAudio && toggleBgmBtn) {
|
| 289 |
+
// 檢查是否有保存的音樂狀態
|
| 290 |
+
const musicPlaying = localStorage.getItem('musicPlaying') === 'true';
|
| 291 |
+
const musicTime = parseFloat(localStorage.getItem('musicTime') || '0');
|
| 292 |
+
|
| 293 |
+
if (musicPlaying) {
|
| 294 |
+
bgmAudio.currentTime = musicTime;
|
| 295 |
+
bgmAudio.play().catch(e => console.log('自動播放被阻止:', e));
|
| 296 |
+
toggleBgmBtn.textContent = '音樂關';
|
| 297 |
+
} else {
|
| 298 |
+
toggleBgmBtn.textContent = '音樂開';
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
// 音樂開關按鈕
|
| 302 |
+
toggleBgmBtn.addEventListener('click', function() {
|
| 303 |
+
if (bgmAudio.paused) {
|
| 304 |
+
bgmAudio.play().then(() => {
|
| 305 |
+
toggleBgmBtn.textContent = '音樂關';
|
| 306 |
+
localStorage.setItem('musicPlaying', 'true');
|
| 307 |
+
}).catch(e => console.log('播放失敗:', e));
|
| 308 |
+
} else {
|
| 309 |
+
bgmAudio.pause();
|
| 310 |
+
toggleBgmBtn.textContent = '音樂開';
|
| 311 |
+
localStorage.setItem('musicPlaying', 'false');
|
| 312 |
+
}
|
| 313 |
+
});
|
| 314 |
+
|
| 315 |
+
// 保存音樂播放時間
|
| 316 |
+
bgmAudio.addEventListener('timeupdate', function() {
|
| 317 |
+
localStorage.setItem('musicTime', bgmAudio.currentTime.toString());
|
| 318 |
+
});
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
// 初始化顯示
|
| 322 |
if (storySection) storySection.style.display = 'block';
|
| 323 |
if (quizSection) quizSection.style.display = 'none';
|