🎮ArcadeLab

城市养狗模拟器

by BraveDragon92
907 lines27.0 KB
▶ Play
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>城市养狗模拟器</title>
<style>
*{
    margin:0;
    padding:0;
    box-sizing:border-box;
    font-family:"Microsoft YaHei","PingFang SC",sans-serif;
}

body{
    background:#f0f4f8;
    padding:18px;
}

.wrap{
    max-width:780px;
    margin:0 auto;
}

h2{
    text-align:center;
    color:#2d3748;
    margin-bottom:10px;
}

/* 主画面:正面视角,逐渐马赛克风格 */
.main-canvas{
    width:100%;
    height:440px;
    border:4px solid #cbd5e0;
    border-radius:12px;
    position:relative;
    overflow:hidden;
    background:#e2e8f0;
}

/* 场景切换 */
.scene{
    width:100%;
    height:100%;
    position:absolute;
    top:0;
    left:0;
    transition:transform 0.9s ease;
}
.scene-home{
    background:#f7f3ea;
}
.scene-city{
    background:#aec6cf;
    transform:translateX(100%);
}
.scene-hospital{
    background:#fef2f2;
    transform:translateX(200%);
}

/* 室内 */
.floor{
    position:absolute;
    bottom:0;
    left:0;
    width:100%;
    height:140px;
    background:repeating-linear-gradient(90deg,#d9cbc0 0 48px,#cbbfb3 48px 96px);
}
.wall{
    position:absolute;
    top:0;
    left:0;
    width:100%;
    height:300px;
    background:#f0e9df;
}
.sofa{
    position:absolute;
    bottom:130px;
    left:60px;
    width:220px;
    height:100px;
    background:#a1b4c7;
    border:4px solid #7c92a8;
    border-radius:12px 12px 0 0;
}
.table{
    position:absolute;
    bottom:130px;
    left:300px;
    width:130px;
    height:80px;
    background:#b8a08c;
    border:4px solid #947e6b;
}
.window{
    position:absolute;
    top:50px;
    right:160px;
    width:160px;
    height:110px;
    background:#c6e0ed;
    border:6px solid #967e6b;
}
.feeder{
    position:absolute;
    bottom:135px;
    right:60px;
    width:100px;
    height:55px;
    background:#ffd700;
    border:3px solid #e6b800;
    border-radius:10px;
    text-align:center;
    line-height:50px;
    font-size:14px;
    color:#7a5200;
    font-weight:bold;
}

/* 城市 */
.road{
    position:absolute;
    bottom:0;
    left:0;
    width:100%;
    height:140px;
    background:#6b7280;
}
.sidewalk{
    position:absolute;
    bottom:140px;
    left:0;
    width:100%;
    height:26px;
    background:#9ca3af;
}
.building{
    position:absolute;
    bottom:166px;
    background:#e5e7eb;
    border:3px solid #d1d5db;
    border-radius:4px 4px 0 0;
}
.hospital-sign{
    position:absolute;
    top:40px;
    left:80px;
    background:#ef4444;
    color:white;
    padding:10px 14px;
    border-radius:8px;
    font-size:15px;
}

/* 医院 */
.hospital-wall{
    width:100%;
    height:100%;
    background:#f7fafc;
    position:absolute;
}
.hospital-desk{
    position:absolute;
    bottom:130px;
    left:100px;
    width:180px;
    height:90px;
    background:#e2e8f0;
    border:3px solid #cbd5e0;
}
.hospital-bed{
    position:absolute;
    bottom:130px;
    right:100px;
    width:200px;
    height:100px;
    background:#ffffff;
    border:3px solid #94a3b8;
    border-radius:8px;
}

/* 人物和狗:低马赛克,不是硬像素 */
.master{
    position:absolute;
    bottom:130px;
    left:360px;
    width:68px;
    height:110px;
    filter:url(#softMosaic);
}
.dog{
    position:absolute;
    bottom:130px;
    width:76px;
    height:60px;
    filter:url(#softMosaic);
    transition:left 0.55s ease-in-out;
}
.dog-a{left:200px;}
.dog-b{left:290px;}
.dog-c{left:460px;}

/* 喂食动画 */
.food-bowl{
    position:absolute;
    bottom:138px;
    right:70px;
    width:80px;
    height:45px;
    background:#ffd700;
    border:3px solid #e6b800;
    border-radius:0 0 12px 12px;
    opacity:0;
    transform:translateY(-20px);
    transition:all 0.4s ease;
}
.food-bowl.show{
    opacity:1;
    transform:translateY(0);
}
.food-particle{
    position:absolute;
    width:6px;
    height:6px;
    background:#7a5200;
    border-radius:50%;
    animation:fall 0.5s ease-in forwards;
}
@keyframes fall{
    0%{transform:translateY(-30px);opacity:1;}
    100%{transform:translateY(0);opacity:0;}
}

/* 软走动动画 */
.walk-master{
    animation:walkMaster 0.38s infinite alternate ease-in-out;
}
.walk-dog{
    animation:walkDog 0.34s infinite alternate ease-in-out;
}
@keyframes walkMaster{
    0%{transform:translateY(0px);}
    100%{transform:translateY(-6px);}
}
@keyframes walkDog{
    0%{transform:translateY(0px) scaleX(1);}
    100%{transform:translateY(-5px) scaleX(1.03);}
}

/* 状态面板 */
.ui{
    margin-top:15px;
    background:white;
    padding:16px;
    border-radius:12px;
    border:2px solid #e2e8f0;
}
.dog-list{
    display:grid;
    grid-template-columns:1fr 1fr 1fr;
    gap:12px;
    margin-bottom:14px;
}
.dog-card{
    background:#f7fafc;
    padding:12px;
    border-radius:8px;
    border:2px solid #e2e8f0;
}
.bar{
    width:100%;
    height:13px;
    background:#e2e8f0;
    border-radius:6px;
    overflow:hidden;
    margin:5px 0;
}
.bar-fill{
    height:100%;
    background:#ffb852;
    transition:0.3s;
}
.bar-health{background:#48bb78;}
.bar-happy{background:#63b3ed;}
.bar-clean{background:#9f7aea;}

/* 按钮 */
.btns{
    display:grid;
    grid-template-columns:repeat(4,1fr);
    gap:10px;
    margin-top:14px;
}
button{
    padding:12px;
    border:none;
    border-radius:8px;
    background:#4a5568;
    color:white;
    font-size:14px;
    cursor:pointer;
}
button:hover{
    background:#2d3748;
}

/* 事件弹窗 */
.modal{
    position:fixed;
    top:0;
    left:0;
    width:100%;
    height:100%;
    background:rgba(0,0,0,0.45);
    display:none;
    align-items:center;
    justify-content:center;
    z-index:10;
}
.modal-box{
    background:white;
    width:90%;
    max-width:520px;
    padding:24px;
    border-radius:12px;
    text-align:center;
}
.modal-box h3{
    margin-bottom:14px;
    color:#2d3748;
}
.modal-box p{
    margin-bottom:18px;
    color:#4a5568;
    line-height:1.6;
}
.modal-choices{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:12px;
}

.tip{
    margin-top:14px;
    text-align:center;
    color:#c53030;
    height:24px;
}

/* 软马赛克滤镜 */
.svg-filters{
    position:absolute;
    width:0;
    height:0;
    overflow:hidden;
}
</style>
</head>
<body>

<div class="svg-filters">
<svg>
<filter id="softMosaic" x="0" y="0" width="100%" height="100%">
  <feFlood flood-color="transparent"/>
  <feMorphology operator="erode" radius="1.2"/>
  <feMorphology operator="dilate" radius="1.2"/>
  <feColorMatrix type="matrix" values="1.25 0 0 0 -0.12   0 1.25 0 0 -0.12   0 0 1.25 0 -0.12   0 0 0 1 0"/>
  <feComposite in2="SourceGraphic" operator="over"/>
</filter>
</svg>
</div>

<div class="wrap">
    <h2>城市养狗模拟器</h2>

    <div class="main-canvas" id="canvas">
        <!-- 家 -->
        <div class="scene scene-home" id="sceneHome">
            <div class="wall"></div>
            <div class="window"></div>
            <div class="sofa"></div>
            <div class="table"></div>
            <div class="feeder" id="feeder">食盆</div>
            <div class="food-bowl" id="foodBowl"></div>
            <div class="floor"></div>

            <div class="master" id="masterHome">
                <svg width="68" height="110" viewBox="0 0 68 110">
                    <rect x="15" y="0" width="38" height="20" fill="#443322"/>
                    <rect x="19" y="20" width="30" height="26" fill="#f8d6bc"/>
                    <rect x="23" y="28" width="5" height="5" fill="#222"/>
                    <rect x="40" y="28" width="5" height="5" fill="#222"/>
                    <rect x="11" y="46" width="46" height="38" fill="#6893c2"/>
                    <rect x="17" y="84" width="34" height="26" fill="#4c6b8c"/>
                </svg>
            </div>

            <div class="dog dog-a" id="dogA">
                <svg width="76" height="60" viewBox="0 0 76 60">
                    <rect x="10" y="6" width="56" height="30" fill="#f7b360"/>
                    <rect x="2" y="10" width="12" height="17" fill="#f7b360"/>
                    <rect x="62" y="10" width="12" height="17" fill="#f7b360"/>
                    <rect x="18" y="18" width="9" height="9" fill="#222"/>
                    <rect x="49" y="18" width="9" height="9" fill="#222"/>
                    <rect x="14" y="36" width="48" height="20" fill="#f7b360"/>
                    <rect x="12" y="50" width="15" height="10" fill="#e29c49"/>
                    <rect x="49" y="50" width="15" height="10" fill="#e29c49"/>
                </svg>
            </div>

            <div class="dog dog-b" id="dogB">
                <svg width="76" height="60" viewBox="0 0 76 60">
                    <rect x="8" y="4" width="60" height="34" fill="#e6b268"/>
                    <rect x="4" y="8" width="10" height="21" fill="#e6b268"/>
                    <rect x="62" y="8" width="10" height="21" fill="#e6b268"/>
                    <rect x="16" y="20" width="8" height="8" fill="#222"/>
                    <rect x="52" y="20" width="8" height="8" fill="#222"/>
                    <rect x="16" y="38" width="44" height="18" fill="#e6b268"/>
                    <rect x="10" y="52" width="13" height="8" fill="#d19a4e"/>
                    <rect x="53" y="52" width="13" height="8" fill="#d19a4e"/>
                </svg>
            </div>
        </div>

        <!-- 城市 -->
        <div class="scene scene-city" id="sceneCity">
            <div class="hospital-sign">🏥 宠物医院</div>
            <div class="building" style="left:40px;width:190px;height:230px;"></div>
            <div class="building" style="left:260px;width:240px;height:190px;"></div>
            <div class="building" style="right:40px;width:170px;height:250px;"></div>
            <div class="sidewalk"></div>
            <div class="road"></div>

            <div class="master" id="masterCity" style="left:140px;">
                <svg width="68" height="110" viewBox="0 0 68 110">
                    <rect x="15" y="0" width="38" height="20" fill="#443322"/>
                    <rect x="19" y="20" width="30" height="26" fill="#f8d6bc"/>
                    <rect x="23" y="28" width="5" height="5" fill="#222"/>
                    <rect x="40" y="28" width="5" height="5" fill="#222"/>
                    <rect x="11" y="46" width="46" height="38" fill="#6893c2"/>
                    <rect x="17" y="84" width="34" height="26" fill="#4c6b8c"/>
                </svg>
            </div>

            <div class="dog" id="dogCity" style="left:220px;">
                <svg width="76" height="60" viewBox="0 0 76 60">
                    <rect x="10" y="6" width="56" height="30" fill="#f7b360"/>
                    <rect x="2" y="10" width="12" height="17" fill="#f7b360"/>
                    <rect x="62" y="10" width="12" height="17" fill="#f7b360"/>
                    <rect x="18" y="18" width="9" height="9" fill="#222"/>
                    <rect x="49" y="18" width="9" height="9" fill="#222"/>
                    <rect x="14" y="36" width="48" height="20" fill="#f7b360"/>
                    <rect x="12" y="50" width="15" height="10" fill="#e29c49"/>
                    <rect x="49" y="50" width="15" height="10" fill="#e29c49"/>
                </svg>
            </div>
        </div>

        <!-- 医院 -->
        <div class="scene scene-hospital" id="sceneHospital">
            <div class="hospital-wall"></div>
            <div class="hospital-desk"></div>
            <div class="hospital-bed"></div>

            <div class="master" id="masterHospital" style="left:300px;">
                <svg width="68" height="110" viewBox="0 0 68 110">
                    <rect x="15" y="0" width="38" height="20" fill="#443322"/>
                    <rect x="19" y="20" width="30" height="26" fill="#f8d6bc"/>
                    <rect x="23" y="28" width="5" height="5" fill="#222"/>
                    <rect x="40" y="28" width="5" height="5" fill="#222"/>
                    <rect x="11" y="46" width="46" height="38" fill="#6893c2"/>
                    <rect x="17" y="84" width="34" height="26" fill="#4c6b8c"/>
                </svg>
            </div>

            <div class="dog" id="dogHospital" style="left:400px;">
                <svg width="76" height="60" viewBox="0 0 76 60">
                    <rect x="10" y="6" width="56" height="30" fill="#f7b360"/>
                    <rect x="2" y="10" width="12" height="17" fill="#f7b360"/>
                    <rect x="62" y="10" width="12" height="17" fill="#f7b360"/>
                    <rect x="18" y="18" width="9" height="9" fill="#222"/>
                    <rect x="49" y="18" width="9" height="9" fill="#222"/>
                    <rect x="14" y="36" width="48" height="20" fill="#f7b360"/>
                    <rect x="12" y="50" width="15" height="10" fill="#e29c49"/>
                    <rect x="49" y="50" width="15" height="10" fill="#e29c49"/>
                </svg>
            </div>
        </div>
    </div>

    <div class="ui">
        <p style="margin-bottom:12px;font-weight:bold;">多只小狗状态</p>
        <div class="dog-list" id="dogList"></div>

        <p>💰 金币:<span id="coin">120</span>|🏠 当前场景:<span id="currentScene">家</span></p>

        <div class="btns">
            <button onclick="feedAll()">喂食</button>
            <button onclick="walkCity()">城市遛狗</button>
            <button onclick="goHospital()">去医院</button>
            <button onclick="bathAll()">洗澡</button>
            <button onclick="playAll()">陪玩</button>
            <button onclick="healAll()">治疗</button>
            <button onclick="backHome()">回家</button>
            <button onclick="randomEvent()">随机事件</button>
        </div>

        <div class="tip" id="tip"></div>
    </div>
</div>

<!-- 事件弹窗 -->
<div class="modal" id="eventModal">
    <div class="modal-box">
        <h3 id="eventTitle">小狗事件</h3>
        <p id="eventText"></p>
        <div class="modal-choices" id="eventChoices"></div>
    </div>
</div>

<script>
let game = {
    coin:120,
    scene:"home",
    dogs:[
        {id:"a",name:"旺财",type:"柴犬",full:92,happy:88,clean:90,health:96},
        {id:"b",name:"豆豆",type:"金毛",full:85,happy:92,clean:84,health:92}
    ]
};

const dogListDom = document.getElementById("dogList");
const coinDom = document.getElementById("coin");
const sceneDom = document.getElementById("currentScene");
const tipDom = document.getElementById("tip");
const modal = document.getElementById("eventModal");
const eventTitle = document.getElementById("eventTitle");
const eventText = document.getElementById("eventText");
const eventChoices = document.getElementById("eventChoices");

const sceneHome = document.getElementById("sceneHome");
const sceneCity = document.getElementById("sceneCity");
const sceneHospital = document.getElementById("sceneHospital");

const masterHome = document.getElementById("masterHome");
const masterCity = document.getElementById("masterCity");
const masterHospital = document.getElementById("masterHospital");
const dogA = document.getElementById("dogA");
const dogB = document.getElementById("dogB");
const dogCity = document.getElementById("dogCity");
const dogHospital = document.getElementById("dogHospital");

const foodBowl = document.getElementById("foodBowl");

function renderDogList(){
    dogListDom.innerHTML = "";
    game.dogs.forEach(dog=>{
        const card = document.createElement("div");
        card.className = "dog-card";
        card.innerHTML = `
            <p style="font-weight:bold;margin-bottom:8px">${dog.name}(${dog.type})</p>
            <p>🍚 饱腹 ${dog.full}/100</p>
            <div class="bar"><div class="bar-fill" style="width:${dog.full}%"></div></div>
            <p>😊 开心 ${dog.happy}/100</p>
            <div class="bar"><div class="bar-fill bar-health" style="width:${dog.happy}%"></div></div>
            <p>🧼 干净 ${dog.clean}/100</p>
            <div class="bar"><div class="bar-fill bar-clean" style="width:${dog.clean}%"></div></div>
            <p>💊 健康 ${dog.health}/100</p>
            <div class="bar"><div class="bar-fill bar-health" style="width:${dog.health}%"></div></div>
        `;
        dogListDom.appendChild(card);
    });
}

function updateUI(){
    coinDom.innerText = game.coin;
    sceneDom.innerText = game.scene==="home"?"家":game.scene==="city"?"城市":"医院";
    renderDogList();
}

function setTip(text){
    tipDom.innerText = text;
    setTimeout(()=>tipDom.innerText="",2800);
}

function decayAll(){
    game.dogs.forEach(dog=>{
        dog.full = Math.max(0,dog.full-5);
        dog.happy = Math.max(0,dog.happy-3);
        dog.clean = Math.max(0,dog.clean-7);
        if(dog.full<25||dog.clean<25) dog.health = Math.max(0,dog.health-4);
    });
    updateUI();
}

function startWalk(){
    masterHome.classList.add("walk-master");
    masterCity.classList.add("walk-master");
    masterHospital.classList.add("walk-master");
    dogA.classList.add("walk-dog");
    dogB.classList.add("walk-dog");
    dogCity.classList.add("walk-dog");
    dogHospital.classList.add("walk-dog");
}

function stopWalk(){
    masterHome.classList.remove("walk-master");
    masterCity.classList.remove("walk-master");
    masterHospital.classList.remove("walk-master");
    dogA.classList.remove("walk-dog");
    dogB.classList.remove("walk-dog");
    dogCity.classList.remove("walk-dog");
    dogHospital.classList.remove("walk-dog");
}

function showFoodAnimation(){
    foodBowl.classList.add("show");

    for(let i=0;i<12;i++){
        setTimeout(()=>{
            const p = document.createElement("div");
            p.className = "food-particle";
            p.style.left = (70+Math.random()*60)+"px";
            p.style.bottom = "145px";
            document.getElementById("canvas").appendChild(p);
            setTimeout(()=>p.remove(),500);
        },i*40);
    }

    setTimeout(()=>foodBowl.classList.remove("show"),600);
}

function feedAll(){
    if(game.coin<12){
        setTip("金币不足,无法喂食!");
        return;
    }
    game.coin-=12;
    game.dogs.forEach(dog=>{
        dog.full = Math.min(100,dog.full+38);
    });
    showFoodAnimation();
    decayAll();
    updateUI();
    setTip("你给小狗们倒了狗粮,它们吃得很香!");
}

function bathAll(){
    if(game.coin<18){
        setTip("金币不足,不能洗澡!");
        return;
    }
    game.coin-=18;
    game.dogs.forEach(dog=>{
        dog.clean = 100;
    });
    decayAll();
    updateUI();
    setTip("小狗们洗完澡,毛毛蓬松又干净!");
}

function playAll(){
    game.dogs.forEach(dog=>{
        dog.happy = Math.min(100,dog.happy+42);
        dog.full = Math.max(0,dog.full-12);
    });
    startWalk();
    setTimeout(stopWalk,700);
    decayAll();
    updateUI();
    setTip("你和小狗们玩了球,气氛很热闹!");
}

function healAll(){
    if(game.scene!=="hospital"){
        setTip("只能在医院治疗小狗!");
        return;
    }
    if(game.coin<35){
        setTip("金币不足,无法治疗!");
        return;
    }
    game.coin-=35;
    game.dogs.forEach(dog=>{
        dog.health = 100;
    });
    decayAll();
    updateUI();
    setTip("兽医检查后,小狗们恢复了健康!");
}

function walkCity(){
    if(game.scene==="city"){
        setTip("你已经在城市里了!");
        return;
    }
    game.scene = "city";
    sceneHome.style.transform = "translateX(-100%)";
    sceneCity.style.transform = "translateX(0)";
    sceneHospital.style.transform = "translateX(100%)";
    startWalk();
    setTimeout(stopWalk,1200);
    game.dogs.forEach(dog=>{
        dog.happy = Math.min(100,dog.happy+32);
    });
    game.coin+=25;
    decayAll();
    updateUI();
    setTip("你带着小狗们来到城市街道散步。");
}

function goHospital(){
    if(game.scene==="hospital"){
        setTip("你已经在医院了!");
        return;
    }
    game.scene = "hospital";
    sceneHome.style.transform = "translateX(-200%)";
    sceneCity.style.transform = "translateX(-100%)";
    sceneHospital.style.transform = "translateX(0)";
    startWalk();
    setTimeout(stopWalk,1200);
    decayAll();
    updateUI();
    setTip("你到达宠物医院,可以治疗生病的小狗。");
}

function backHome(){
    if(game.scene==="home"){
        setTip("你已经在家了!");
        return;
    }
    game.scene = "home";
    sceneHome.style.transform = "translateX(0)";
    sceneCity.style.transform = "translateX(100%)";
    sceneHospital.style.transform = "translateX(200%)";
    startWalk();
    setTimeout(stopWalk,1200);
    decayAll();
    updateUI();
    setTip("你和小狗们回到了温暖的家。");
}

const events = [
    {
        title:"旺财打翻了食盆",
        text:"旺财突然把食盆推倒,狗粮撒了一地。豆豆也凑过去想吃地上的食物。",
        choices:[
            {text:"立刻重新喂食",action:()=>{
                if(game.coin>=12){
                    game.coin-=12;
                    game.dogs[0].full = Math.min(100,game.dogs[0].full+35);
                    game.dogs[1].full = Math.min(100,game.dogs[1].full+20);
                    showFoodAnimation();
                    setTip("你重新收拾并喂了两只小狗。");
                }else{
                    setTip("金币不够,只能先打扫地面。");
                }
            }},
            {text:"先批评再打扫",action:()=>{
                game.dogs[0].happy = Math.max(0,game.dogs[0].happy-18);
                setTip("旺财低着头,好像知道自己做错了。");
            }}
        ]
    },
    {
        title:"豆豆发现了玩具箱",
        text:"豆豆从沙发旁边叼出一个旧玩具球,它把球推到你脚边。",
        choices:[
            {text:"陪它玩一会儿",action:()=>{
                game.dogs[1].happy = Math.min(100,game.dogs[1].happy+38);
                startWalk();
                setTimeout(stopWalk,600);
                setTip("豆豆追着球跑,非常开心!");
            }},
            {text:"把玩具收起来",action:()=>{
                game.dogs[1].happy = Math.max(0,game.dogs[1].happy-10);
                setTip("豆豆有点失望,但还是安静地坐下了。");
            }}
        ]
    },
    {
        title:"旺财没精神",
        text:"旺财趴在垫子上,耳朵垂下来,鼻子有点干。它可能生病了。",
        choices:[
            {text:"带去医院检查",action:()=>{
                if(game.coin>=35){
                    game.coin-=35;
                    game.dogs[0].health = 100;
                    goHospital();
                    setTip("医生说只是小感冒,旺财很快恢复了。");
                }else{
                    setTip("金币不够,只能先观察一晚。");
                    game.dogs[0].health = Math.max(0,game.dogs[0].health-8);
                }
            }},
            {text:"在家休息观察",action:()=>{
                game.dogs[0].health = Math.max(0,game.dogs[0].health-6);
                setTip("旺财在家休息,状态没有明显好转。");
            }}
        ]
    },
    {
        title:"城市里遇到宠物零食车",
        text:"街角有一辆宠物零食车,两只小狗都停下脚步看着你。",
        choices:[
            {text:"买两份零食",action:()=>{
                if(game.coin>=28){
                    game.coin-=28;
                    game.dogs.forEach(d=>{
                        d.happy = Math.min(100,d.happy+28);
                        d.full = Math.min(100,d.full+22);
                    });
                    setTip("小狗们吃到零食,尾巴摇个不停!");
                }else{
                    setTip("金币不够,只能继续散步。");
                }
            }},
            {text:"只买一份给旺财",action:()=>{
                if(game.coin>=16){
                    game.coin-=16;
                    game.dogs[0].happy = Math.min(100,game.dogs[0].happy+22);
                    game.dogs[0].full = Math.min(100,game.dogs[0].full+18);
                    setTip("旺财吃到了零食,豆豆委屈地看着。");
                }else{
                    setTip("金币不够买零食。");
                }
            }}
        ]
    },
    {
        title:"家里来了客人",
        text:"门铃响了,朋友来做客。两只小狗立刻兴奋地围了上去。",
        choices:[
            {text:"让客人摸摸狗",action:()=>{
                game.dogs.forEach(d=>{
                    d.happy = Math.min(100,d.happy+22);
                });
                setTip("客人很喜欢小狗,家里变得很热闹。");
            }},
            {text:"先把小狗安顿好",action:()=>{
                game.dogs.forEach(d=>{
                    d.happy = Math.min(100,d.happy+10);
                });
                setTip("你把小狗带到旁边,客人顺利坐下聊天。");
            }}
        ]
    },
    {
        title:"豆豆在外面弄脏了",
        text:"豆豆在城市草地上滚了一圈,爪子和毛毛都变脏了。",
        choices:[
            {text:"回家立刻洗澡",action:()=>{
                if(game.coin>=18){
                    game.coin-=18;
                    game.dogs[1].clean = 100;
                    backHome();
                    setTip("豆豆洗干净后,毛毛又变蓬松了。");
                }else{
                    setTip("金币不够,只能先擦一擦。");
                    game.dogs[1].clean = Math.max(0,game.dogs[1].clean-12);
                }
            }},
            {text:"先回家再处理",action:()=>{
                game.dogs[1].clean = Math.max(0,game.dogs[1].clean-18);
                backHome();
                setTip("豆豆带着一身脏东西回了家。");
            }}
        ]
    }
];

function randomEvent(){
    const event = events[Math.floor(Math.random()*events.length)];
    eventTitle.innerText = event.title;
    eventText.innerText = event.text;
    eventChoices.innerHTML = "";

    event.choices.forEach(choice=>{
        const btn = document.createElement("button");
        btn.innerText = choice.text;
        btn.onclick = ()=>{
            choice.action();
            modal.style.display = "none";
        };
        eventChoices.appendChild(btn);
    });

    modal.style.display = "flex";
}

// 自动随机事件
setInterval(()=>{
    if(Math.random()<0.10){
        randomEvent();
    }
},15000);

// 初始化
renderDogList();
updateUI();
</script>

</body>
</html>

Game Source: 城市养狗模拟器

Creator: BraveDragon92

Libraries: none

Complexity: complex (907 lines, 27.0 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-bravedragon92" to link back to the original. Then publish at arcadelab.ai/publish.