跳到正文

剪贴板

剪贴板 31d97d7x

原文
剪贴板信息

剪贴板信息

收录
更新

快乐的来源:

愤怒的来源:

代码
顶

要顶

必须顶

不得不顶

用尽全力顶

再加上千斤顶

总之把它顶到顶

接着使出葵花宝顶

就算顶到史前也要顶

老子看了会用道德经顶

孔子亲自拜我为师天天顶

秦始皇站在阿房宫上使劲顶

汉高祖挥师杀向东罗马为我顶

吕布抛弃了貂禅而选择了帮我顶

张三丰见了后用太极拳九式全力顶

左冷禅召开武林盟主大会商讨如何顶

西门吹雪从此学会了最强一招剑神一顶

龙剑飞的如来神掌最后一式改为万佛朝顶

陆小凤从此再也不管闲事了而专门来为我顶

四大名捕四面出击看天下还有没有人敢不在顶

黄飞鸿的宝芝林里从此多了一味药叫做吃了就顶

霍元甲其实根本就没有死因为他还想要努力帮我顶

蒋介石之所以秃了顶就是因为天天晚上在费力为我顶

希特勒消失在人们的视线当中其实是在暗地里不断地顶

爱因斯坦宁愿自已把相对论彻底的否定也要来为我顶一顶

萨达姆成了亡国奴可是一直到现在都没有屈服而在拼命的顶

本拉登在曼哈顿不小心放了两个大花炮现在只能躲起来为我顶

小泉这厮本来不想让他顶但他有这么厚脸也没办法只能让他也顶

小布什调集了全球美军所有的战斧式巡航导弹向华盛顿发射来狂顶

阿扁的腿已吓得发颤大小便也已经失禁却还要硬着头皮说我就是要顶

外逃的贪官们已被抓回了一大批但还有一些心存侥幸的家伙在想办法顶

张艺谋为了表达心中对你的感慨而去专门拍了一部片子大红灯笼高高挂顶

超级女声的名头越来越响但实际上在她们内心的世界里只爱我一人只为我顶

姚明竭尽全力在总决赛第七场的最后一秒高高跳起不为了扣蓝而是为了帮我顶

乔丹在蓝球场上之所以这么伟大是因为他在多年前就预感到了伟大的你而为我顶

贝克汉姆在一场比赛里踢出了一百个香蕉球都被对手奋不顾身的往自家的球门里顶

国际乒联为了取悦于我而彻底的将乒乓球击球的规则由向前拍打改为只准用拍向前顶

全国人民代表大会所有委员一致通过将你的精神写进宪法让全国人民来一起围着我狂顶

所有的这一切都是你再世卧龙在背后所精心策划的为了让我能够光宗耀祖而煞费苦心的顶

 \

 \

代码
AC = All Crashed 全部崩溃

CE = Compile Easily 轻松编译

PC = Perfectly Correct 完全正确

WA = Wonderful Answer 很棒的答案 (我的头像)

RE = Run Efficently 运行效率高

TLE = Time Limit Enough 时间足够

MLE = Memory Limit Enough 空间足够

OLE = Output Limit Enough 输出足够

UKE = UFO Kills Errors 飞碟把错误杀了

AU = All Unaccepted 全部不正确

写代码的小女孩:


天冷极了,下着雪,又快黑了。这是NOIP的前夜。在这又冷又黑的晚上,一个衣衫破烂的小女孩在机房敲着代码。她从班里逃出来的时候还拿着一本算导,但是有什么用呢?那是一本很破旧的书——那么大,一向是她妈妈垫桌角的。她默写SPFA的时候,年级主任突然冲进机房,吓得她把算导都丢掉了。书叫一个学数竞捡起来拿着跑了。他说,他可以用那本书当草纸,证明切比雪夫定理。小女孩只好自己写二叉堆,一双小脚冻得红一块青一块的。她面前的草纸堆得满满的,上面全是DP转移方程。这一整天,没有一个OJ让她AC一道题,她已经交了32遍采药了。

可怜的小女孩!她又冷又饿,浑身战栗地写着二叉堆。CRT显示器发出的光落在她的枯黄的长头发上,那干枯的头发打成卷儿披在肩上,看上去就像二叉树,不过她没注意这些。每个显示器里都透出光来,机房里飘着一股CPU发糊的怪味,因为这是NOIP前夜——她可忘不了这个。 她在主函数前面停了下来,蜷着趴在键盘上。她觉得更冷了。她不敢回家,因为她还没调完二叉堆,没写对一个DP方程,教练一定会骂她的。再说,换成别的数据结构,一样写不出来。这些题都太水,虽然神犇都写过题解了,但是题解上一般都只有三个字:傻X题。   她几乎绝望了。啊,哪怕一个函数不会RE,对她也是有好处的!她每写一遍程序,跑出来的结果就不一样,要是她有数据,她就知道哪一个程序是算对了的。她得不到数据了,因为机房上不去网了,全校的网速都让隔壁的年级主任拿来下小电影了。如果能保证下一个程序能AC,她就敢再写几十KB的代码,但是她是不敢啊,她怕又算出来一个奇葩的结果来。   她新建了一个cpp重写了程序。编译通过了了,样例过了。这次,她感觉自己站在IOI的考场中AK。学校的大门上,贴着“我校学生以国际金牌向110周年校庆献礼”的条幅。在班级内的非诚勿扰中,全班男生都给她留了灯。这时候,程序又RE了,她面前只有cmd上的黑底白字。

她又写了一道模拟。这一回,她坐在美丽的二叉堆下。这棵二叉堆,比她在丽洁代码中看到的常数还要小,还要短。眼前是许多优美动人的ASCII码,那些都是她写的程序,各种可爱的指针在跳跃着,满世界都是系统栈,都在向她眨眼睛。小女孩向眼前的系统栈伸出手去。这时候,眼前的ASCII码还在,条幅还在,指针还在,年级主任还是和蔼地微笑着。只见那些代码那些指针越升越高越升越高,最后成了在天空中闪烁的星星。有一颗星星落下来了,在天空中划出了一道细长的红光。 “有一个什么人快要死了。”小女孩说。唯一疼她的学姐保送之前告诉过她:一颗星星落下来,就有一个灵魂要到上帝那儿去了。她notepad++中又写了一个快排。这一回,她把能用的IDE都用了。学姐出现在亮光里,是那么温和,那么快乐。 “学姐!”小女孩叫起来,“啊!请把我带走吧!我知道,系统栈一溢出,您就会不见的,像那校门的条幅,浮点数的精度,循环队列的空间一个样,就会不见的!”她赶紧编译了5KB的高精度模板,要把学姐留住。一大把程序发出强烈的光,把机房照得跟白天一样明亮。学姐从来没有像现在这样温柔,这样美丽。她把小女孩抱起来,搂在怀里。她们俩在光明和快乐中飞走了,越飞越高,飞到那没有DP,没有图论,也没有数据结构的地方去了。第二天清晨,这个小女孩坐在机房里,两腮通红,嘴上带着微笑。她死了,在NOIP的前夜死了。NOIP Day1的太阳升起来了,照在她小小的尸体上。小女孩坐在那儿,显示器上还有一坨编译过的代码。“她想好好复习复赛。”人们说。谁也不知道她曾经看到过多么美丽的东西,她曾经多么幸福,跟着她学姐一起走向新世界的幸福中去。

奇怪的符号:


☯♂⑨☣♛㍿✡◐◑◒◓☢☭☠☃Ⓗ❁❆✎

代码压行机

a+b problem 的137种写法

1101352=(114514+114514)∗(−11−4+5+14)+(114514+(114∗514+(11451+4+(−(1−14)∗51+4+11−4+5/1−4))))1101352 = (114514+114514)*(-11-4+5+14)+(114514+(114*514+(11451+4+(-(1-14)*51+4+11-4+5/1-4))))

恶臭数字论证器

城市交通模拟器

HTML
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>3D 城市交通模拟</title>
    <style>
        body {
            margin: 0;
            overflow: hidden;
            font-family: Arial, sans-serif;
        }
        #info {
            position: absolute;
            top: 10px;
            left: 10px;
            background: rgba(0,0,0,0.7);
            color: white;
            padding: 10px;
            border-radius: 5px;
            font-size: 14px;
            z-index: 100;
            max-width: 300px;
        }
        #controls {
            position: absolute;
            bottom: 10px;
            left: 10px;
            background: rgba(0,0,0,0.7);
            color: white;
            padding: 10px;
            border-radius: 5px;
            z-index: 100;
            display: flex;
            flex-wrap: wrap;
            max-width: 80%;
        }
        button {
            margin: 5px;
            padding: 5px 10px;
            cursor: pointer;
            background: #4CAF50;
            color: white;
            border: none;
            border-radius: 3px;
        }
        button:hover {
            background: #45a049;
        }
        #stats {
            position: absolute;
            top: 10px;
            right: 10px;
            background: rgba(0,0,0,0.7);
            color: white;
            padding: 10px;
            border-radius: 5px;
            font-size: 14px;
            z-index: 100;
        }
        .slider-container {
            margin: 5px;
            color: white;
        }
        .slider-container label {
            display: block;
            margin-bottom: 5px;
        }
    </style>
