Spaces:
Running
Running
Upload 41 files
Browse files
script.js
CHANGED
|
@@ -68,10 +68,10 @@ document.addEventListener('DOMContentLoaded', async function() {
|
|
| 68 |
await loadPlayerData();
|
| 69 |
|
| 70 |
// 獲取所有按鈕元素
|
| 71 |
-
const startGameBtn = document.getElementById('start-
|
| 72 |
-
const loadGameBtn = document.getElementById('load-
|
| 73 |
-
const achievementsBtn = document.getElementById('achievements');
|
| 74 |
-
const exitGameBtn = document.getElementById('exit-
|
| 75 |
const toggleBgmBtn = document.getElementById('toggle-bgm');
|
| 76 |
|
| 77 |
// 調試:檢查按鈕是否正確獲取
|
|
@@ -82,9 +82,9 @@ document.addEventListener('DOMContentLoaded', async function() {
|
|
| 82 |
console.log('音樂開關按鈕:', toggleBgmBtn);
|
| 83 |
|
| 84 |
// 獲取模態框元素
|
| 85 |
-
const playerModal = document.getElementById('
|
| 86 |
-
const loadModal = document.getElementById('
|
| 87 |
-
const closeModalBtns = document.querySelectorAll('.close');
|
| 88 |
|
| 89 |
// 調試:檢查模態框是否正確獲取
|
| 90 |
console.log('玩家選擇模態框:', playerModal);
|
|
@@ -97,7 +97,7 @@ document.addEventListener('DOMContentLoaded', async function() {
|
|
| 97 |
console.log('點擊開始遊戲按鈕');
|
| 98 |
if (playerModal) {
|
| 99 |
playerModal.style.display = 'block';
|
| 100 |
-
|
| 101 |
} else {
|
| 102 |
console.error('找不到玩家選擇模態框');
|
| 103 |
}
|
|
@@ -110,11 +110,8 @@ document.addEventListener('DOMContentLoaded', async function() {
|
|
| 110 |
if (loadGameBtn) {
|
| 111 |
loadGameBtn.addEventListener('click', function() {
|
| 112 |
console.log('點擊讀取進度按鈕');
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
} else {
|
| 116 |
-
console.error('找不到讀取進度模態框');
|
| 117 |
-
}
|
| 118 |
});
|
| 119 |
} else {
|
| 120 |
console.error('找不到讀取進度按鈕');
|
|
@@ -160,96 +157,36 @@ document.addEventListener('DOMContentLoaded', async function() {
|
|
| 160 |
}
|
| 161 |
});
|
| 162 |
|
| 163 |
-
// 處理
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
console.error('找不到玩家列表元素');
|
| 168 |
-
return;
|
| 169 |
-
}
|
| 170 |
-
|
| 171 |
-
playerList.innerHTML = '';
|
| 172 |
-
|
| 173 |
-
if (playerData.length === 0) {
|
| 174 |
-
playerList.innerHTML = '<p>正在載入玩家資料...</p>';
|
| 175 |
-
return;
|
| 176 |
-
}
|
| 177 |
-
|
| 178 |
-
playerData.forEach(function(player) {
|
| 179 |
-
const playerDiv = document.createElement('div');
|
| 180 |
-
playerDiv.className = 'player-option';
|
| 181 |
-
playerDiv.innerHTML = `
|
| 182 |
-
<h3>${player.name}</h3>
|
| 183 |
-
<p>職業:${player.profession}</p>
|
| 184 |
-
<p>ID:${player.id}</p>
|
| 185 |
-
`;
|
| 186 |
-
|
| 187 |
-
playerDiv.addEventListener('click', function() {
|
| 188 |
-
console.log('選擇玩家:', player);
|
| 189 |
-
localStorage.setItem('currentPlayerId', player.id);
|
| 190 |
-
localStorage.setItem('currentPlayerName', player.name);
|
| 191 |
-
localStorage.setItem('currentPlayerProfession', player.profession);
|
| 192 |
-
|
| 193 |
-
// 檢查是否有存檔
|
| 194 |
-
const existingProgress = localStorage.getItem(`gameProgress_${player.id}`);
|
| 195 |
-
if (existingProgress) {
|
| 196 |
-
if (confirm(`發現 ${player.name} 的存檔,是否繼續之前的進度?`)) {
|
| 197 |
-
window.location.href = 'kingdom_map.html';
|
| 198 |
-
} else {
|
| 199 |
-
// 重新開始遊戲
|
| 200 |
-
localStorage.removeItem(`gameProgress_${player.id}`);
|
| 201 |
-
window.location.href = 'prologue.html';
|
| 202 |
-
}
|
| 203 |
-
} else {
|
| 204 |
-
// 新遊戲
|
| 205 |
-
window.location.href = 'prologue.html';
|
| 206 |
-
}
|
| 207 |
-
});
|
| 208 |
-
|
| 209 |
-
playerList.appendChild(playerDiv);
|
| 210 |
-
});
|
| 211 |
-
}
|
| 212 |
-
|
| 213 |
-
// 處理存檔碼載入
|
| 214 |
-
const loadSaveBtn = document.getElementById('load-save-btn');
|
| 215 |
-
const saveCodeInput = document.getElementById('save-code-input');
|
| 216 |
|
| 217 |
-
if (
|
| 218 |
-
|
| 219 |
-
const
|
| 220 |
-
if (!
|
| 221 |
-
|
| 222 |
return;
|
| 223 |
}
|
| 224 |
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
window.location.href = 'kingdom_map.html';
|
| 229 |
-
} else {
|
| 230 |
-
alert('存檔載入失敗:' + result.error);
|
| 231 |
-
}
|
| 232 |
-
});
|
| 233 |
-
}
|
| 234 |
-
|
| 235 |
-
// 處理存檔碼生成
|
| 236 |
-
const generateSaveBtn = document.getElementById('generate-save-btn');
|
| 237 |
-
const saveCodeOutput = document.getElementById('save-code-output');
|
| 238 |
-
|
| 239 |
-
if (generateSaveBtn && saveCodeOutput) {
|
| 240 |
-
generateSaveBtn.addEventListener('click', function() {
|
| 241 |
-
const currentPlayerId = localStorage.getItem('currentPlayerId');
|
| 242 |
-
if (!currentPlayerId) {
|
| 243 |
-
alert('請先開始遊戲');
|
| 244 |
-
return;
|
| 245 |
-
}
|
| 246 |
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
} else {
|
| 252 |
-
|
|
|
|
| 253 |
}
|
| 254 |
});
|
| 255 |
}
|
|
|
|
| 68 |
await loadPlayerData();
|
| 69 |
|
| 70 |
// 獲取所有按鈕元素
|
| 71 |
+
const startGameBtn = document.getElementById('start-btn');
|
| 72 |
+
const loadGameBtn = document.getElementById('load-btn');
|
| 73 |
+
const achievementsBtn = document.getElementById('achievements-btn');
|
| 74 |
+
const exitGameBtn = document.getElementById('exit-btn');
|
| 75 |
const toggleBgmBtn = document.getElementById('toggle-bgm');
|
| 76 |
|
| 77 |
// 調試:檢查按鈕是否正確獲取
|
|
|
|
| 82 |
console.log('音樂開關按鈕:', toggleBgmBtn);
|
| 83 |
|
| 84 |
// 獲取模態框元素
|
| 85 |
+
const playerModal = document.getElementById('id-modal');
|
| 86 |
+
const loadModal = document.getElementById('welcome-modal');
|
| 87 |
+
const closeModalBtns = document.querySelectorAll('.close-btn, .close-welcome-btn');
|
| 88 |
|
| 89 |
// 調試:檢查模態框是否正確獲取
|
| 90 |
console.log('玩家選擇模態框:', playerModal);
|
|
|
|
| 97 |
console.log('點擊開始遊戲按鈕');
|
| 98 |
if (playerModal) {
|
| 99 |
playerModal.style.display = 'block';
|
| 100 |
+
// 直接顯示 ID 輸入框,而不是玩家列表
|
| 101 |
} else {
|
| 102 |
console.error('找不到玩家選擇模態框');
|
| 103 |
}
|
|
|
|
| 110 |
if (loadGameBtn) {
|
| 111 |
loadGameBtn.addEventListener('click', function() {
|
| 112 |
console.log('點擊讀取進度按鈕');
|
| 113 |
+
// 這裡可以實現讀取進度的邏輯
|
| 114 |
+
alert('讀取進度功能尚未實現');
|
|
|
|
|
|
|
|
|
|
| 115 |
});
|
| 116 |
} else {
|
| 117 |
console.error('找不到讀取進度按鈕');
|
|
|
|
| 157 |
}
|
| 158 |
});
|
| 159 |
|
| 160 |
+
// 處理 ID 輸入確認
|
| 161 |
+
const confirmIdBtn = document.getElementById('confirm-id');
|
| 162 |
+
const playerIdInput = document.getElementById('player-id');
|
| 163 |
+
const idError = document.getElementById('id-error');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
+
if (confirmIdBtn && playerIdInput) {
|
| 166 |
+
confirmIdBtn.addEventListener('click', function() {
|
| 167 |
+
const playerId = playerIdInput.value.trim();
|
| 168 |
+
if (!playerId) {
|
| 169 |
+
if (idError) idError.textContent = '請輸入ID';
|
| 170 |
return;
|
| 171 |
}
|
| 172 |
|
| 173 |
+
// 設置玩家資料
|
| 174 |
+
localStorage.setItem('currentPlayerId', playerId);
|
| 175 |
+
localStorage.setItem('currentPlayerName', playerId); // 暫時使用 ID 作為名稱
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
+
// 檢查是否有存檔
|
| 178 |
+
const existingProgress = localStorage.getItem(`gameProgress_${playerId}`);
|
| 179 |
+
if (existingProgress) {
|
| 180 |
+
if (confirm(`發現 ${playerId} 的存檔,是否繼續之前的進度?`)) {
|
| 181 |
+
window.location.href = 'kingdom_map.html';
|
| 182 |
+
} else {
|
| 183 |
+
// 重新開始遊戲
|
| 184 |
+
localStorage.removeItem(`gameProgress_${playerId}`);
|
| 185 |
+
window.location.href = 'prologue.html';
|
| 186 |
+
}
|
| 187 |
} else {
|
| 188 |
+
// 新遊戲
|
| 189 |
+
window.location.href = 'prologue.html';
|
| 190 |
}
|
| 191 |
});
|
| 192 |
}
|