231 lines
6.0 KiB
HTML
231 lines
6.0 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-TW">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>虛擬寵物系統 - Console 互動版</title>
|
||
<style>
|
||
* {
|
||
margin: 0;
|
||
padding: 0;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
body {
|
||
font-family: 'Courier New', monospace;
|
||
background: #1e1e1e;
|
||
color: #d4d4d4;
|
||
padding: 20px;
|
||
line-height: 1.6;
|
||
}
|
||
|
||
.container {
|
||
max-width: 1200px;
|
||
margin: 0 auto;
|
||
}
|
||
|
||
h1 {
|
||
color: #4ec9b0;
|
||
margin-bottom: 10px;
|
||
border-bottom: 2px solid #4ec9b0;
|
||
padding-bottom: 10px;
|
||
}
|
||
|
||
.info {
|
||
background: #252526;
|
||
padding: 15px;
|
||
border-radius: 5px;
|
||
margin-bottom: 20px;
|
||
border-left: 4px solid #007acc;
|
||
}
|
||
|
||
.info h2 {
|
||
color: #4ec9b0;
|
||
margin-bottom: 10px;
|
||
}
|
||
|
||
.console-area {
|
||
background: #1e1e1e;
|
||
border: 2px solid #3c3c3c;
|
||
border-radius: 5px;
|
||
padding: 15px;
|
||
min-height: 400px;
|
||
max-height: 600px;
|
||
overflow-y: auto;
|
||
font-family: 'Courier New', monospace;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.command-list {
|
||
background: #252526;
|
||
padding: 15px;
|
||
border-radius: 5px;
|
||
margin-top: 20px;
|
||
}
|
||
|
||
.command-list h3 {
|
||
color: #4ec9b0;
|
||
margin-bottom: 10px;
|
||
}
|
||
|
||
.command-list code {
|
||
color: #ce9178;
|
||
background: #1e1e1e;
|
||
padding: 2px 6px;
|
||
border-radius: 3px;
|
||
}
|
||
|
||
.command-list ul {
|
||
list-style: none;
|
||
padding-left: 0;
|
||
}
|
||
|
||
.command-list li {
|
||
margin: 8px 0;
|
||
padding-left: 20px;
|
||
}
|
||
|
||
.status-display {
|
||
background: #252526;
|
||
padding: 15px;
|
||
border-radius: 5px;
|
||
margin-top: 20px;
|
||
border-left: 4px solid #4ec9b0;
|
||
}
|
||
|
||
.warning {
|
||
color: #f48771;
|
||
background: #3c1e1e;
|
||
padding: 10px;
|
||
border-radius: 5px;
|
||
margin: 10px 0;
|
||
}
|
||
|
||
.success {
|
||
color: #4ec9b0;
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="container">
|
||
<h1>🐾 虛擬寵物系統 - Console 互動版</h1>
|
||
|
||
<div class="info">
|
||
<h2>📖 使用說明</h2>
|
||
<p>1. 打開瀏覽器的開發者工具(F12 或 Cmd+Option+I)</p>
|
||
<p>2. 切換到 <strong>Console</strong> 標籤</p>
|
||
<p>3. 系統會自動初始化,然後你可以在 console 中輸入命令</p>
|
||
<p>4. 輸入 <code>help()</code> 查看所有可用命令</p>
|
||
<p>5. 輸入 <code>start()</code> 開始遊戲循環</p>
|
||
</div>
|
||
|
||
<div class="warning">
|
||
⚠️ <strong>注意:</strong>此版本使用 Mock API(資料儲存在 localStorage),未來可切換到真實 API。
|
||
</div>
|
||
|
||
<div class="status-display">
|
||
<h3>📊 系統狀態</h3>
|
||
<p id="system-status">正在載入...</p>
|
||
</div>
|
||
|
||
<div class="command-list">
|
||
<h3>🎮 快速命令參考</h3>
|
||
<ul>
|
||
<li><code>init()</code> - 初始化系統</li>
|
||
<li><code>showStatus()</code> - 顯示寵物狀態</li>
|
||
<li><code>start()</code> - 啟動遊戲循環</li>
|
||
<li><code>stop()</code> - 停止遊戲循環</li>
|
||
<li><code>feed(20)</code> - 餵食</li>
|
||
<li><code>play(15)</code> - 玩耍</li>
|
||
<li><code>clean()</code> - 清理便便</li>
|
||
<li><code>heal(20)</code> - 治療</li>
|
||
<li><code>pray()</code> - 祈福</li>
|
||
<li><code>drawFortune()</code> - 抽籤</li>
|
||
<li><code>help()</code> - 查看完整幫助</li>
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="console-area" id="console-output">
|
||
<div class="success">✅ 系統載入中...</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script type="module">
|
||
// 動態載入模組(使用絕對路徑,從專案根目錄)
|
||
const basePath = window.location.origin
|
||
const modulePath = basePath + '/console-demo.js'
|
||
|
||
let init, showStatus, start, stop, help
|
||
|
||
// 載入模組
|
||
import(modulePath).then(module => {
|
||
init = module.init
|
||
showStatus = module.showStatus
|
||
start = module.start
|
||
stop = module.stop
|
||
help = module.help
|
||
|
||
// 掛載到 window 供 console 使用
|
||
window.init = init
|
||
window.showStatus = showStatus
|
||
window.start = start
|
||
window.stop = stop
|
||
window.help = help
|
||
|
||
// 初始化系統
|
||
initializeSystem()
|
||
}).catch(error => {
|
||
console.error('載入模組失敗:', error)
|
||
updateStatus('❌ 載入模組失敗,請確認路徑正確')
|
||
})
|
||
|
||
// 更新狀態顯示
|
||
function updateStatus(message) {
|
||
const statusEl = document.getElementById('system-status')
|
||
const outputEl = document.getElementById('console-output')
|
||
if (statusEl) statusEl.textContent = message
|
||
if (outputEl) {
|
||
const div = document.createElement('div')
|
||
div.className = 'success'
|
||
div.textContent = message
|
||
outputEl.appendChild(div)
|
||
outputEl.scrollTop = outputEl.scrollHeight
|
||
}
|
||
}
|
||
|
||
// 初始化系統
|
||
async function initializeSystem() {
|
||
try {
|
||
updateStatus('正在初始化系統...')
|
||
await init()
|
||
updateStatus('✅ 系統初始化完成!輸入 help() 查看所有命令')
|
||
|
||
// 覆蓋 console.log 以顯示在頁面上
|
||
const originalLog = console.log
|
||
console.log = function(...args) {
|
||
originalLog.apply(console, args)
|
||
const outputEl = document.getElementById('console-output')
|
||
if (outputEl) {
|
||
const div = document.createElement('div')
|
||
div.textContent = args.join(' ')
|
||
outputEl.appendChild(div)
|
||
outputEl.scrollTop = outputEl.scrollHeight
|
||
}
|
||
}
|
||
} catch (error) {
|
||
updateStatus('❌ 初始化失敗: ' + error.message)
|
||
console.error(error)
|
||
}
|
||
}
|
||
|
||
// 等待 DOM 載入
|
||
if (document.readyState === 'loading') {
|
||
document.addEventListener('DOMContentLoaded', () => {
|
||
// 模組載入完成後會自動初始化
|
||
})
|
||
}
|
||
</script>
|
||
</body>
|
||
</html>
|
||
|