</head>
<body>
    <div id="info">
        <h2>3D 城市交通模拟</h2>
        <p>视角: <span id="view-mode">鸟瞰</span></p>
        <p>时间: <span id="time">12:00</span> <span id="day-night-text">(白天)</span></p>
        <p>天气: <span id="weather">晴朗</span></p>
        <p>交通流量: <span id="traffic">中等</span></p>
        <p>人口: <span id="population">20</span></p>
        <p>车辆: <span id="vehicle-count">10</span></p>
    </div>

    <div id="stats">
        <p>FPS: <span id="fps">0</span></p>
        <p>渲染时间: <span id="render-time">0</span>ms</p>
        <p>场景对象: <span id="scene-objects">0</span></p>
    </div>

    <div id="controls">
        <button id="toggle-view">切换视角</button>
        <button id="day-night">切换昼夜</button>
        <button id="add-car">添加汽车</button>
        <button id="add-bus">添加公交车</button>
        <button id="add-pedestrian">添加行人</button>
        <button id="toggle-traffic">切换交通灯</button>
        <button id="change-weather">改变天气</button>
        <button id="add-building">添加建筑</button>
        <button id="emergency">紧急事件</button>

        <div class="slider-container">
            <label for="traffic-density">交通密度</label>
            <input type="range" id="traffic-density" min="1" max="10" value="5">
        </div>

        <div class="slider-container">
            <label for="simulation-speed">模拟速度</label>
            <input type="range" id="simulation-speed" min="1" max="10" value="5">
        </div>
    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/loaders/GLTFLoader.min.js"></script>
    <script>
        // 性能监控
        const stats = {
            lastTime: performance.now(),
            frames: 0,
            fps: 0,
            renderTime: 0
        };

        // 初始化场景、相机和渲染器
        const scene = new THREE.Scene();
        scene.background = new THREE.Color(0x87CEEB); // 天空蓝

        const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
        camera.position.set(0, 150, 200);

        const renderer = new THREE.WebGLRenderer({ antialias: true });
        renderer.setSize(window.innerWidth, window.innerHeight);
        renderer.shadowMap.enabled = true;
        renderer.shadowMap.type = THREE.PCFSoftShadowMap;
        document.body.appendChild(renderer.domElement);

        // 添加轨道控制器
        const controls = new THREE.OrbitControls(camera, renderer.domElement);
        controls.enableDamping = true;
        controls.dampingFactor = 0.05;
        controls.minDistance = 50;
        controls.maxDistance = 500;

        // 添加环境光和方向光
        const ambientLight = new THREE.AmbientLight(0x404040);
        scene.add(ambientLight);

        const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
        directionalLight.position.set(100, 100, 50);
        directionalLight.castShadow = true;
        directionalLight.shadow.mapSize.width = 2048;
        directionalLight.shadow.mapSize.height = 2048;
        directionalLight.shadow.camera.near = 0.5;
        directionalLight.shadow.camera.far = 500;
        directionalLight.shadow.camera.left = -100;
        directionalLight.shadow.camera.right = 100;
        directionalLight.shadow.camera.top = 100;
        directionalLight.shadow.camera.bottom = -100;
        scene.add(directionalLight);

        // 创建地面
        const groundGeometry = new THREE.PlaneGeometry(500, 500);
        const groundMaterial = new THREE.MeshStandardMaterial({
            color: 0x3a5f0b,
            roughness: 0.8,
            metalness: 0.2
        });
        const ground = new THREE.Mesh(groundGeometry, groundMaterial);
        ground.rotation.x = -Math.PI / 2;
        ground.receiveShadow = true;
        scene.add(ground);

        // 添加网格辅助
        const gridHelper = new THREE.GridHelper(500, 50, 0x555555, 0x333333);
        scene.add(gridHelper);

        // 城市管理类
        class CityManager {
            constructor() {
                this.buildings = [];
                this.cars = [];
                this.buses = [];
                this.pedestrians = [];
                this.trains = [];
                this.airplanes = [];
                this.trafficLights = [];
                this.busStops = [];
                this.weather = 'sunny';
                this.time = 12 * 60; // 中午12点
                this.isDay = true;
                this.trafficDensity = 5;
                this.simulationSpeed = 5;
                this.emergencyMode = false;
                this.emergencyVehicles = [];
            }

            // 更新城市状态
            update(deltaTime) {
                // 更新时间
                this.time = (this.time + (0.1 * this.simulationSpeed / 5)) % (24 * 60);

                // 更新昼夜状态
                const newIsDay = this.time > 6 * 60 && this.time < 18 * 60;
                if (newIsDay !== this.isDay) {
                    this.isDay = newIsDay;
                    this.updateLighting();
                }

                // 更新所有交通工具
                this.cars.forEach(car => car.update(deltaTime, this));
                this.buses.forEach(bus => bus.update(deltaTime, this));
                this.pedestrians.forEach(ped => ped.update(deltaTime, this));
                this.trains.forEach(train => train.update(deltaTime, this));
                this.airplanes.forEach(plane => plane.update(deltaTime, this));
                this.emergencyVehicles.forEach(vehicle => vehicle.update(deltaTime, this));

                // 更新交通灯
                this.updateTrafficLights(deltaTime);
            }

            updateLighting() {
                if (this.isDay) {
                    ambientLight.intensity = 0.4;
                    directionalLight.intensity = 0.8;
                } else {
                    ambientLight.intensity = 0.1;
                    directionalLight.intensity = 0.3;
                }

                // 根据天气调整光照
                if (this.weather === 'rainy' || this.weather === 'foggy') {
                    ambientLight.intensity *= 0.7;
                    directionalLight.intensity *= 0.5;
                }
            }

            updateTrafficLights(deltaTime) {
                const trafficLightInterval = 10 * 1000 / (this.trafficDensity / 5);

                this.trafficLights.forEach(light => {
                    light.timer += deltaTime;

                    if (light.timer >= trafficLightInterval) {
                        light.timer = 0;
                        light.changeState();
                    }
                });
            }

            // 添加随机建筑
            addRandomBuilding() {
                const width = Math.random() * 20 + 10;
                const height = Math.random() * 50 + 20;
                const depth = Math.random() * 20 + 10;
                const color = new THREE.Color(
                    Math.random() * 0.2 + 0.7,
                    Math.random() * 0.2 + 0.7,
                    Math.random() * 0.2 + 0.7
                );
                let x, z;

                // 确保建筑不会太靠近中心区域
                do {
                    x = Math.random() * 400 - 200;
                    z = Math.random() * 400 - 200;
                } while (Math.abs(x) < 50 && Math.abs(z) < 50);

                const building = new Building(width, height, depth, color, x, z);
                this.buildings.push(building);
                scene.add(building.group);

                return building;
            }

            // 添加随机汽车
            addRandomCar() {
                const direction = Math.floor(Math.random() * 4) * Math.PI / 2;
                let x, z;

                switch (direction) {
                    case 0: // 东
                        x = -250;
                        z = Math.random() * 100 - 50;
                        break;
                    case Math.PI / 2: // 北
                        x = Math.random() * 100 - 50;
                        z = 250;
                        break;
                    case Math.PI: // 西
                        x = 250;
                        z = Math.random() * 100 - 50;
                        break;
                    case Math.PI * 3 / 2: // 南
                        x = Math.random() * 100 - 50;
                        z = -250;
                        break;
                }

                const color = new THREE.Color(
                    Math.random(),
                    Math.random(),
                    Math.random()
                );

                const car = new Car(color, x, z, direction);
                this.cars.push(car);
                scene.add(car.group);

                return car;
            }

            // 添加随机行人
            addRandomPedestrian() {
                const x = Math.random() * 100 - 50;
                const z = Math.random() * 100 - 50;

                const pedestrian = new Pedestrian(x, z);
                this.pedestrians.push(pedestrian);
                scene.add(pedestrian.group);

                return pedestrian;
            }

            // 添加紧急车辆
            addEmergencyVehicle() {
                const directions = [0, Math.PI/2, Math.PI, Math.PI*3/2];
                const direction = directions[Math.floor(Math.random() * 4)];
                let x, z;

                switch (direction) {
                    case 0: // 东
                        x = -250;
                        z = Math.random() * 100 - 50;
                        break;
                    case Math.PI / 2: // 北
                        x = Math.random() * 100 - 50;
                        z = 250;
                        break;
                    case Math.PI: // 西
                        x = 250;
                        z = Math.random() * 100 - 50;
                        break;
                    case Math.PI * 3 / 2: // 南
                        x = Math.random() * 100 - 50;
                        z = -250;
                        break;
                }

                const type = Math.random() > 0.5 ? 'police' : 'ambulance';
                const vehicle = new EmergencyVehicle(type, x, z, direction);
                this.emergencyVehicles.push(vehicle);
                scene.add(vehicle.group);

                // 让其他车辆让路
                this.cars.forEach(car => {
                    const dx = car.group.position.x - x;
                    const dz = car.group.position.z - z;
                    const distance = Math.sqrt(dx * dx + dz * dz);

                    if (distance < 50) {
                        car.speed = 0.2; // 减速
                        car.waiting = true;
                        setTimeout(() => {
                            car.speed = Math.random() * 0.5 + 0.5;
                            car.waiting = false;
                        }, 3000);
                    }
                });

                return vehicle;
            }

            // 改变天气
            changeWeather() {
                const weatherTypes = ['sunny', 'rainy', 'foggy', 'cloudy'];
                this.weather = weatherTypes[(weatherTypes.indexOf(this.weather) + 1) % weatherTypes.length];
                this.updateWeatherEffects();
            }

            updateWeatherEffects() {
                // 这里可以添加天气特效,如雨、雾等
                // 简化实现,只更新UI
                document.getElementById('weather').textContent =
                    this.weather === 'sunny' ? '晴朗' :
                    this.weather === 'rainy' ? '雨天' :
                    this.weather === 'foggy' ? '雾天' : '多云';

                this.updateLighting();
            }

            // 初始化城市
            initialize() {
                // 创建道路
                this.createRoads();

                // 创建交通灯
                this.createTrafficLights();

                // 创建公交站
                this.createBusStops();

                // 创建基础设施
                this.createInfrastructure();

                // 初始化随机建筑
                for (let i = 0; i < 50; i++) {
                    this.addRandomBuilding();
                }

                // 初始化随机汽车
                for (let i = 0; i < 10; i++) {
                    this.addRandomCar();
                }

                // 初始化公交车
                this.initializeBuses();

                // 初始化随机行人
                for (let i = 0; i < 20; i++) {
                    this.addRandomPedestrian();
                }

                // 初始化火车
                this.initializeTrains();

                // 初始化飞机
                this.initializeAirplanes();
            }

            createRoads() {
                // 主道路
                new Road(30, 500, 0, 0, 0); // 水平主路
                new Road(30, 500, Math.PI / 2, 0, 0); // 垂直主路

                // 次要道路
                new Road(20, 500, 0, 100, 0);
                new Road(20, 500, 0, -100, 0);
                new Road(20, 500, Math.PI / 2, 0, 100);
                new Road(20, 500, Math.PI / 2, 0, -100);
            }

            createTrafficLights() {
                // 创建四个方向的交通灯
                this.trafficLights = [
                    new TrafficLight(-15, 0, Math.PI / 2), // 西向
                    new TrafficLight(15, 0, -Math.PI / 2), // 东向
                    new TrafficLight(0, -15, 0), // 南向
                    new TrafficLight(0, 15, Math.PI) // 北向
                ];

                // 设置初始交通灯状态
                this.trafficLights[0].setState('green');
                this.trafficLights[1].setState('green');
                this.trafficLights[2].setState('red');
                this.trafficLights[3].setState('red');
            }

            createBusStops() {
                this.busStops = [
                    new BusStop(-100, 30),
                    new BusStop(-50, -30),
                    new BusStop(50, 30),
                    new BusStop(100, -30)
                ];
            }

            createInfrastructure() {
                // 创建火车站
                new TrainStation(-150, 0, Math.PI / 2);
                new TrainStation(150, 0, -Math.PI / 2);

                // 创建机场
                new Airport(0, -180, 0);

                // 添加天空盒
                this.createSkybox();

                // 添加太阳
                this.createSun();
            }

            initializeBuses() {
                const bus1 = new Bus(-100, 30, 0);
                bus1.stops = [
                    { x: -100, z: 30 },
                    { x: -50, z: -30 },
                    { x: 50, z: 30 },
                    { x: 100, z: -30 }
                ];
                this.buses.push(bus1);
                scene.add(bus1.group);

                const bus2 = new Bus(100, -30, Math.PI);
                bus2.stops = [
                    { x: 100, z: -30 },
                    { x: 50, z: 30 },
                    { x: -50, z: -30 },
                    { x: -100, z: 30 }
                ];
                this.buses.push(bus2);
                scene.add(bus2.group);
            }

            initializeTrains() {
                const train1 = new Train(-200, 0, 0);
                train1.stations = [
                    { x: -200, z: 0 },
                    { x: -150, z: 0 },
                    { x: 150, z: 0 },
                    { x: 200, z: 0 }
                ];
                this.trains.push(train1);
                scene.add(train1.group);
            }

            initializeAirplanes() {
                const airplane1 = new Airplane(0, 100, -300, 0);
                airplane1.state = 'flying';
                this.airplanes.push(airplane1);
                scene.add(airplane1.group);

                const airplane2 = new Airplane(50, 0, -180, 0);
                airplane2.state = 'parked';
                this.airplanes.push(airplane2);
                scene.add(airplane2.group);
            }

            createSkybox() {
                const skyGeometry = new THREE.SphereGeometry(1000, 32, 32);
                const skyMaterial = new THREE.MeshBasicMaterial({
                    color: 0x87CEEB,
                    side: THREE.BackSide
                });
                const sky = new THREE.Mesh(skyGeometry, skyMaterial);
                scene.add(sky);
                this.sky = sky;
                this.skyMaterial = skyMaterial;
            }

            createSun() {
                const sunGeometry = new THREE.SphereGeometry(10, 32, 32);
                const sunMaterial = new THREE.MeshBasicMaterial({ color: 0xffff00 });
                const sun = new THREE.Mesh(sunGeometry, sunMaterial);
                scene.add(sun);
                this.sun = sun;
            }

            // 更新UI信息
            updateUI() {
                const hours = Math.floor(this.time / 60);
                const minutes = Math.floor(this.time % 60);
                document.getElementById('time').textContent =
                    `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`;
                document.getElementById('day-night-text').textContent = this.isDay ? '(白天)' : '(夜晚)';
                document.getElementById('population').textContent = this.pedestrians.length;
                document.getElementById('vehicle-count').textContent = this.cars.length + this.buses.length;

                // 更新交通流量显示
                const trafficLevels = ['很低', '低', '中等', '高', '很高'];
                document.getElementById('traffic').textContent =
                    trafficLevels[Math.floor(this.trafficDensity / 2) - 1] || '中等';
            }
        }

        // 建筑类
        class Building {
            constructor(width, height, depth, color, x, z) {
                this.width = width;
                this.height = height;
                this.depth = depth;
                this.color = color;
                this.x = x;
                this.z = z;

                this.createBuilding();
            }

            createBuilding() {
                this.group = new THREE.Group();

                // 主体
                const geometry = new THREE.BoxGeometry(this.width, this.height, this.depth);
                const material = new THREE.MeshStandardMaterial({ color: this.color });
                const building = new THREE.Mesh(geometry, material);
                building.position.set(0, this.height / 2, 0);
                building.castShadow = true;
                building.receiveShadow = true;
                this.group.add(building);

                // 随机添加窗户
                const windowGeometry = new THREE.BoxGeometry(1, 1, 0.5);
                const windowMaterial = new THREE.MeshStandardMaterial({
                    color: 0xadd8e6,
                    transparent: true,
                    opacity: 0.7
                });

                const rows = Math.floor(this.height / 5);
                const cols = Math.floor(this.width / 4);
                const layers = Math.floor(this.depth / 4);

                for (let r = 0; r < rows; r++) {
                    for (let c = 0; c < cols; c++) {
                        const window = new THREE.Mesh(windowGeometry, windowMaterial);
                        window.position.set(
                            -this.width/2 + (c + 0.5) * (this.width / cols),
                            5 + r * 5,
                            this.depth/2 + 0.1
                        );
                        this.group.add(window);

                        if (layers > 1) {
                            const backWindow = new THREE.Mesh(windowGeometry, windowMaterial);
                            backWindow.position.set(
                                -this.width/2 + (c + 0.5) * (this.width / cols),
                                5 + r * 5,
                                -this.depth/2 - 0.1
                            );
                            this.group.add(backWindow);
                        }
                    }
                }

                // 随机添加屋顶装饰
                if (Math.random() > 0.7) {
                    const roofGeometry = new THREE.ConeGeometry(this.width/2 * 0.8, 10, 4);
                    const roofMaterial = new THREE.MeshStandardMaterial({ color: 0x888888 });
                    const roof = new THREE.Mesh(roofGeometry, roofMaterial);
                    roof.position.set(0, this.height + 5, 0);
                    roof.castShadow = true;
                    this.group.add(roof);
                }

                this.group.position.set(this.x, 0, this.z);
            }
        }

        // 道路类
        class Road {
            constructor(width, length, rotation, x, z) {
                this.width = width;
                this.length = length;
                this.rotation = rotation;
                this.x = x;
                this.z = z;

                this.createRoad();
            }

            createRoad() {
                const geometry = new THREE.PlaneGeometry(this.width, this.length);
                const material = new THREE.MeshStandardMaterial({
                    color: 0x333333,
                    roughness: 0.9,
                    metalness: 0.1
                });
                const road = new THREE.Mesh(geometry, material);
                road.rotation.x = -Math.PI / 2;
                if (this.rotation) road.rotation.y = this.rotation;
                road.position.set(this.x, 0.1, this.z);
                road.receiveShadow = true;
                scene.add(road);

                // 添加道路标记
                if (this.rotation === 0 || this.rotation === Math.PI) {
                    // 水平道路
                    for (let i = -this.length/2 + 5; i < this.length/2; i += 10) {
                        const lineGeometry = new THREE.PlaneGeometry(this.width * 0.8, 1);
                        const lineMaterial = new THREE.MeshStandardMaterial({ color: 0xffff00 });
                        const line = new THREE.Mesh(lineGeometry, lineMaterial);
                        line.rotation.x = -Math.PI / 2;
                        line.position.set(this.x, 0.11, this.z + i);
                        scene.add(line);
                    }
                } else {
                    // 垂直道路
                    for (let i = -this.length/2 + 5; i < this.length/2; i += 10) {
                        const lineGeometry = new THREE.PlaneGeometry(1, this.width * 0.8);
                        const lineMaterial = new THREE.MeshStandardMaterial({ color: 0xffff00 });
                        const line = new THREE.Mesh(lineGeometry, lineMaterial);
                        line.rotation.x = -Math.PI / 2;
                        line.position.set(this.x + i, 0.11, this.z);
                        scene.add(line);
                    }
                }
            }
        }

        // 交通灯类
        class TrafficLight {
            constructor(x, z, rotation) {
                this.x = x;
                this.z = z;
                this.rotation = rotation;
                this.state = 'red'; // 'red', 'yellow', 'green'
                this.timer = 0;

                this.createTrafficLight();
            }

            createTrafficLight() {
                this.group = new THREE.Group();

                // 灯柱
                const poleGeometry = new THREE.CylinderGeometry(0.5, 0.5, 8, 8);
                const poleMaterial = new THREE.MeshStandardMaterial({ color: 0x333333 });
                const pole = new THREE.Mesh(poleGeometry, poleMaterial);
                pole.position.set(0, 4, 0);
                pole.castShadow = true;
                this.group.add(pole);

                // 灯箱
                const boxGeometry = new THREE.BoxGeometry(2, 6, 1);
                const boxMaterial = new THREE.MeshStandardMaterial({ color: 0x222222 });
                const box = new THREE.Mesh(boxGeometry, boxMaterial);
                box.position.set(0, 9, 0);
                box.castShadow = true;
                this.group.add(box);

                // 红灯
                const redLightGeometry = new THREE.SphereGeometry(0.5, 16, 16);
                this.redLightMaterial = new THREE.MeshStandardMaterial({
                    color: 0xff0000,
                    emissive: 0xff0000,
                    emissiveIntensity: 0
                });
                const redLight = new THREE.Mesh(redLightGeometry, this.redLightMaterial);
                redLight.position.set(0, 10.5, 0.6);
                this.group.add(redLight);

                // 黄灯
                const yellowLightGeometry = new THREE.SphereGeometry(0.5, 16, 16);
                this.yellowLightMaterial = new THREE.MeshStandardMaterial({
                    color: 0xffff00,
                    emissive: 0xffff00,
                    emissiveIntensity: 0
                });
                const yellowLight = new THREE.Mesh(yellowLightGeometry, this.yellowLightMaterial);
                yellowLight.position.set(0, 9, 0.6);
                this.group.add(yellowLight);

                // 绿灯
                const greenLightGeometry = new THREE.SphereGeometry(0.5, 16, 16);
                this.greenLightMaterial = new THREE.MeshStandardMaterial({
                    color: 0x00ff00,
                    emissive: 0x00ff00,
                    emissiveIntensity: 0
                });
                const greenLight = new THREE.Mesh(greenLightGeometry, this.greenLightMaterial);
                greenLight.position.set(0, 7.5, 0.6);
                this.group.add(greenLight);

                this.group.position.set(this.x, 0, this.z);
                this.group.rotation.y = this.rotation;
            }

            setState(state) {
                this.state = state;
                this.redLightMaterial.emissiveIntensity = state === 'red' ? 1 : 0;
                this.yellowLightMaterial.emissiveIntensity = state === 'yellow' ? 1 : 0;
                this.greenLightMaterial.emissiveIntensity = state === 'green' ? 1 : 0;
            }

            changeState() {
                if (this.state === 'red') {
                    this.setState('green');
                } else if (this.state === 'green') {
                    this.setState('yellow');
                } else {
                    this.setState('red');
                }
            }
        }

        // 汽车类
        class Car {
            constructor(color, x, z, direction) {
                this.color = color;
                this.x = x;
                this.z = z;
                this.direction = direction;
                this.speed = Math.random() * 0.5 + 0.5;
                this.waiting = false;
                this.path = [];
                this.originalSpeed = this.speed;

                this.createCar();
            }

            createCar() {
                this.group = new THREE.Group();

                // 车身
                const bodyGeometry = new THREE.BoxGeometry(5, 2, 10);
                const bodyMaterial = new THREE.MeshStandardMaterial({ color: this.color });
                const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
                body.position.set(0, 1, 0);
                body.castShadow = true;
                this.group.add(body);

                // 车窗
                const windowGeometry = new THREE.BoxGeometry(4.5, 1.5, 4);
                const windowMaterial = new THREE.MeshStandardMaterial({
                    color: 0xadd8e6,
                    transparent: true,
                    opacity: 0.7
                });
                const frontWindow = new THREE.Mesh(windowGeometry, windowMaterial);
                frontWindow.position.set(0, 2.5, 2.5);
                this.group.add(frontWindow);

                const backWindow = new THREE.Mesh(windowGeometry, windowMaterial);
                backWindow.position.set(0, 2.5, -2.5);
                this.group.add(backWindow);

                // 车轮
                const wheelGeometry = new THREE.CylinderGeometry(0.8, 0.8, 1, 16);
                const wheelMaterial = new THREE.MeshStandardMaterial({ color: 0x222222 });

                const wheel1 = new THREE.Mesh(wheelGeometry, wheelMaterial);
                wheel1.rotation.z = Math.PI / 2;
                wheel1.position.set(-2.5, 0.5, 3.5);
                wheel1.castShadow = true;
                this.wheel1 = wheel1;
                this.group.add(wheel1);

                const wheel2 = new THREE.Mesh(wheelGeometry, wheelMaterial);
                wheel2.rotation.z = Math.PI / 2;
                wheel2.position.set(2.5, 0.5, 3.5);
                wheel2.castShadow = true;
                this.wheel2 = wheel2;
                this.group.add(wheel2);

                const wheel3 = new THREE.Mesh(wheelGeometry, wheelMaterial);
                wheel3.rotation.z = Math.PI / 2;
                wheel3.position.set(-2.5, 0.5, -3.5);
                wheel3.castShadow = true;
                this.wheel3 = wheel3;
                this.group.add(wheel3);

                const wheel4 = new THREE.Mesh(wheelGeometry, wheelMaterial);
                wheel4.rotation.z = Math.PI / 2;
                wheel4.position.set(2.5, 0.5, -3.5);
                wheel4.castShadow = true;
                this.wheel4 = wheel4;
                this.group.add(wheel4);

                this.group.position.set(this.x, 0, this.z);
                this.group.rotation.y = this.direction;
            }

            update(deltaTime, city) {
                if (this.waiting) {
                    // 检查前方交通灯状态
                    const inIntersection = Math.abs(this.group.position.x) < 20 && Math.abs(this.group.position.z) < 20;

                    if (!inIntersection) {
                        let trafficLight = null;

                        if (Math.abs(this.direction) < 0.1) { // 东向
                            trafficLight = city.trafficLights[1];
                        } else if (Math.abs(this.direction - Math.PI / 2) < 0.1) { // 北向
                            trafficLight = city.trafficLights[3];
                        } else if (Math.abs(this.direction - Math.PI) < 0.1) { // 西向
                            trafficLight = city.trafficLights[0];
                        } else if (Math.abs(this.direction - Math.PI * 3 / 2) < 0.1) { // 南向
                            trafficLight = city.trafficLights[2];
                        }

                        if (trafficLight && trafficLight.state !== 'red') {
                            this.waiting = false;
                            this.speed = this.originalSpeed;
                        }
                    } else {
                        this.waiting = false;
                        this.speed = this.originalSpeed;
                    }
                }

                if (!this.waiting) {
                    // 简单路径跟随
                    if (this.path.length > 0) {
                        const target = this.path[0];
                        const dx = target.x - this.group.position.x;
                        const dz = target.z - this.group.position.z;
                        const distance = Math.sqrt(dx * dx + dz * dz);

                        if (distance < 5) {
                            this.path.shift();
                        } else {
                            const angle = Math.atan2(dx, dz);
                            this.group.rotation.y = angle;
                            this.direction = angle;

                            this.group.position.x += Math.sin(this.direction) * this.speed * (deltaTime / 16);
                            this.group.position.z += Math.cos(this.direction) * this.speed * (deltaTime / 16);
                        }
                    } else {
                        // 随机移动
                        this.group.position.x += Math.sin(this.direction) * this.speed * (deltaTime / 16);
                        this.group.position.z += Math.cos(this.direction) * this.speed * (deltaTime / 16);

                        // 检查是否到达边界或需要转弯
                        if (Math.abs(this.group.position.x) > 240 || Math.abs(this.group.position.z) > 240) {
                            this.direction = (this.direction + Math.PI / 2) % (Math.PI * 2);
                            this.group.rotation.y = this.direction;
                        }

                        // 检查是否需要停车(在红灯前)
                        const inIntersection = Math.abs(this.group.position.x) < 20 && Math.abs(this.group.position.z) < 20;

                        if (!inIntersection) {
                            if (Math.abs(this.group.position.x) < 25 && Math.abs(this.direction) < 0.1) { // 东向接近路口
                                const trafficLight = city.trafficLights[1];
                                if (trafficLight.state === 'red') {
                                    this.waiting = true;
                                    this.speed = 0.2;
                                }
                            } else if (Math.abs(this.group.position.x) < 25 && Math.abs(this.direction - Math.PI) < 0.1) { // 西向接近路口
                                const trafficLight = city.trafficLights[0];
                                if (trafficLight.state === 'red') {
                                    this.waiting = true;
                                    this.speed = 0.2;
                                }
                            } else if (Math.abs(this.group.position.z) < 25 && Math.abs(this.direction - Math.PI / 2) < 0.1) { // 北向接近路口
                                const trafficLight = city.trafficLights[3];
                                if (trafficLight.state === 'red') {
                                    this.waiting = true;
                                    this.speed = 0.2;
                                }
                            } else if (Math.abs(this.group.position.z) < 25 && Math.abs(this.direction - Math.PI * 3 / 2) < 0.1) { // 南向接近路口
                                const trafficLight = city.trafficLights[2];
                                if (trafficLight.state === 'red') {
                                    this.waiting = true;
                                    this.speed = 0.2;
                                }
                            }
                        }
                    }
                }

                // 更新车轮旋转
                if (!this.waiting) {
                    const rotationSpeed = this.speed * 0.5 * (deltaTime / 16);
                    this.wheel1.rotation.x += rotationSpeed;
                    this.wheel2.rotation.x += rotationSpeed;
                    this.wheel3.rotation.x += rotationSpeed;
                    this.wheel4.rotation.x += rotationSpeed;
                }
            }
        }

        // 公交车类
        class Bus {
            constructor(x, z, direction) {
                this.x = x;
                this.z = z;
                this.direction = direction;
                this.speed = Math.random() * 0.3 + 0.3;
                this.waitingTime = undefined;
                this.stops = [];
                this.currentStop = 0;

                this.createBus();
            }

            createBus() {
                this.group = new THREE.Group();

                // 车身
                const bodyGeometry = new THREE.BoxGeometry(6, 4, 15);
                const bodyMaterial = new THREE.MeshStandardMaterial({ color: 0xff6600 });
                const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
                body.position.set(0, 2, 0);
                body.castShadow = true;
                this.group.add(body);

                // 车窗
                const windowGeometry = new THREE.BoxGeometry(5.5, 2, 3);
                const windowMaterial = new THREE.MeshStandardMaterial({
                    color: 0xadd8e6,
                    transparent: true,
                    opacity: 0.7
                });

                for (let i = 0; i < 4; i++) {
                    const window = new THREE.Mesh(windowGeometry, windowMaterial);
                    window.position.set(0, 4, -5 + i * 3.5);
                    this.group.add(window);
                }

                // 车轮
                const wheelGeometry = new THREE.CylinderGeometry(1, 1, 1.5, 16);
                const wheelMaterial = new THREE.MeshStandardMaterial({ color: 0x222222 });

                this.wheels = [];
                for (let i = -2; i <= 1; i++) {
                    for (let j = 0; j < 2; j++) {
                        const wheel = new THREE.Mesh(wheelGeometry, wheelMaterial);
                        wheel.rotation.z = Math.PI / 2;
                        wheel.position.set(j === 0 ? -3 : 3, 0.5, i * 5);
                        wheel.castShadow = true;
                        this.wheels.push(wheel);
                        this.group.add(wheel);
                    }
                }

                this.group.position.set(this.x, 0, this.z);
                this.group.rotation.y = this.direction;
            }

            update(deltaTime, city) {
                if (this.currentStop < this.stops.length) {
                    const target = this.stops[this.currentStop];
                    const dx = target.x - this.group.position.x;
                    const dz = target.z - this.group.position.z;
                    const distance = Math.sqrt(dx * dx + dz * dz);

                    if (distance < 5) {
                        // 到达站点,等待一会儿
                        if (this.waitingTime === undefined) {
                            this.waitingTime = 0;
                        } else {
                            this.waitingTime += deltaTime;

                            if (this.waitingTime > 3000) { // 等待3秒
                                this.waitingTime = undefined;
                                this.currentStop = (this.currentStop + 1) % this.stops.length;
                            }
                        }
                    } else {
                        // 计算方向并移动
                        const angle = Math.atan2(dx, dz);
                        this.group.rotation.y = angle;
                        this.direction = angle;

                        this.group.position.x += Math.sin(this.direction) * this.speed * (deltaTime / 16);
                        this.group.position.z += Math.cos(this.direction) * this.speed * (deltaTime / 16);
                    }
                }

                // 更新车轮旋转
                if (this.waitingTime === undefined) {
                    const rotationSpeed = this.speed * 0.3 * (deltaTime / 16);
                    this.wheels.forEach(wheel => {
                        wheel.rotation.x += rotationSpeed;
                    });
                }
            }
        }

        // 行人类
        class Pedestrian {
            constructor(x, z) {
                this.x = x;
                this.z = z;
                this.speed = Math.random() * 0.1 + 0.05;
                this.direction = Math.random() * Math.PI * 2;
                this.target = null;
                this.animationTime = 0;

                this.createPedestrian();
            }

            createPedestrian() {
                this.group = new THREE.Group();

                // 身体
                const bodyGeometry = new THREE.BoxGeometry(1, 3, 1);
                const bodyMaterial = new THREE.MeshStandardMaterial({ color: 0x3333ff });
                const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
                body.position.set(0, 1.5, 0);
                body.castShadow = true;
                this.group.add(body);

                // 头
                const headGeometry = new THREE.SphereGeometry(0.7);
                const headMaterial = new THREE.MeshStandardMaterial({ color: 0xffdbac });
                const head = new THREE.Mesh(headGeometry, headMaterial);
                head.position.set(0, 3.2, 0);
                head.castShadow = true;
                this.group.add(head);

                // 腿
                const legGeometry = new THREE.BoxGeometry(0.3, 1, 0.3);
                const legMaterial = new THREE.MeshStandardMaterial({ color: 0x0000aa });

                const leftLeg = new THREE.Mesh(legGeometry, legMaterial);
                leftLeg.position.set(-0.2, 0.5, 0);
                this.leftLeg = leftLeg;
                this.group.add(leftLeg);

                const rightLeg = new THREE.Mesh(legGeometry, legMaterial);
                rightLeg.position.set(0.2, 0.5, 0);
                this.rightLeg = rightLeg;
                this.group.add(rightLeg);

                this.group.position.set(this.x, 0, this.z);
            }

            update(deltaTime, city) {
                this.animationTime += deltaTime;

                // 行走动画
                if (!this.target) {
                    const legAngle = Math.sin(this.animationTime * 0.01) * 0.5;
                    this.leftLeg.rotation.x = legAngle;
                    this.rightLeg.rotation.x = -legAngle;
                }

                if (this.target) {
                    const dx = this.target.x - this.group.position.x;
                    const dz = this.target.z - this.group.position.z;
                    const distance = Math.sqrt(dx * dx + dz * dz);

                    if (distance < 1) {
                        this.target = null;
                    } else {
                        this.direction = Math.atan2(dx, dz);
                        this.group.rotation.y = this.direction;

                        this.group.position.x += Math.sin(this.direction) * this.speed * (deltaTime / 16);
                        this.group.position.z += Math.cos(this.direction) * this.speed * (deltaTime / 16);
                    }
                } else {
                    // 随机移动或设置新目标
                    if (Math.random() < 0.01 * (deltaTime / 16)) {
                        this.direction = Math.random() * Math.PI * 2;
                    }

                    this.group.position.x += Math.sin(this.direction) * this.speed * (deltaTime / 16);
                    this.group.position.z += Math.cos(this.direction) * this.speed * (deltaTime / 16);

                    // 检查是否需要新目标
                    if (Math.random() < 0.005 * (deltaTime / 16)) {
                        this.target = {
                            x: this.group.position.x + (Math.random() * 40 - 20),
                            z: this.group.position.z + (Math.random() * 40 - 20)
                        };
                    }

                    // 确保行人在合理范围内
                    if (Math.abs(this.group.position.x) > 100 || Math.abs(this.group.position.z) > 100) {
                        this.direction = Math.atan2(-this.group.position.x, -this.group.position.z);
                    }
                }
            }
        }

        // 火车站类
        class TrainStation {
            constructor(x, z, rotation) {
                this.x = x;
                this.z = z;
                this.rotation = rotation;

                this.createTrainStation();
            }

            createTrainStation() {
                this.group = new THREE.Group();

                // 站台
                const platformGeometry = new THREE.BoxGeometry(40, 2, 10);
                const platformMaterial = new THREE.MeshStandardMaterial({ color: 0xaaaaaa });
                const platform = new THREE.Mesh(platformGeometry, platformMaterial);
                platform.position.set(0, 1, 0);
                platform.receiveShadow = true;
                this.group.add(platform);

                // 站台屋顶
                const roofGeometry = new THREE.BoxGeometry(42, 0.5, 15);
                const roofMaterial = new THREE.MeshStandardMaterial({
                    color: 0x888888,
                    roughness: 0.7,
                    metalness: 0.3
                });
                const roof = new THREE.Mesh(roofGeometry, roofMaterial);
                roof.position.set(0, 8, 0);
                roof.castShadow = true;
                this.group.add(roof);

                // 支撑柱
                const pillarGeometry = new THREE.CylinderGeometry(0.5, 0.5, 6, 8);
                const pillarMaterial = new THREE.MeshStandardMaterial({ color: 0x777777 });

                for (let i = -15; i <= 15; i += 10) {
                    const pillar = new THREE.Mesh(pillarGeometry, pillarMaterial);
                    pillar.position.set(i, 4, 0);
                    pillar.castShadow = true;
                    this.group.add(pillar);
                }

                // 站台标志
                const signGeometry = new THREE.BoxGeometry(10, 2, 0.5);
                const signMaterial = new THREE.MeshStandardMaterial({ color: 0xff0000 });
                const sign = new THREE.Mesh(signGeometry, signMaterial);
                sign.position.set(0, 5, -5);
                sign.castShadow = true;
                this.group.add(sign);

                // 站牌文字
                const textGeometry = new THREE.PlaneGeometry(8, 1);
                const textMaterial = new THREE.MeshStandardMaterial({
                    color: 0xffffff,
                    emissive: 0xffffff,
                    emissiveIntensity: 0.5
                });
                const text = new THREE.Mesh(textGeometry, textMaterial);
                text.position.set(0, 5, -5.1);
                text.rotation.x = Math.PI;
                this.group.add(text);

                this.group.position.set(this.x, 0, this.z);
                this.group.rotation.y = this.rotation;
                scene.add(this.group);
            }
        }

        // 火车类
        class Train {
            constructor(x, z, direction) {
                this.x = x;
                this.z = z;
                this.direction = direction;
                this.speed = 1.5;
                this.waitingTime = undefined;
                this.stations = [];
                this.currentStation = 0;

                this.createTrain();
            }

            createTrain() {
                this.group = new THREE.Group();

                // 火车头
                const engineGeometry = new THREE.BoxGeometry(6, 5, 20);
                const engineMaterial = new THREE.MeshStandardMaterial({ color: 0x0066cc });
                const engine = new THREE.Mesh(engineGeometry, engineMaterial);
                engine.position.set(0, 2.5, 0);
                engine.castShadow = true;
                this.group.add(engine);

                // 车窗
                const windowGeometry = new THREE.BoxGeometry(5, 2, 3);
                const windowMaterial = new THREE.MeshStandardMaterial({
                    color: 0xadd8e6,
                    transparent: true,
                    opacity: 0.7
                });

                for (let i = 0; i < 3; i++) {
                    const window = new THREE.Mesh(windowGeometry, windowMaterial);
                    window.position.set(0, 4, -7 + i * 7);
                    this.group.add(window);
                }

                // 车厢
                const carriageGeometry = new THREE.BoxGeometry(6, 4, 15);
                const carriageMaterial = new THREE.MeshStandardMaterial({ color: 0x0066cc });

                for (let i = 0; i < 3; i++) {
                    const carriage = new THREE.Mesh(carriageGeometry, carriageMaterial);
                    carriage.position.set(0, 2, 20 + i * 16);
                    carriage.castShadow = true;
                    this.group.add(carriage);

                    // 车厢窗户
                    for (let j = 0; j < 2; j++) {
                        const carriageWindow = new THREE.Mesh(windowGeometry, windowMaterial);
                        carriageWindow.position.set(0, 3.5, 20 + i * 16 - 5 + j * 10);
                        this.group.add(carriageWindow);
                    }
                }

                // 车轮
                const wheelGeometry = new THREE.CylinderGeometry(1, 1, 1.5, 16);
                const wheelMaterial = new THREE.MeshStandardMaterial({ color: 0x222222 });

                this.wheels = [];
                for (let i = -2; i <= 3; i++) {
                    for (let j = 0; j < 2; j++) {
                        const wheel = new THREE.Mesh(wheelGeometry, wheelMaterial);
                        wheel.rotation.z = Math.PI / 2;
                        wheel.position.set(j === 0 ? -3 : 3, 0.5, i * 10);
                        wheel.castShadow = true;
                        this.wheels.push(wheel);
                        this.group.add(wheel);
                    }
                }

                this.group.position.set(this.x, 0, this.z);
                this.group.rotation.y = this.direction;
            }

            update(deltaTime, city) {
                if (this.currentStation < this.stations.length) {
                    const target = this.stations[this.currentStation];
                    const dx = target.x - this.group.position.x;
                    const dz = target.z - this.group.position.z;
                    const distance = Math.sqrt(dx * dx + dz * dz);

                    if (distance < 10) {
                        // 到达站点,等待一会儿
                        if (this.waitingTime === undefined) {
                            this.waitingTime = 0;
                        } else {
                            this.waitingTime += deltaTime;

                            if (this.waitingTime > 5000) { // 等待5秒
                                this.waitingTime = undefined;
                                this.currentStation = (this.currentStation + 1) % this.stations.length;
                            }
                        }
                    } else {
                        // 计算方向并移动
                        const angle = Math.atan2(dx, dz);
                        this.group.rotation.y = angle;
                        this.direction = angle;

                        this.group.position.x += Math.sin(this.direction) * this.speed * (deltaTime / 16);
                        this.group.position.z += Math.cos(this.direction) * this.speed * (deltaTime / 16);
                    }
                }

                // 更新车轮旋转
                if (this.waitingTime === undefined) {
                    const rotationSpeed = this.speed * 0.2 * (deltaTime / 16);
                    this.wheels.forEach(wheel => {
                        wheel.rotation.x += rotationSpeed;
                    });
                }
            }
        }

        // 机场类
        class Airport {
            constructor(x, z, rotation) {
                this.x = x;
                this.z = z;
                this.rotation = rotation;

                this.createAirport();
            }

            createAirport() {
                this.group = new THREE.Group();

                // 跑道
                const runwayGeometry = new THREE.PlaneGeometry(100, 20);
                const runwayMaterial = new THREE.MeshStandardMaterial({
                    color: 0x666666,
                    roughness: 0.7,
                    metalness: 0.3
                });
                const runway = new THREE.Mesh(runwayGeometry, runwayMaterial);
                runway.rotation.x = -Math.PI / 2;
                runway.position.set(0, 0.1, 0);
                runway.receiveShadow = true;
                this.group.add(runway);

                // 跑道标记
                const markGeometry = new THREE.PlaneGeometry(5, 1);
                const markMaterial = new THREE.MeshStandardMaterial({ color: 0xffffff });

                for (let i = -45; i <= 45; i += 10) {
                    const mark = new THREE.Mesh(markGeometry, markMaterial);
                    mark.rotation.x = -Math.PI / 2;
                    mark.position.set(i, 0.11, 0);
                    this.group.add(mark);
                }

                // 航站楼
                const terminalGeometry = new THREE.BoxGeometry(30, 10, 50);
                const terminalMaterial = new THREE.MeshStandardMaterial({
                    color: 0xdddddd,
                    metalness: 0.5,
                    roughness: 0.2
                });
                const terminal = new THREE.Mesh(terminalGeometry, terminalMaterial);
                terminal.position.set(0, 5, -35);
                terminal.castShadow = true;
                terminal.receiveShadow = true;
                this.group.add(terminal);

                // 控制塔
                const towerBaseGeometry = new THREE.CylinderGeometry(3, 5, 10, 8);
                const towerBaseMaterial = new THREE.MeshStandardMaterial({ color: 0xaaaaaa });
                const towerBase = new THREE.Mesh(towerBaseGeometry, towerBaseMaterial);
                towerBase.position.set(15, 5, -60);
                towerBase.castShadow = true;
                this.group.add(towerBase);

                const towerTopGeometry = new THREE.BoxGeometry(8, 6, 8);
                const towerTopMaterial = new THREE.MeshStandardMaterial({
                    color: 0x8888ff,
                    transparent: true,
                    opacity: 0.7
                });
                const towerTop = new THREE.Mesh(towerTopGeometry, towerTopMaterial);
                towerTop.position.set(15, 13, -60);
                towerTop.castShadow = true;
                this.group.add(towerTop);

                // 停机坪
                const apronGeometry = new THREE.PlaneGeometry(60, 40);
                const apronMaterial = new THREE.MeshStandardMaterial({
                    color: 0x444444,
                    roughness: 0.8,
                    metalness: 0.1
                });
                const apron = new THREE.Mesh(apronGeometry, apronMaterial);
                apron.rotation.x = -Math.PI / 2;
                apron.position.set(0, 0.1, -60);
                apron.receiveShadow = true;
                this.group.add(apron);

                // 停机位标记
                for (let i = -20; i <= 20; i += 20) {
                    const spotMark = new THREE.Mesh(
                        new THREE.PlaneGeometry(15, 3),
                        new THREE.MeshStandardMaterial({ color: 0xffff00 })
                    );
                    spotMark.rotation.x = -Math.PI / 2;
                    spotMark.position.set(i, 0.11, -60);
                    this.group.add(spotMark);
                }

                this.group.position.set(this.x, 0, this.z);
                this.group.rotation.y = this.rotation;
                scene.add(this.group);
            }
        }

        // 飞机类
        class Airplane {
            constructor(x, y, z, rotation) {
                this.x = x;
                this.y = y;
                this.z = z;
                this.rotation = rotation;
                this.speed = 3;
                this.altitude = y;
                this.state = 'flying'; // 'flying', 'landing', 'taking-off', 'parked'
                this.targetAltitude = y;

                this.createAirplane();
            }

            createAirplane() {
                this.group = new THREE.Group();

                // 机身
                const bodyGeometry = new THREE.CylinderGeometry(1, 1, 20, 16);
                const bodyMaterial = new THREE.MeshStandardMaterial({ color: 0xffffff });
                const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
                body.rotation.z = Math.PI / 2;
                body.castShadow = true;
                this.group.add(body);

                // 机翼
                const wingGeometry = new THREE.BoxGeometry(20, 0.5, 5);
                const wingMaterial = new THREE.MeshStandardMaterial({ color: 0xffffff });
                const wing = new THREE.Mesh(wingGeometry, wingMaterial);
                wing.position.set(0, 0, 0);
                wing.castShadow = true;
                this.group.add(wing);

                // 尾翼
                const tailGeometry = new THREE.BoxGeometry(3, 0.5, 5);
                const tailMaterial = new THREE.MeshStandardMaterial({ color: 0xffffff });
                const tail = new THREE.Mesh(tailGeometry, tailMaterial);
                tail.position.set(-10, 0, 0);
                tail.castShadow = true;
                this.group.add(tail);

                // 垂直尾翼
                const vTailGeometry = new THREE.BoxGeometry(2, 5, 0.5);
                const vTailMaterial = new THREE.MeshStandardMaterial({ color: 0xff0000 });
                const vTail = new THREE.Mesh(vTailGeometry, vTailMaterial);
                vTail.position.set(-10, 2.5, 0);
                vTail.castShadow = true;
                this.group.add(vTail);

                // 引擎
                const engineGeometry = new THREE.CylinderGeometry(1.5, 1.5, 4, 16);
                const engineMaterial = new THREE.MeshStandardMaterial({ color: 0x333333 });
                const engine1 = new THREE.Mesh(engineGeometry, engineMaterial);
                engine1.position.set(5, 0, -3);
                engine1.rotation.z = Math.PI / 2;
                engine1.castShadow = true;
                this.engine1 = engine1;
                this.group.add(engine1);

                const engine2 = new THREE.Mesh(engineGeometry, engineMaterial);
                engine2.position.set(5, 0, 3);
                engine2.rotation.z = Math.PI / 2;
                engine2.castShadow = true;
                this.engine2 = engine2;
                this.group.add(engine2);

                this.group.position.set(this.x, this.y, this.z);
                this.group.rotation.y = this.rotation;
            }

            update(deltaTime, city) {
                const rotationSpeed = this.speed * 0.5 * (deltaTime / 16);
                this.engine1.rotation.x += rotationSpeed;
                this.engine2.rotation.x += rotationSpeed;

                switch (this.state) {
                    case 'flying':
                        // 飞行状态
                        this.group.position.y = this.altitude;
                        this.group.position.z += this.speed * (deltaTime / 16);

                        // 检查是否需要降落
                        if (this.group.position.z > -200 && this.group.position.z < -180) {
                            this.state = 'landing';
                            this.targetAltitude = 0;
                        }
                        break;

                    case 'landing':
                        // 降落状态
                        if (this.altitude > this.targetAltitude) {
                            this.altitude -= 0.1 * (deltaTime / 16);
                            this.group.position.y = this.altitude;
                        } else {
                            this.state = 'parked';
                        }
                        break;

                    case 'parked':
                        // 停放状态
                        if (Math.random() < 0.001 * (deltaTime / 16)) {
                            this.state = 'taking-off';
                            this.targetAltitude = 100;
                        }
                        break;

                    case 'taking-off':
                        // 起飞状态
                        if (this.altitude < this.targetAltitude) {
                            this.altitude += 0.1 * (deltaTime / 16);
                            this.group.position.y = this.altitude;
                        } else {
                            this.state = 'flying';
                            this.group.position.z = -300; // 重置位置
                        }
                        break;
                }
            }
        }

        // 公交站类
        class BusStop {
            constructor(x, z) {
                this.x = x;
                this.z = z;

                this.createBusStop();
            }

            createBusStop() {
                this.group = new THREE.Group();

                // 站牌柱
                const poleGeometry = new THREE.CylinderGeometry(0.2, 0.2, 3, 8);
                const poleMaterial = new THREE.MeshStandardMaterial({ color: 0x333333 });
                const pole = new THREE.Mesh(poleGeometry, poleMaterial);
                pole.position.set(0, 1.5, 0);
                pole.castShadow = true;
                this.group.add(pole);

                // 站牌
                const signGeometry = new THREE.BoxGeometry(2, 1.5, 0.1);
                const signMaterial = new THREE.MeshStandardMaterial({ color: 0x0066cc });
                const sign = new THREE.Mesh(signGeometry, signMaterial);
                sign.position.set(0, 3, 0);
                sign.castShadow = true;
                this.group.add(sign);

                // 站牌文字
                const textGeometry = new THREE.PlaneGeometry(1.8, 0.8);
                const textMaterial = new THREE.MeshStandardMaterial({
                    color: 0xffffff,
                    emissive: 0xffffff,
                    emissiveIntensity: 0.5
                });
                const text = new THREE.Mesh(textGeometry, textMaterial);
                text.position.set(0, 3, 0.06);
                this.group.add(text);

                this.group.position.set(this.x, 0, this.z);
                scene.add(this.group);
            }
        }

        // 紧急车辆类
        class EmergencyVehicle {
            constructor(type, x, z, direction) {
                this.type = type; // 'police' or 'ambulance'
                this.x = x;
                this.z = z;
                this.direction = direction;
                this.speed = 1.0;
                this.sirenOn = true;
                this.sirenTimer = 0;
                this.sirenLight = null;

                this.createVehicle();
            }

            createVehicle() {
                this.group = new THREE.Group();

                // 车身
                const bodyGeometry = new THREE.BoxGeometry(5, 2, 10);
                const bodyMaterial = new THREE.MeshStandardMaterial({
                    color: this.type === 'police' ? 0x0000ff : 0xff0000
                });
                const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
                body.position.set(0, 1, 0);
                body.castShadow = true;
                this.group.add(body);

                // 车窗
                const windowGeometry = new THREE.BoxGeometry(4.5, 1.5, 4);
                const windowMaterial = new THREE.MeshStandardMaterial({
                    color: 0xadd8e6,
                    transparent: true,
                    opacity: 0.7
                });
                const frontWindow = new THREE.Mesh(windowGeometry, windowMaterial);
                frontWindow.position.set(0, 2.5, 2.5);
                this.group.add(frontWindow);

                const backWindow = new THREE.Mesh(windowGeometry, windowMaterial);
                backWindow.position.set(0, 2.5, -2.5);
                this.group.add(backWindow);

                // 警灯/救护灯
                const lightGeometry = new THREE.BoxGeometry(2, 0.5, 1);
                this.lightMaterial = new THREE.MeshStandardMaterial({
                    color: 0xffffff,
                    emissive: 0xffffff,
                    emissiveIntensity: 1
                });
                this.sirenLight = new THREE.Mesh(lightGeometry, this.lightMaterial);
                this.sirenLight.position.set(0, 3, 0);
                this.group.add(this.sirenLight);

                // 车轮
                const wheelGeometry = new THREE.CylinderGeometry(0.8, 0.8, 1, 16);
                const wheelMaterial = new THREE.MeshStandardMaterial({ color: 0x222222 });

                this.wheel1 = new THREE.Mesh(wheelGeometry, wheelMaterial);
                this.wheel1.rotation.z = Math.PI / 2;
                this.wheel1.position.set(-2.5, 0.5, 3.5);
                this.wheel1.castShadow = true;
                this.group.add(this.wheel1);

                this.wheel2 = new THREE.Mesh(wheelGeometry, wheelMaterial);
                this.wheel2.rotation.z = Math.PI / 2;
                this.wheel2.position.set(2.5, 0.5, 3.5);
                this.wheel2.castShadow = true;
                this.group.add(this.wheel2);

                this.wheel3 = new THREE.Mesh(wheelGeometry, wheelMaterial);
                this.wheel3.rotation.z = Math.PI / 2;
                this.wheel3.position.set(-2.5, 0.5, -3.5);
                this.wheel3.castShadow = true;
                this.group.add(this.wheel3);

                this.wheel4 = new THREE.Mesh(wheelGeometry, wheelMaterial);
                this.wheel4.rotation.z = Math.PI / 2;
                this.wheel4.position.set(2.5, 0.5, -3.5);
                this.wheel4.castShadow = true;
                this.group.add(this.wheel4);

                this.group.position.set(this.x, 0, this.z);
                this.group.rotation.y = this.direction;
            }

            update(deltaTime, city) {
                // 更新警灯闪烁
                this.sirenTimer += deltaTime;
                if (this.sirenTimer > 200) { // 每200ms切换一次
                    this.sirenTimer = 0;
                    this.lightMaterial.emissiveIntensity = this.lightMaterial.emissiveIntensity > 0 ? 0 : 1;
                    this.lightMaterial.color.setHex(
                        this.lightMaterial.color.getHex() === 0xffffff ?
                        (this.type === 'police' ? 0x0000ff : 0xff0000) :
                        0xffffff
                    );
                }

                // 移动车辆
                this.group.position.x += Math.sin(this.direction) * this.speed * (deltaTime / 16);
                this.group.position.z += Math.cos(this.direction) * this.speed * (deltaTime / 16);

                // 检查是否到达边界或需要转弯
                if (Math.abs(this.group.position.x) > 240 || Math.abs(this.group.position.z) > 240) {
                    this.direction = (this.direction + Math.PI / 2) % (Math.PI * 2);
                    this.group.rotation.y = this.direction;
                }

                // 更新车轮旋转
                const rotationSpeed = this.speed * 0.5 * (deltaTime / 16);
                this.wheel1.rotation.x += rotationSpeed;
                this.wheel2.rotation.x += rotationSpeed;
                this.wheel3.rotation.x += rotationSpeed;
                this.wheel4.rotation.x += rotationSpeed;
            }
        }

        // 创建城市管理器
        const city = new CityManager();
        city.initialize();

        // 处理窗口大小变化
        window.addEventListener('resize', () => {
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
            renderer.setSize(window.innerWidth, window.innerHeight);
        });

        // 控制按钮事件
        document.getElementById('toggle-view').addEventListener('click', () => {
            viewMode = viewMode === 'overhead' ? 'first-person' : 'overhead';
            document.getElementById('view-mode').textContent = viewMode === 'overhead' ? '鸟瞰' : '第一人称';

            if (viewMode === 'overhead') {
                camera.position.set(0, 150, 200);
                camera.lookAt(0, 0, 0);
                controls.enabled = true;
            } else {
                // 随机选择一个行人或汽车作为第一人称视角
                let target;
                if (Math.random() > 0.5 && city.pedestrians.length > 0) {
                    target = city.pedestrians[Math.floor(Math.random() * city.pedestrians.length)];
                } else if (city.cars.length > 0) {
                    target = city.cars[Math.floor(Math.random() * city.cars.length)];
                } else {
                    target = city.pedestrians[0] || city.cars[0];
                }

                if (target) {
                    camera.position.copy(target.group.position);
                    camera.position.y += target.type === 'pedestrian' ? 2 : 1.5; // 眼睛高度
                    camera.rotation.y = target.direction || 0;
                    camera.rotation.x = 0;
                    controls.enabled = false;
                }
            }
        });

        document.getElementById('day-night').addEventListener('click', () => {
            city.isDay = !city.isDay;
            city.skyMaterial.color.setHex(city.isDay ? 0x87CEEB : 0x000033);
            city.updateLighting();
        });

        document.getElementById('add-car').addEventListener('click', () => {
            city.addRandomCar();
        });

        document.getElementById('add-bus').addEventListener('click', () => {
            const directions = [0, Math.PI/2, Math.PI, Math.PI*3/2];
            const direction = directions[Math.floor(Math.random() * 4)];
            let x, z;

            switch (direction) {
                case 0: // 东
                    x = -250;
                    z = Math.random() * 100 - 50;
                    break;
                case Math.PI / 2: // 北
                    x = Math.random() * 100 - 50;
                    z = 250;
                    break;
                case Math.PI: // 西
                    x = 250;
                    z = Math.random() * 100 - 50;
                    break;
                case Math.PI * 3 / 2: // 南
                    x = Math.random() * 100 - 50;
                    z = -250;
                    break;
            }

            const bus = new Bus(x, z, direction);
            bus.stops = [
                { x: -100, z: 30 },
                { x: -50, z: -30 },
                { x: 50, z: 30 },
                { x: 100, z: -30 }
            ].sort(() => Math.random() - 0.5); // 随机排序站点

            city.buses.push(bus);
            scene.add(bus.group);
        });

        document.getElementById('add-pedestrian').addEventListener('click', () => {
            city.addRandomPedestrian();
        });

        document.getElementById('toggle-traffic').addEventListener('click', () => {
            // 切换交通灯状态
            city.trafficLights.forEach(light => light.changeState());
        });

        document.getElementById('change-weather').addEventListener('click', () => {
            city.changeWeather();
        });

        document.getElementById('add-building').addEventListener('click', () => {
            city.addRandomBuilding();
        });

        document.getElementById('emergency').addEventListener('click', () => {
            city.emergencyMode = !city.emergencyMode;

            if (city.emergencyMode) {
                // 添加2-4辆紧急车辆
                const count = Math.floor(Math.random() * 3) + 2;
                for (let i = 0; i < count; i++) {
                    city.addEmergencyVehicle();
                }

                document.getElementById('emergency').style.backgroundColor = '#ff0000';
                document.getElementById('emergency').textContent = '紧急模式(开)';
            } else {
                // 移除所有紧急车辆
                city.emergencyVehicles.forEach(vehicle => {
                    scene.remove(vehicle.group);
                });
                city.emergencyVehicles = [];

                document.getElementById('emergency').style.backgroundColor = '#4CAF50';
                document.getElementById('emergency').textContent = '紧急模式(关)';
            }
        });

        document.getElementById('traffic-density').addEventListener('input', (e) => {
            city.trafficDensity = parseInt(e.target.value);
        });

        document.getElementById('simulation-speed').addEventListener('input', (e) => {
            city.simulationSpeed = parseInt(e.target.value);
        });

        // 动画循环
        function animate() {
            const startTime = performance.now();

            requestAnimationFrame(animate);

            // 计算deltaTime以确保不同帧率下的一致行为
            const currentTime = performance.now();
            const deltaTime = currentTime - stats.lastTime;
            stats.lastTime = currentTime;

            // 更新城市状态
            city.update(deltaTime);

            // 更新太阳位置
            const sunAngle = (city.time / (24 * 60)) * Math.PI * 2;
            city.sun.position.x = Math.cos(sunAngle) * 300;
            city.sun.position.y = Math.sin(sunAngle) * 300;
            city.sun.position.z = -100;

            directionalLight.position.copy(city.sun.position);

            // 更新UI信息
            city.updateUI();

            // 更新轨道控制器
            controls.update();

            // 渲染场景
            renderer.render(scene, camera);

            // 更新性能统计
            stats.frames++;
            stats.renderTime = performance.now() - startTime;

            if (currentTime - stats.lastFpsUpdate > 1000) {
                stats.fps = Math.round((stats.frames * 1000) / (currentTime - stats.lastFpsUpdate));
                stats.lastFpsUpdate = currentTime;
                stats.frames = 0;

                document.getElementById('fps').textContent = stats.fps;
                document.getElementById('render-time').textContent = stats.renderTime.toFixed(2);
                document.getElementById('scene-objects').textContent = scene.children.length;
            }
        }

        // 开始动画循环
        stats.lastTime = performance.now();
        stats.lastFpsUpdate = performance.now();
        animate();
    </script>
