three实现三维农场种植经营游戏代码

代码语言:html

所属分类:其他

代码由minimax-m3.1-flash ai生成,可能有错误,仅供参考:点击查看提示词

代码描述:农场种植经营游戏

代码标签: three 三维 农场 种植 经营 游戏 代码

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

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<meta name="description" content="北部郡土豆农场 —— 规划种植、盲盒收获、财务生存的 3D 农场经营游戏" />
<title>北部郡土豆农场</title>

<!-- ===========================================================================
     依赖管理:Three.js 与 OrbitControls 仅通过 <script src> 从 cdnjs / unpkg 引入。
     选用 r128 经典版(UMD + 全局 THREE),保证 file:// 双击打开即可运行,
     无需 importmap / ES Module(CORS 会阻止本地页面加载模块脚本)。
     =========================================================================== -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://unpkg.com/three@0.128.0/examples/js/controls/OrbitControls.js"></script>

<!-- CDN 兜底:若上方镜像因网络原因不可达,依次尝试备用镜像(仍限 cdnjs / unpkg) -->
<script>
window.__ensureDeps = function () {
  var THREE_MIRRORS = [
    'https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js',
    'https://unpkg.com/three@0.128.0/build/three.min.js'
  ];
  var OC_MIRRORS = [
    'https://unpkg.com/three@0.128.0/examples/js/controls/OrbitControls.js'
  ];

  function inject(url) {
    return new Promise(function (resolve, reject) {
      var s = document.createElement('script');
      s.src = url;
      s.async = false;
      s.onload = function () { resolve(url); };
      s.onerror = function () { reject(new Error('加载失败: ' + url)); };
      document.head.appendChild(s);
    });
  }

  function tryEach(list) {
    return list.reduce(function (chain, url) {
      return chain.catch(function () { return inject(url); });
    }, Promise.reject(new Error('全部镜像失败')));
  }

  var chain = window.THREE ? Promise.resolve() : tryEach(THREE_MIRRORS);
  return chain.then(function () {
    if (window.THREE && window.THREE.OrbitControls) { return true; }
    return tryEach(OC_MIRRORS).then(function () { return true; });
  });
};
</script>

<style>
/* ===========================================================================
 * 《北部郡土豆农场》样式表
 * 设计原则:
 *   1) 浅色模式(Light Mode)—— 明亮背景 + 高对比文字,禁止深色底;
 *   2) OCR 友好 —— 无衬线标准字体、无文字阴影、关键数值独立成 span 且字号够大;
 *   3) 所有图标均为内联 SVG(无外链图片、无字体图标)。
 * =========================================================================== */

:root {
  --bg: #eef7ff;              /* 页面浅蓝底 */
  --panel: #ffffff;           /* 面板纯白,保证文字对比度 */
  --panel-line: #c9d8e8;
  --ink: #111827;             /* 主文字:近黑 */
  --ink-soft: #44546a;        /* 次级文字 */
  --primary: #186a3b;         /* 主题绿 */
  --primary-ink: #ffffff;
  --amber: #b45309;
  --danger: #b42318;
  --shadow: 0 6px 20px rgba(15, 23, 42, 0.13);

  /* 与 3D 场景一一对应的地块状态色(便于图像识别状态判定) */
  --c-soil: #8B4513;          /* 空闲:棕色 */
  --c-seed: #9ACD32;          /* 已种植:浅绿 */
  --c-grow: #55A630;          /* 生长期:绿色 */
  --c-ripe: #228B22;          /* 成熟:深绿 */
  --c-gold: #F2C200;          /* 成熟点缀:黄 */
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

#scene-root { position: fixed; inset: 0; z-index: 1; }
#scene-root canvas { display: block; touch-action: none; }

/* HUD 容器不拦截鼠标,只有面板本体可交互(保证仍能拖动 3D 场景) */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }

