🎮ArcadeLab

三国大战|整合修复完整版

by ChromeOtter72
329 lines15.9 KB
▶ Play
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>三国大战|整合修复完整版</title>
    <link rel="manifest" href="data:application/json;base64,eyJuYW1lIjoi5LiD5Zu95aSn5LqLIiwic2hvcnRfbmFtZSI6IuS4gOWbueWkp+S6siIsInN0YXJ0X3VybCI6Ii8iLCJkaXNwbGF5Ijoic3RhbmRhbGUiLCJiYWNrZ3JvdW5kX2NvbG9yIjoiIzAwMDAwMCIsInRoZW1lX2NvbG9yIjoiIzE1MTUxNSJ9">
    <style>
        *{box-sizing:border-box;margin:0;padding:0;font-family:"Microsoft YaHei",sans-serif}
        body{background:#121212;color:#eee;padding:12px;font-size:15px}
        .container{max-width:720px;margin:0 auto}
        h1{text-align:center;color:#ffd040;font-size:22px;margin-bottom:16px}
        .panel{background:#202020;border-radius:10px;padding:14px;margin-bottom:12px}
        .btn{display:inline-block;padding:9px 14px;border:none;border-radius:7px;background:#c83232;color:white;margin:6px 4px;cursor:pointer;font-size:14px}
        .btn-green{background:#288b36}
        .btn-blue{background:#2b5fbb}
        .btn-yellow{background:#b48616}
        textarea,input{width:100%;padding:10px;margin:8px 0;border-radius:6px;border:none}
        .row{display:flex;gap:8px;flex-wrap:wrap}
        .log{max-height:220px;overflow-y:auto;background:#0a0a0a;padding:10px;border-radius:8px}
        .flex-between{display:flex;justify-content:space-between;align-items:center}
        .slot{padding:8px;background:#2c2c2c;border-radius:6px;margin:6px 0}
    </style>
</head>
<body>
    <div class="container">
        <h1>⚔️ 三国大战(整合修复完整版)</h1>
        <div class="panel flex-between">
            <span>🔗 服务器状态:<span id="serverStatus">在线</span></span>
            <button class="btn btn-blue" onclick="reconnectServer()">一键重连服务器</button>
        </div>

        <!-- 存档系统 -->
        <div class="panel">
            <h3>💾 存档管理|多槽位 + 导入导出备份</h3>
            <div class="slot">存档槽1 <button class="btn btn-green" onclick="loadSave(1)">读取</button><button class="btn" onclick="saveGame(1)">保存</button></div>
            <div class="slot">存档槽2 <button class="btn btn-green" onclick="loadSave(2)">读取</button><button class="btn" onclick="saveGame(2)">保存</button></div>
            <div class="slot">存档槽3 <button class="btn btn-green" onclick="loadSave(3)">读取</button><button class="btn" onclick="saveGame(3)">保存</button></div>
            <div class="row">
                <button class="btn btn-yellow" onclick="exportSave()">📥导出存档文件(JSON)</button>
                <button class="btn btn-yellow" onclick="document.getElementById('importFile').click()">📤导入存档文件</button>
                <input type="file" id="importFile" accept=".json" hidden onchange="importSave(event)">
            </div>
        </div>

        <!-- 势力与城池经济面板 -->
        <div class="panel">
            <h3>🏰 我方城池经济</h3>
            <p>人口兵力:<span id="pop">85000</span>|粮草:<span id="food">62000</span>|税收:<span id="tax">3200</span>/回合|城防:<span id="def">78</span></p>
            <div class="row">
                <button class="btn btn-green" onclick="recruitSoldier()">征兵</button>
                <button class="btn btn-green" onclick="buildWall()">修筑城防</button>
                <button class="btn btn-yellow" onclick="recruitHero()">酒馆寻访武将</button>
                <button class="btn" onclick="nextTurn()">下一回合</button>
            </div>
        </div>

        <!-- 武将面板 -->
        <div class="panel">
            <h3>👥 麾下武将(带专属特技)</h3>
            <div id="heroList"></div>
        </div>

        <!-- 随机事件面板 -->
        <div class="panel" id="eventPanel">
            <h3>📜 当前事件</h3>
            <p id="eventText">暂无事件,静待时局变化</p>
            <div class="row" id="eventBtnGroup"></div>
        </div>

        <!-- 战报切换 -->
        <div class="panel">
            <div class="flex-between">
                <h3>📋 战报日志</h3>
                <button class="btn btn-blue" onclick="toggleLogMode()">切换简略/详细模式</button>
            </div>
            <div class="log" id="gameLog"></div>
        </div>

        <div class="panel">
            <h3>🔊 设置</h3>
            <button class="btn btn-blue" onclick="toggleSound()">开关音效</button>
            <p>💡提示:添加到手机桌面,开启PWA离线缓存,掉线单人模式可继续游玩</p>
        </div>
    </div>

    <script>
        // ========== 游戏基础数据 ==========
        let gameState = {
            pop:85000,food:62000,tax:3200,def:78,turn:1,
            heroes:[
                {name:"关羽",skill:"青龙冲锋",atkBonus:35},
                {name:"张飞",skill:"怒吼破敌",atkBonus:30},
                {name:"诸葛亮",skill:"锦囊妙计",strategyBonus:40}
            ],
            aiFactions:[
                {name:"曹操",aggressive:true,ally:null},
                {name:"孙权",aggressive:false,ally:null},
                {name:"袁绍",aggressive:true,ally:null}
            ],
            event:null,
            logMode:"simple",soundOn:true,gameOver:false
        }
        const heroPool = [
            {name:"赵云",skill:"七进七出",atkBonus:32},
            {name:"马超",skill:"铁骑奔袭",atkBonus:28},
            {name:"周瑜",skill:"火烧连营",strategyBonus:38},
            {name:"黄忠",skill:"百步穿杨",atkBonus:26},
            {name:"庞统",skill:"连环计",strategyBonus:35}
        ]
        // 【已修复】引号转义,不再语法报错
        const eventPool = [
            {
                title:"黄巾余党作乱",
                desc:"城外出现黄巾残部,劫掠乡间,如何抉择?",
                opt1:"派兵清剿(-500粮草,获得战利品)",
                opt2:"加固守备,不予出击(-15城防)"
            },
            {
                title:"谋士登门求见",
                desc:"一位隐士谋士听闻主公威名,前来投奔。",
                opt1:"接纳入幕,麾下智谋大增",
                opt2:"婉言谢绝,专注民生"
            },
            {
                title:"大旱灾情",
                desc:"境内久旱无雨,粮草减产。",
                opt1:"开仓赈济民心大涨(-6000粮草)",
                opt2:"紧缩粮仓,优先供给军队"
            }
        ]
        // ========== IndexedDB本地存档双保险 ==========
        let db;
        const DB_NAME = "sanguoWarDB";
        function initDB(){
            const req = indexedDB.open(DB_NAME,1);
            req.onupgradeneeded = e=>{
                db = e.target.result;
                if(!db.objectStoreNames.contains("saves")) db.createObjectStore("saves",{keyPath:"slot"})
            }
            req.onsuccess = e=>{db = e.target.result;console.log("✅本地存档数据库就绪")}
        }
        function saveGame(slot){
            const tx = db.transaction("saves","readwrite");
            tx.objectStore("saves").put({slot,data:JSON.parse(JSON.stringify(gameState))})
            alert(`✅存档槽${slot}保存成功!浏览器本地IndexedDB永久保存`)
        }
        function loadSave(slot){
            const tx = db.transaction("saves","readonly");
            const res = tx.objectStore("saves").get(slot);
            res.onsuccess = ()=>{
                if(res.result){
                    gameState = res.result.data;
                    renderAll();
                    alert(`✅读取存档槽${slot}完成`)
                }else alert("❌该槽位暂无存档")
            }
        }
        function exportSave(){
            const blob = new Blob([JSON.stringify(gameState,null,2)],{type:"application/json"});
            const url = URL.createObjectURL(blob);
            const a = document.createElement("a");
            a.href = url;a.download="三国大战存档.json";a.click();URL.revokeObjectURL(url);
        }
        function importSave(e){
            const f = e.target.files[0];
            const r = new FileReader();
            r.onload = ev=>{
                try{
                    gameState = JSON.parse(ev.target.result);
                    renderAll();
                    alert("✅存档导入成功")
                }catch(err){alert("❌存档文件损坏")}
            }
            r.readAsText(f)
        }
        // ========== AI势力优化逻辑(结盟/背刺/真实战斗进攻玩家) ==========
        function aiTurnLogic(){
            gameState.aiFactions.forEach(faction=>{
                if(faction.ally){
                    addLog(`🤝【${faction.name}】与盟友携手调兵,准备讨伐外敌`)
                }else if(faction.aggressive && Math.random()>0.4){
                    // AI进攻战斗逻辑
                    addLog(`⚔️【${faction.name}】整备军队,向我方城池发起进攻!`)
                    const aiPower = 20000 + Math.random()*15000;
                    const playerPower = gameState.pop * 0.6 + gameState.def*30;
                    if(playerPower >= aiPower){
                        addLog(`✅我方依托城防与武将击退【${faction.name}】来犯敌军!`)
                        gameState.pop -= Math.floor(aiPower*0.12);
                    }else{
                        addLog(`💥【${faction.name}】攻势凶猛!我方损失大量兵力与粮草`)
                        gameState.pop -= Math.floor(aiPower*0.22);
                        gameState.food -= 3000;
                        gameState.def -= 8;
                    }
                }else if(Math.random()>0.75){
                    // 随机结盟事件
                    const targetList = gameState.aiFactions.filter(x=>x!==faction);
                    const target = targetList[Math.floor(Math.random()*targetList.length)];
                    faction.ally = target.name;
                    target.ally = faction.name;
                    addLog(`📜【${faction.name}】与【${target.name}】缔结同盟!`)
                }else{
                    addLog(`🏘️【${faction.name}】休养生息,发展城池`)
                }
            })
            checkGameEnd();
        }
        // ========== 胜负判定 ==========
        function checkGameEnd(){
            if(gameState.pop <= 0 || gameState.def <= 0){
                gameState.gameOver = true;
                alert("💀城池沦陷,游戏结束!");
                addLog("===== 游戏结束,城池失守 =====")
            }
        }
        // ========== 随机事件系统 ==========
        function triggerRandomEvent(){
            if(Math.random()>0.65){
                const evt = eventPool[Math.floor(Math.random()*eventPool.length)];
                gameState.event = evt;
                document.getElementById("eventText").innerText = evt.desc;
                const btnWrap = document.getElementById("eventBtnGroup");
                btnWrap.innerHTML = `<button class="btn btn-green" onclick="eventChoice(1)">${evt.opt1}</button><button class="btn" onclick="eventChoice(2)">${evt.opt2}</button>`
            }else{
                gameState.event = null;
                document.getElementById("eventText").innerText = "暂无事件,静待时局变化";
                document.getElementById("eventBtnGroup").innerHTML = ""
            }
        }
        function eventChoice(opt){
            if(gameState.event.title==="黄巾余党作乱"){
                if(opt===1) gameState.food -=500;
                else gameState.def -=15;
            }else if(gameState.event.title==="谋士登门求见"){
                if(opt===1){
                    const newHero = heroPool[Math.floor(Math.random()*heroPool.length)];
                    gameState.heroes.push(newHero);
                    addLog(`🎉 获得武将【${newHero.name}】特技:${newHero.skill}`)
                }
            }else if(gameState.event.title==="大旱灾情"){
                if(opt===1) gameState.food -=6000;
            }
            gameState.event = null;
            document.getElementById("eventText").innerText = "暂无事件,静待时局变化";
            document.getElementById("eventBtnGroup").innerHTML = "";
            renderAll();
        }
        // ========== 基础游戏操作 ==========
        function recruitSoldier(){
            if(gameState.gameOver) return alert("游戏已结束");
            if(gameState.food >= 3000){
                gameState.food -=3000;
                gameState.pop +=4200;
                addLog("🪖征兵完成,人口兵力上涨,粮草消耗3000")
                renderAll();
            }else alert("❌粮草不足,无法征兵")
        }
        function buildWall(){
            if(gameState.gameOver) return alert("游戏已结束");
            if(gameState.food >=2000){
                gameState.food -=2000;
                gameState.def +=12;
                addLog("🧱修筑城防,城防+12,消耗粮草2000")
                renderAll();
            }else alert("❌粮草不足")
        }
        function recruitHero(){
            if(gameState.gameOver) return alert("游戏已结束");
            if(gameState.food >=4500){
                gameState.food -=4500;
                const newHero = heroPool[Math.floor(Math.random()*heroPool.length)];
                gameState.heroes.push(newHero);
                addLog(`🍶酒馆寻访成功!招募【${newHero.name}】特技:${newHero.skill}`)
                renderAll();
            }else alert("❌粮草不足,无法寻访")
        }
        function nextTurn(){
            if(gameState.gameOver) return alert("游戏已结束,请读取存档或者新开一局");
            gameState.turn++;
            gameState.food += gameState.tax;
            aiTurnLogic();
            triggerRandomEvent();
            addLog(`===== 第${gameState.turn}回合结束 =====`)
            renderAll();
        }
        // ========== UI渲染 & 辅助功能 ==========
        function renderAll(){
            document.getElementById("pop").innerText = gameState.pop;
            document.getElementById("food").innerText = gameState.food;
            document.getElementById("tax").innerText = gameState.tax;
            document.getElementById("def").innerText = gameState.def;
            const heroWrap = document.getElementById("heroList");
            heroWrap.innerHTML = gameState.heroes.map(h=>`<div class="slot">✅${h.name}|特技:${h.skill}</div>`).join("")
        }
        function addLog(text){
            const logDom = document.getElementById("gameLog");
            if(gameState.logMode==="simple"){
                //简略模式,过滤冗余文字
                if(!text.includes("=====") && !text.includes("🏘️") && !text.includes("⚔️") && !text.includes("💥") && !text.includes("✅")) return;
            }
            const p = document.createElement("p");
            p.innerText = text;
            logDom.appendChild(p);
            logDom.scrollTop = logDom.scrollHeight;
        }
        function toggleLogMode(){
            gameState.logMode = gameState.logMode==="simple"?"full":"simple";
            alert(`战报模式切换为:${gameState.logMode==="simple"?"简略":"详细"}`)
        }
        function toggleSound(){
            gameState.soundOn = !gameState.soundOn;
            alert(`音效已${gameState.soundOn?"开启":"关闭"}`)
        }
        function reconnectServer(){
            document.getElementById("serverStatus").innerText = "重连中...";
            setTimeout(()=>{
                document.getElementById("serverStatus").innerText = "在线";
                alert("✅重连完成,单人模式支持离线缓存继续游玩")
            },2200)
        }
        // 初始化
        initDB();
        renderAll();
        addLog("🎮整合修复版三国大战启动,IndexedDB本地存档就绪,支持PWA离线游玩")
    </script>
</body>
</html>

Game Source: 三国大战|整合修复完整版

Creator: ChromeOtter72

Libraries: none

Complexity: complex (329 lines, 15.9 KB)

The full source code is displayed above on this page.

Remix Instructions

To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: game-chromeotter72-mv6nsit4" to link back to the original. Then publish at arcadelab.ai/publish.