</body>
</html>

主文件index.html

HTML
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>水果忍者</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="game-container">
        <div class="game-header">
            <div class="score">分数: <span id="score">0</span></div>
            <div class="best-score">最高分: <span id="best-score">0</span></div>
            <div class="lives">
                <span class="life">❤️</span>
                <span class="life">❤️</span>
                <span class="life">❤️</span>
            </div>
        </div>

        <div class="game-area">
            <canvas id="game-canvas" width="800" height="500"></canvas>
            <div id="game-start" class="game-overlay">
                <h1>水果忍者</h1>
                <button id="start-button">开始游戏</button>
            </div>
            <div id="game-over" class="game-overlay hidden">
                <h1>游戏结束</h1>
                <div class="final-score">最终得分: <span id="final-score">0</span></div>
                <button id="restart-button">重新开始</button>
            </div>
        </div>
    </div>

    <script src="game.js"></script>
</body>
</html>

game.js

JavaScript
// 游戏常量
const FRUIT_TYPES = [
    { name: 'apple', color: '#ff0000', radius: 30, score: 10 },
    { name: 'orange', color: '#ffa500', radius: 35, score: 15 },
    { name: 'watermelon', color: '#00cc00', radius: 45, score: 20 },
    { name: 'banana', color: '#ffff00', radius: 25, score: 5 },
    { name: 'peach', color: '#ffc0cb', radius: 30, score: 10 },
    { name: 'bomb', color: '#333333', radius: 30, score: -30, isBomb: true }
];