.panel {
  position: absolute;
  pointer-events: auto;
  background: var(--panel);
  border: 2px solid var(--panel-line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

/* ---------- 顶部左:标题 + 核心数值 ---------- */
#panel-status { top: 14px; left: 14px; min-width: 306px; }

.game-title {
  margin: 0 0 2px;
  font-size: 21px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: 0.5px;
}
.game-title .sub {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.2px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 14px;
  margin-top: 10px;
}
.stat { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--ink-soft);
  white-space: nowrap;
}
/* 图标使用浅灰蓝描边:视觉清爽的同时避免 OCR 把小图标误识别成汉字 */
.stat-label svg { width: 15px; height: 15px; flex: none; color: #a6b7c8; }
.stat-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
}
.stat-value.money { color: var(--primary); }
.stat-unit { font-size: 13px; color: var(--ink-soft); font-weight: 700; margin-left: 2px; }
.stat-value.warn { color: var(--danger); }

/* ---------- 右侧纵向堆叠:农场经营 + 地块统计 ---------- */
#right-stack {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 272px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
#right-stack .panel { position: relative; top: auto; right: auto; width: 100%; }

/* ---------- 顶部右:操作按钮 ---------- */
#panel-actions { width: 100%; }
.panel-title {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 6px;
}
.panel-title svg { width: 15px; height: 15px; }

.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 7px 10px;
  border: 2px solid var(--panel-line);
  border-radius: 10px;
  background: #f5f9fd;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:hover:not(:disabled) { background: #e6f2ea; border-color: var(--primary); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover:not(:disabled) { background: #12562e; border-color: #12562e; }
.btn-full { grid-column: 1 / -1; }
.btn.on { background: #fff4d6; border-color: var(--amber); }

.hint {
  margin-top: 9px;
  padding: 7px 9px;
  border-radius: 9px;
  background: #f0f7ff;
  border: 1px dashed #b9cfe4;
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* ---------- 右侧中:统计 + 结算 ---------- */
#panel-report { width: 100%; }
.mini-grid { display: grid; gap: 4px; font-size: 13px; }
.mini-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mini-row .k { color: var(--ink-soft); display: inline-flex; align-items: center; gap: 5px; }
.mini-row .k svg { width: 14px; height: 14px; }
.mini-row .v { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: 0.5px; }
.divider { height: 1px; background: var(--panel-line); margin: 9px 0; }

/* ---------- 左下:图例 + 说明 ---------- */
#panel-legend { left: 14px; bottom: 14px; width: 306px; }
.legend-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 10px; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.legend-swatch {
  width: 18px; height: 18px; border-radius: 4px; flex: none;
  border: 1px solid rgba(0, 0, 0, 0.18);
}
.lg-soil { background: #8B4513; }
.lg-seed { background: #9ACD32; }
.lg-grow { background: #55A630; }
.lg-ripe { background: #228B22; }
.rules { margin: 9px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--ink-soft); }
.rules li { margin: 2px 0; }

/* ---------- 右下:操作日志 ---------- */
#panel-log { right: 14px; bottom: 14px; width: 268px; }
.log-list {
  max-height: 158px;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid #e3ecf5;
  border-radius: 9px;
  background: #fafcfe;
}
.log-item {
  padding: 5px 8px;
  font-size: 12.5px;
  color: var(--ink);
  border-bottom: 1px solid #eef3f8;
}
.log-item:last-child { border-bottom: none; }
.log-item.warn { color: var(--danger); }
.log-item.good { color: var(--primary); }
.log-item.gold { color: var(--amber); font-weight: 700; }
.last-line {
  margin-top: 7px;
  font-size: 12.5px;
  color: var(--ink-soft);
}
.last-line span { color: var(--ink); font-weight: 700; }

/* ---------- 悬浮地块提示 ---------- */
.tooltip {
  position: absolute;
  z-index: 20;
  display: none;
  min-width: 168px;
  padding: 8px 10px;
  background: #ffffff;
  border: 2px solid.........完整代码请登录后点击上方下载按钮下载查看

网友评论0