three实现3d孔明棋游戏代码Peg Solitaire

代码语言:html

所属分类:游戏

代码描述:three实现3d孔明棋游戏代码Peg Solitaire

代码标签: three 3d 孔明棋 游戏 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Three.js 3D 孔明棋</title>
    <style>
        body { margin: 0; overflow: hidden; font-family: 'Segoe UI', sans-serif; background-color: #222; }
        
        /* UI 覆盖层 */
        #ui-container {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            padding: 20px;
            pointer-events: none; /* 让鼠标事件穿透到 Canvas */
            color: white;
            text-align: center;
            text-shadow: 1px 1px 4px rgba(0,0,0,0.8);
        }

        h1 { margin: 0; font-weight: 300; letter-spacing: 2px; }
        p { color: #ccc; font-size: 14px; }

        #status {
            font-size: 24px;
            font-weight: bold;
            margin-top: 20px;
            min-height: 30px;
            color: #ffd700;
        }

        #controls {
            position: absolute;
            bottom: 30px;
            left: 50%;
            transform: translateX(-50%);
            pointer-events: auto;
        }

        button {
            background: linear-gradient(45deg, #ff6b6b, #ff8787);
            border: none;
            padding: 12px 30px;
            color: white;
            font-size: 16px;
            border-radius: 25px;
            cursor: pointer;
            box-shadow: 0 4px 15px rgba(0,0,0,0.3);
            transition: transform 0.1s;
        }

        button:active { transform: scale(0.95); }
    </style>
    
    <!-- 引入 Three.js 和 Tween.js (用于动画) -->
    <script type="importmap">
        {
            "imports": {
                "three": "https://unpkg.com/three@0.160.0/build/three.module.js",
                "three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/",
                "@tweenjs/tween.js": "https://unpkg.com/@tweenjs/tween.js@23.1.1/dist/tween.esm.js"
            }
        }
    </script>
</head>
<body>

    <div id="ui-container">
        <h1>3D 孔明棋 (Peg Solitaire)</h1>
        <p>规则:选中棋子,跳过相邻棋子落入空位,被跳过的棋子将被移除。<br>目标:最后只剩下一颗棋子(最好在中心)。</p>
        <div id="status"></div>
    </div>

    <div id="controls">
        <button id="resetBtn">重置游戏</button>
    </div>

    <script type="module">
        import * as THREE from 'three';
        import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
        import * as TWEEN from '@tweenjs/tween.js';

        // --- 全局变量 ---
        let scene, camera, renderer, controls;
        let raycaster, mouse;
        
        // 游戏配置
        const TILE_SIZE = 2.5; // 格子间距
        const PEG_RADIUS = 0.8;
        const BOARD_OFFSET = 3; // 7x7 网格的中心偏移量

        // 材质
        const materials = {
            board: new THREE.MeshStandardMater.........完整代码请登录后点击上方下载按钮下载查看

网友评论0