const GRAVITY = 0.2; // 减小重力加速度,让水果下落更慢
const MAX_LIVES = 3;

// 游戏变量
let canvas, ctx;
let fruits = [];
let slices = [];
let score = 0;
let lives = MAX_LIVES;
let bestScore = localStorage.getItem('fruitNinjaBestScore') || 0;
let gameActive = false;
let lastFrameTime = 0;
let fruitGenerationInterval;
let mouseX = 0, mouseY = 0;
let lastMouseX = 0, lastMouseY = 0;
let mouseDown = false;

// 初始化游戏
function initGame() {
    canvas = document.getElementById('game-canvas');
    ctx = canvas.getContext('2d');

    // 更新最高分显示
    document.getElementById('best-score').textContent = bestScore;

    // 添加事件监听器
    canvas.addEventListener('mousedown', handleMouseDown);
    canvas.addEventListener('mouseup', handleMouseUp);
    canvas.addEventListener('mousemove', handleMouseMove);
    canvas.addEventListener('touchstart', handleTouchStart);
    canvas.addEventListener('touchend', handleTouchEnd);
    canvas.addEventListener('touchmove', handleTouchMove);

    // 设置开始和重新开始按钮
    document.getElementById('start-button').addEventListener('click', startGame);
    document.getElementById('restart-button').addEventListener('click', restartGame);

    // 开始动画循环
    requestAnimationFrame(gameLoop);
}

