Lashtw commited on
Commit
b96428a
·
verified ·
1 Parent(s): 67b0887

Upload 41 files

Browse files
Files changed (1) hide show
  1. script.js +34 -97
script.js CHANGED
@@ -68,10 +68,10 @@ document.addEventListener('DOMContentLoaded', async function() {
68
  await loadPlayerData();
69
 
70
  // 獲取所有按鈕元素
71
- const startGameBtn = document.getElementById('start-game');
72
- const loadGameBtn = document.getElementById('load-game');
73
- const achievementsBtn = document.getElementById('achievements');
74
- const exitGameBtn = document.getElementById('exit-game');
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('player-modal');
86
- const loadModal = document.getElementById('load-modal');
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
- populatePlayerList();
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
- if (loadModal) {
114
- loadModal.style.display = 'block';
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
- function populatePlayerList() {
165
- const playerList = document.getElementById('player-list');
166
- if (!playerList) {
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 (loadSaveBtn && saveCodeInput) {
218
- loadSaveBtn.addEventListener('click', function() {
219
- const saveCode = saveCodeInput.value.trim();
220
- if (!saveCode) {
221
- alert('請輸入存檔碼');
222
  return;
223
  }
224
 
225
- const result = loadFromSaveCode(saveCode);
226
- if (result.success) {
227
- alert('存檔載入成功!');
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
- const saveCode = generateSaveCode(currentPlayerId);
248
- if (saveCode) {
249
- saveCodeOutput.value = saveCode;
250
- alert('存檔碼已生成請複製保存');
 
 
 
 
 
 
251
  } else {
252
- alert('沒有找到遊戲進度');
 
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
  }