js实现完整的种菜开心农场游戏代码

代码语言:html

所属分类:游戏

代码描述:js实现完整的种菜开心农场游戏代码,带你了解种菜全过程,特色:

代码标签: js 完整 种菜 开心 农场 游戏 代码

下面为部分代码预览,完整代码请点击下载或在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>🥬 开心农场 - 种菜游戏</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', sans-serif;
            overflow: hidden;
            user-select: none;
        }

        #gameContainer {
            width: 100vw;
            height: 100vh;
            background: linear-gradient(180deg, #87CEEB 0%, #87CEEB 40%, #8B4513 40%, #654321 100%);
            position: relative;
            overflow: hidden;
        }

        /* 天空背景 */
        #sky {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 40%;
            background: linear-gradient(180deg, #87CEEB, #B0E0E6);
            transition: background 1s;
        }

        #sky.night {
            background: linear-gradient(180deg, #1a1a2e, #16213e);
        }

        #sky.rainy {
            background: linear-gradient(180deg, #4a5568, #718096);
        }

        /* 太阳/月亮 */
        #celestial {
            position: absolute;
            top: 30px;
            right: 80px;
            width: 70px;
            height: 70px;
            border-radius: 50%;
            background: radial-gradient(circle, #FFD700, #FFA500);
            box-shadow: 0 0 50px #FFD700;
            transition: all 1s;
        }

        #celestial.moon {
            background: radial-gradient(circle, #F5F5DC, #FFFACD);
            box-shadow: 0 0 30px #F5F5DC;
        }

        /* 云朵 */
        .cloud {
            position: absolute;
            background: white;
            border-radius: 50px;
            opacity: 0.9;
            animation: cloudFloat 30s linear infinite;
        }

        @keyframes cloudFloat {
            0% { transform: translateX(-200px); }
            100% { transform: translateX(calc(100vw + 200px)); }
        }

        /* 雨滴 */
        .raindrop {
            position: absolute;
            width: 3px;
            height: 20px;
            background: linear-gradient(180deg, transparent, rgba(174, 194, 224, 0.8));
            animation: rainFall 0.6s linear infinite;
        }

        @keyframes rainFall {
            0% { transform: translateY(-20px); opacity: 1; }
            100% { transform: translateY(40vh); opacity: 0; }
        }

        /* 状态栏 */
        #statusBar {
            position: absolute;
            top: 10px;
            left: 10px;
            background: rgba(255, 255, 255, 0.95);
            padding: 15px 25px;
            border-radius: 15px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.2);
            display: flex;
            gap: 25px;
            z-index: 100;
            border: 3px solid #8B4513;
        }

        .stat {
            display: flex;
            align-items: center;
            gap: 8px;
            font-size: 16px;
            font-weight: bold;
            color: #333;
        }

        .stat-icon {
            font-size: 22px;
        }

        /* 时间天气栏 */
        #weatherBar {
            position: absolute;
            top: 10px;
            right: 10px;
            background: rgba(255, 255, 255, 0.95);
            padding: 12px 20px;
            border-radius: 15px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.2);
            z-index: 100;
            border: 3px solid #8B4513;
            text-align: center;
        }

        /* 工具栏 */
        #toolbar {
            position: absolute;
            bottom: 15px;
            left: 50%;
            transform: translateX(-50%);
            background: linear-gradient(180deg, #DEB887, #D2691E);
            padding: 15px 25px;
            border-radius: 20px;
            display: flex;
            gap: 12px;
            box-shadow: 0 5px 25px rgba(0,0,0,0.4);
            border: 4px solid #8B4513;
            z-index: 100;
        }

        .tool {
            width: 65px;
            height: 65px;
            border-radius: 12px;
            border: 3px solid #654321;
            cursor: pointer;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            font-size: 28px;
            transition: all 0.2s;
            background: linear-gradient(145deg, #F5DEB3, #DEB887);
            position: relative;
        }

        .tool:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 15px rgba(0,0,0,0.3);
        }

        .tool.active {
            background: linear-gradient(145deg, #90EE90, #32CD32);
            transform: scale(1.1);
            box-shadow: 0 0 20px #32CD32;
        }

        .tool-name {
            font-size: 9px;
            color: #333;
            margin-top: 2px;
            font-weight: bold;
        }

        .tool-badge {
            position: absolute;
            top: -8px;
            right: -8px;
            background: #FF6347;
            color: white;
            padding: 2px 6px;
            border-radius: 10px;
            font-size: 10px;
            font-weight: bold;
        }

        /* 农田区域 */
        #farmland {
            position: absolute;
            top: 45%;
            left: 50%;
            transform: translate(-50%, -50%);
            display: grid;
            grid-template-columns: repeat(6, 1fr);
            gap: 10px;
            padding: 25px;
            background: rgba(139, 69, 19, 0.5);
            border-radius: 20px;
            border: 5px solid #654321;
        }

        /* 田地格子 */
        .plot {
            width: 100px;
            height: 120px;
            background: linear-gradient(180deg, #8B4513, #654321);
            border-radius: 10px;
            cursor: pointer;
            position: relative;
            transition: all 0.3s;
            border: 3px solid #5D3A1A;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: flex-end;
            padding-bottom: 10px;
        }

        .plot:hover {
            transform: scale(1.05);
            box-shadow: 0 5px 20px rgba(0,0,0,0.4);
        }

        .plot.watered {
            background: linear-gradient(180deg, #654321, #4a2c17);
        }

  .........完整代码请登录后点击上方下载按钮下载查看

网友评论0