// 开始游戏
function startGame() {
    gameActive = true;
    score = 0;
    lives = MAX_LIVES;
    fruits = [];
    slices = [];

    document.getElementById('score').textContent = score;
    document.getElementById('game-start').classList.add('hidden');
    updateLives();

    // 定时生成水果,初始间隔更长,让玩家有更多反应时间
    updateFruitGenerationInterval();
}

// 重新开始游戏
function restartGame() {
    document.getElementById('game-over').classList.add('hidden');
    startGame();
}

// 结束游戏
function endGame() {
    gameActive = false;
    clearInterval(fruitGenerationInterval);

    // 更新最高分
    if (score > bestScore) {
        bestScore = score;
        localStorage.setItem('fruitNinjaBestScore', bestScore);
        document.getElementById('best-score').textContent = bestScore;
    }

    document.getElementById('final-score').textContent = score;
    document.getElementById('game-over').classList.remove('hidden');
}

// 更新生命值显示
function updateLives() {
    const livesContainer = document.querySelector('.lives');
    livesContainer.innerHTML = '';

    for (let i = 0; i < MAX_LIVES; i++) {
        const lifeSpan = document.createElement('span');
        lifeSpan.className = 'life';
        lifeSpan.textContent = i < lives ? '❤️' : '💔';
        livesContainer.appendChild(lifeSpan);
    }
}

// 根据分数更新水果生成间隔
function updateFruitGenerationInterval() {
    // 清除现有的定时器
    if (fruitGenerationInterval) {
        clearInterval(fruitGenerationInterval);
    }

    // 根据分数计算间隔时间,分数越高间隔越短,但有最小值
    // 初始间隔为2500毫秒,最小间隔为1000毫秒
    const minInterval = 1000;
    const maxInterval = 2500;
    const interval = Math.max(minInterval, maxInterval - Math.floor(score / 50) * 100);

    // 设置新的定时器
    fruitGenerationInterval = setInterval(generateFruits, interval);
}

// 生成水果
function generateFruits() {
    if (!gameActive) return;

    // 根据分数调整水果数量,分数越高可能同时出现的水果越多
    const maxFruitCount = Math.min(3, 1 + Math.floor(score / 100));
    const fruitCount = Math.floor(Math.random() * maxFruitCount) + 1;

    for (let i = 0; i < fruitCount; i++) {
        const fruitType = FRUIT_TYPES[Math.floor(Math.random() * FRUIT_TYPES.length)];
        const x = Math.random() * (canvas.width - 100) + 50;
        const speedX = ((Math.random() - 0.5) * 5 )* 0.5;
        const speedY = (-Math.random() * 12 - 15) * 0.5;

        fruits.push({
            x,
            y: canvas.height, // 调整水果的初始位置
            radius: fruitType.radius,
            color: fruitType.color,
            speedX,
            speedY,
            rotation: 0,
            rotationSpeed: (Math.random() - 0.5) * 0.2,
            name: fruitType.name,
            score: fruitType.score,
            isBomb: fruitType.isBomb || false,
            sliced: false
        });
    }
}

// 处理鼠标按下
function handleMouseDown(e) {
    mouseDown = true;
    const rect = canvas.getBoundingClientRect();
    mouseX = e.clientX - rect.left;
    mouseY = e.clientY - rect.top;
    lastMouseX = mouseX;
    lastMouseY = mouseY;
}

// 处理鼠标抬起
function handleMouseUp() {
    mouseDown = false;
}

// 处理鼠标移动
function handleMouseMove(e) {
    const rect = canvas.getBoundingClientRect();
    lastMouseX = mouseX;
    lastMouseY = mouseY;
    mouseX = e.clientX - rect.left;
    mouseY = e.clientY - rect.top;

    if (mouseDown && gameActive) {
        createSlice();
        checkSlice();
    }
}

// 处理触摸开始
function handleTouchStart(e) {
    e.preventDefault();
    mouseDown = true;
    const rect = canvas.getBoundingClientRect();
    const touch = e.touches[0];
    mouseX = touch.clientX - rect.left;
    mouseY = touch.clientY - rect.top;
    lastMouseX = mouseX;
    lastMouseY = mouseY;
}

// 处理触摸结束
function handleTouchEnd(e) {
    e.preventDefault();
    mouseDown = false;
}

// 处理触摸移动
function handleTouchMove(e) {
    e.preventDefault();
    const rect = canvas.getBoundingClientRect();
    const touch = e.touches[0];
    lastMouseX = mouseX;
    lastMouseY = mouseY;
    mouseX = touch.clientX - rect.left;
    mouseY = touch.clientY - rect.top;

    if (mouseDown && gameActive) {
        createSlice();
        checkSlice();
    }
}

// 创建切片效果
function createSlice() {
    slices.push({
        startX: lastMouseX,
        startY: lastMouseY,
        endX: mouseX,
        endY: mouseY,
        time: 10 // 切片显示的帧数
    });
}

// 检查切片是否击中水果
function checkSlice() {
    const dx = mouseX - lastMouseX;
    const dy = mouseY - lastMouseY;
    const distance = Math.sqrt(dx * dx + dy * dy);

    // 如果移动距离太小,不检测碰撞
    if (distance < 10) return;

    // 检查每个水果
    fruits.forEach(fruit => {
        if (fruit.sliced) return;

        // 线段与圆的碰撞检测
        if (lineCircleCollision(lastMouseX, lastMouseY, mouseX, mouseY, fruit.x, fruit.y, fruit.radius)) {
            fruit.sliced = true;

            // 如果是炸弹,减少生命值
            if (fruit.isBomb) {
                lives--;
                updateLives();

                if (lives <= 0) {
                    endGame();
                }
            } else {
                // 增加分数
                score += fruit.score;
                document.getElementById('score').textContent = score;

                // 根据新的分数更新水果生成间隔
                updateFruitGenerationInterval();

                // 切开水果后分成两半
                const angle = Math.atan2(dy, dx);

                // 左半部分
                fruits.push({
                    x: fruit.x,
                    y: fruit.y,
                    radius: fruit.radius * 0.7,
                    color: fruit.color,
                    speedX: fruit.speedX - 2 * Math.cos(angle + Math.PI/2),
                    speedY: fruit.speedY - 2 * Math.sin(angle + Math.PI/2),
                    rotation: fruit.rotation,
                    rotationSpeed: fruit.rotationSpeed * 1.5,
                    name: fruit.name + '-half',
                    sliced: true,
                    half: 'left',
                    lifespan: 60 // 半个水果的存在帧数
                });

                // 右半部分
                fruits.push({
                    x: fruit.x,
                    y: fruit.y,
                    radius: fruit.radius * 0.7,
                    color: fruit.color,
                    speedX: fruit.speedX + 2 * Math.cos(angle + Math.PI/2),
                    speedY: fruit.speedY + 2 * Math.sin(angle + Math.PI/2),
                    rotation: fruit.rotation,
                    rotationSpeed: fruit.rotationSpeed * 1.5,
                    name: fruit.name + '-half',
                    sliced: true,
                    half: 'right',
                    lifespan: 60 // 半个水果的存在帧数
                });
            }
        }
    });
}

// 线段与圆的碰撞检测
function lineCircleCollision(x1, y1, x2, y2, cx, cy, r) {
    // 计算线段长度的平方
    const lengthSquared = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);

    // 如果线段长度为0,直接检查点与圆的距离
    if (lengthSquared === 0) {
        return Math.sqrt((x1 - cx) * (x1 - cx) + (y1 - cy) * (y1 - cy)) <= r;
    }

    // 计算线段上最近点的参数t (0 <= t <= 1)
    const t = Math.max(0, Math.min(1, ((cx - x1) * (x2 - x1) + (cy - y1) * (y2 - y1)) / lengthSquared));

    // 计算线段上最近的点
    const nearestX = x1 + t * (x2 - x1);
    const nearestY = y1 + t * (y2 - y1);

    // 检查最近点与圆心的距离是否小于半径
    const distance = Math.sqrt((nearestX - cx) * (nearestX - cx) + (nearestY - cy) * (nearestY - cy));
    return distance <= r;
}

// 游戏主循环
function gameLoop(timestamp) {
    // 计算帧间隔时间
    const deltaTime = timestamp - lastFrameTime;
    lastFrameTime = timestamp;

    // 清空画布
    ctx.clearRect(0, 0, canvas.width, canvas.height);

    // 更新和绘制切片
    updateAndDrawSlices();

    // 更新和绘制水果
    updateAndDrawFruits(deltaTime);

    // 继续游戏循环
    requestAnimationFrame(gameLoop);
}

// 更新和绘制切片
function updateAndDrawSlices() {
    // 绘制切片
    ctx.lineWidth = 3;
    ctx.lineCap = 'round';

    for (let i = slices.length - 1; i >= 0; i--) {
        const slice = slices[i];

        // 创建渐变
        const gradient = ctx.createLinearGradient(slice.startX, slice.startY, slice.endX, slice.endY);
        gradient.addColorStop(0, 'rgba(255, 255, 255, 0)');
        gradient.addColorStop(0.5, 'rgba(255, 255, 255, 0.8)');
        gradient.addColorStop(1, 'rgba(255, 255, 255, 0)');

        ctx.strokeStyle = gradient;
        ctx.beginPath();
        ctx.moveTo(slice.startX, slice.startY);
        ctx.lineTo(slice.endX, slice.endY);
        ctx.stroke();

        // 减少切片的显示时间
        slice.time--;

        // 如果时间到了,移除切片
        if (slice.time <= 0) {
            slices.splice(i, 1);
        }
    }
}

// 更新和绘制水果
function updateAndDrawFruits(deltaTime) {
    let missedFruits = 0;

    for (let i = fruits.length - 1; i >= 0; i--) {
        const fruit = fruits[i];

        // 更新位置
        fruit.x += fruit.speedX;
        fruit.y += fruit.speedY;
        fruit.speedY += GRAVITY;
        fruit.rotation += fruit.rotationSpeed;

        // 如果是被切开的水果,减少寿命
        if (fruit.lifespan !== undefined) {
            fruit.lifespan--;
            if (fruit.lifespan <= 0) {
                fruits.splice(i, 1);
                continue;
            }
        }

        // 检查是否超出屏幕底部
        if (fruit.y - fruit.radius > canvas.height) {
            // 如果是完整的水果(未被切开)且不是炸弹,则算作错过
            if (!fruit.sliced && !fruit.isBomb && fruit.name.indexOf('-half') === -1) {
                missedFruits++;
            }

            fruits.splice(i, 1);
            continue;
        }

        // 绘制水果
        ctx.save();
        ctx.translate(fruit.x, fruit.y);
        ctx.rotate(fruit.rotation);

        if (fruit.name.indexOf('-half') !== -1) {
            // 绘制半个水果
            ctx.beginPath();
            if (fruit.half === 'left') {
                ctx.arc(0, 0, fruit.radius, Math.PI / 2, Math.PI * 3 / 2, false);
            } else {
                ctx.arc(0, 0, fruit.radius, -Math.PI / 2, Math.PI / 2, false);
            }
            ctx.lineTo(0, 0);
            ctx.closePath();
            ctx.fillStyle = fruit.color;
            ctx.fill();
        } else if (fruit.isBomb) {
            // 绘制炸弹
            ctx.beginPath();
            ctx.arc(0, 0, fruit.radius, 0, Math.PI * 2);
            ctx.fillStyle = fruit.color;
            ctx.fill();

            // 绘制炸弹引线
            ctx.beginPath();
            ctx.moveTo(0, -fruit.radius);
            ctx.lineTo(0, -fruit.radius - 10);
            ctx.strokeStyle = '#888';
            ctx.lineWidth = 3;
            ctx.stroke();

            // 绘制火花
            ctx.beginPath();
            ctx.arc(0, -fruit.radius - 12, 4, 0, Math.PI * 2);
            ctx.fillStyle = '#ff9900';
            ctx.fill();
        } else {
            // 绘制完整水果
            ctx.beginPath();
            ctx.arc(0, 0, fruit.radius, 0, Math.PI * 2);
            ctx.fillStyle = fruit.color;
            ctx.fill();

            // 如果是苹果,添加一个小叶子
            if (fruit.name === 'apple') {
                ctx.beginPath();
                ctx.moveTo(0, -fruit.radius);
                ctx.lineTo(5, -fruit.radius - 10);
                ctx.lineTo(0, -fruit.radius - 5);
                ctx.closePath();
                ctx.fillStyle = '#00cc00';
                ctx.fill();
            }
        }

        ctx.restore();
    }

    // 如果错过了水果,减少生命值
    if (gameActive && missedFruits > 0) {
        lives -= missedFruits;
        updateLives();

        if (lives <= 0) {
            endGame();
        }
    }
}

// 当页面加载完成后初始化游戏
window.addEventListener('load', initGame);

sytle.css

CSS
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background-color: #f0f0f0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
}

.game-container {
    width: 800px;
    background-color: #fff;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background-color: #333;
    color: white;
}

.score, .best-score {
    font-size: 20px;
    font-weight: bold;
}

.lives {
    display: flex;
    gap: 5px;
}

.life {
    font-size: 20px;
}

.game-area {
    position: relative;
}

#game-canvas {
    display: block;
    background-color: #e8f4f8;
    cursor: crosshair;
}

.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    z-index: 10;
}

.hidden {
    display: none;
}

h1 {
    font-size: 48px;
    margin-bottom: 30px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

button {
    padding: 12px 30px;
    font-size: 20px;
    background-color: #ff6b6b;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #ff5252;
}

.final-score {
    font-size: 24px;
    margin-bottom: 20px;
}

三个文件应处于1个同级目录中哦。直接执行index.html就可以玩了!(就是怎么好像没见过香蕉类)

◄ ⁣▀▀▀▀▀▀▀▀ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣To Be Continued ⁣   ⁣ ⁣▲ ⁣ ⁣ ⁣ ⁣  ⁣▏ ⁣ ⁣ ⁣ ⁣ ⁣ ⁣▼ ⁣ ⁣ ⁣ ⁣  ⁣ ⁣▼ ⁣ ⁣ ⁣ ⁣ ⁣   ⁣▏\color{black}\Huge{◄}\!\Large{▀▀▀▀▀▀▀▀}\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!^{\small\color{white}\textit{To Be Continued}\!\ \ \!\!\Large\color{black}▲\color{white}\!\!\!\!\:\!▏\large\!\!\!\!\!\!\color{black}▼\!\!\!\!\:\!\!▼\color{white}\!\!\!\!\!\;\!▏}