跳到正文

休闲·娱乐

人身长寿模拟器HTML

codingHe约 81 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年5月13日
篇幅
约 81 分钟

版本

  1. v1当前
C++
<!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>
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            max-width: 1000px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
            color: #333;
            line-height: 1.6;
        }
        h1 {
            color: #2c3e50;
            text-align: center;
            margin-bottom: 30px;
        }
        .game-container {
            background-color: white;
            border-radius: 10px;
            padding: 20px;
            box-shadow: 0 0 15px rgba(0,0,0,0.1);
        }
        .phase {
            display: none;
        }
        .phase.active {
            display: block;
        }
        .talents {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 10px;
            margin-bottom: 20px;
        }
        .talent {
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            cursor: pointer;
            transition: all 0.3s;
        }
        .talent:hover {
            background-color: #eaf7fd;
            border-color: #3498db;
        }
        .talent.selected {
            background-color: #d4edff;
            border-color: #2980b9;
        }
        .talent.disabled {
            opacity: 0.5;
            cursor: not-allowed;
            background-color: #f5f5f5;
        }
        .talent-cost {
            float: right;
            color: #e74c3c;
            font-weight: bold;
        }
        .stats {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
            gap: 10px;
            margin-bottom: 20px;
        }
        .stat {
            padding: 10px;
            background-color: #f8f9fa;
            border-radius: 5px;
            text-align: center;
        }
        .stat-value {
            font-size: 1.2em;
            font-weight: bold;
            color: #2c3e50;
        }
        .event-log {
            height: 300px;
            overflow-y: auto;
            border: 1px solid #ddd;
            padding: 15px;
            margin-bottom: 20px;
            background-color: #f9f9f9;
            border-radius: 5px;
        }
        .event {
            margin-bottom: 10px;
            padding-bottom: 10px;
            border-bottom: 1px dashed #eee;
        }
        .event:last-child {
            border-bottom: none;
        }
        .event-age {
            font-weight: bold;
            color: #3498db;
        }
        .button {
            padding: 10px 15px;
            background-color: #3498db;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s;
            margin-right: 10px;
            margin-bottom: 10px;
        }
        .button:hover {
            background-color: #2980b9;
        }
        .button:disabled {
            background-color: #95a5a6;
            cursor: not-allowed;
        }
        .achievements {
            margin-top: 20px;
        }
        .achievement {
            padding: 8px;
            margin: 5px 0;
            background-color: #e8f8f5;
            border-left: 4px solid #1abc9c;
            border-radius: 0 5px 5px 0;
        }
        .progress-container {
            width: 100%;
            background-color: #e0e0e0;
            border-radius: 5px;
            margin: 10px 0;
        }
        .progress-bar {
            height: 20px;
            border-radius: 5px;
            background-color: #2ecc71;
            width: 0%;
            transition: width 0.5s;
        }
        .life-summary {
            margin-top: 20px;
            padding: 15px;
            background-color: #f8f9fa;
            border-radius: 5px;
        }
        .highlight {
            color: #e74c3c;
            font-weight: bold;
        }
        .section-title {
            border-bottom: 2px solid #3498db;
            padding-bottom: 5px;
            margin: 20px 0 15px 0;
            color: #2c3e50;
        }
    </style>
</head>
<body>
    <div class="game-container">
        <h1>人生重开模拟器(长寿版)</h1>

        <!-- 天赋选择阶段 -->
        <div class="phase active" id="talentPhase">
            <h2 class="section-title">选择你的天赋</h2>
            <p>你有 <span id="talentPoints">20</span> 点天赋点可用 (最多可选10个天赋)</p>
            <div class="progress-container">
                <div class="progress-bar" id="talentProgress"></div>
            </div>
            <div class="talents" id="talentsContainer">
                <!-- 天赋将通过JS动态生成 -->
            </div>
            <button class="button" id="startLife">开始人生</button>
        </div>

        <!-- 人生模拟阶段 -->
        <div class="phase" id="lifePhase">
            <div class="stats">
                <div class="stat">
                    <div>年龄</div>
                    <div class="stat-value" id="age">0</div>
                </div>
                <div class="stat">
                    <div>健康</div>
                    <div class="stat-value" id="health">100</div>
                </div>
                <div class="stat">
                    <div>快乐</div>
                    <div class="stat-value" id="happiness">100</div>
                </div>
                <div class="stat">
                    <div>智力</div>
                    <div class="stat-value" id="intelligence">50</div>
                </div>
                <div class="stat">
                    <div>外貌</div>
                    <div class="stat-value" id="looks">50</div>
                </div>
                <div class="stat">
                    <div>财富</div>
                    <div class="stat-value" id="wealth">0</div>
                </div>
                <div class="stat">
                    <div>声望</div>
                    <div class="stat-value" id="fame">0</div>
                </div>
            </div>

            <div class="event-log" id="eventLog">
                <div class="event">你出生了!开始了新的人生旅程...</div>
            </div>

            <button class="button" id="nextYear">进入下一年</button>
            <button class="button" id="fastForward">快进5年</button>
            <button class="button" id="restart">重新开始</button>

            <div class="achievements">
                <h3 class="section-title">人生成就</h3>
                <div id="achievementsList">
                    <!-- 成就会在这里显示 -->
                </div>
            </div>

            <div class="life-summary" id="lifeSummary" style="display: none;">
                <h3 class="section-title">人生总结</h3>
                <div id="summaryContent"></div>
            </div>
        </div>
    </div>

    <script>
        // 游戏状态
        const state = {
            phase: "talent", // talent, life, end
            talents: [],
            selectedTalents: [],
            talentPoints: 20,
            maxTalents: 10,

            // 人生属性
            age: 0,
            maxAge: 0,
            health: 100,
            happiness: 100,
            intelligence: 50,
            looks: 50,
            wealth: 0,
            fame: 0,

            // 人生状态
            isAlive: true,
            isMarried: false,
            spouse: null,
            children: 0,
            career: null,
            careerLevel: 0,
            education: "无",
            house: null,
            car: null,

            // 记录
            events: ["你出生了!开始了新的人生旅程..."],
            achievements: [],
            annualEvents: []
        };

        // 天赋数据
        const talentData = [
            { id: 1, name: "天才儿童", cost: 5, description: "智力+20,从小表现出非凡才能" },
            { id: 2, name: "运动健将", cost: 3, description: "健康+15,运动能力出众" },
            { id: 3, name: "天生丽质", cost: 4, description: "外貌+20,更容易获得他人好感" },
            { id: 4, name: "富二代", cost: 6, description: "初始财富+1,000,000" },
            { id: 5, name: "艺术天赋", cost: 3, description: "艺术相关能力提升" },
            { id: 6, name: "音乐天才", cost: 4, description: "音乐才能出众" },
            { id: 7, name: "幸运星", cost: 5, description: "幸运值提升,好事更容易发生" },
            { id: 8, name: "社交达人", cost: 3, description: "社交能力提升" },
            { id: 9, name: "早熟", cost: 2, description: "心智成熟早" },
            { id: 10, name: "长寿基因", cost: 4, description: "健康+15,寿命显著延长" },  // 修改:从+10提高到+15
            { id: 11, name: "学霸体质", cost: 3, description: "学习效率提升" },
            { id: 12, name: "企业家精神", cost: 4, description: "商业头脑出众" },
            { id: 13, name: "技术宅", cost: 2, description: "技术相关能力提升" },
            { id: 14, name: "语言天才", cost: 3, description: "语言学习能力提升" },
            { id: 15, name: "心灵手巧", cost: 2, description: "手工能力提升" },
            { id: 16, name: "超强记忆力", cost: 4, description: "记忆力出众" },
            { id: 17, name: "抗压能力", cost: 3, description: "压力影响减小" },
            { id: 18, name: "美食家", cost: 1, description: "烹饪能力提升" },
            { id: 19, name: "探险家", cost: 2, description: "探索能力提升" },
            { id: 20, name: "领袖气质", cost: 4, description: "领导能力提升" },
            { id: 21, name: "写作天赋", cost: 3, description: "写作能力提升" },
            { id: 22, name: "数学天才", cost: 4, description: "数学能力提升" },
            { id: 23, name: "科学头脑", cost: 3, description: "科学研究能力提升" },
            { id: 24, name: "幽默大师", cost: 2, description: "幽默感提升" },
            { id: 25, name: "环保主义者", cost: 1, description: "环保意识强烈" },
            { id: 26, name: "动物亲和", cost: 2, description: "与动物相处能力提升" },
            { id: 27, name: "医疗知识", cost: 3, description: "医疗相关能力提升" },
            { id: 28, name: "法律专家", cost: 3, description: "法律知识丰富" },
            { id: 29, name: "理财高手", cost: 4, description: "财务管理能力提升" },
            { id: 30, name: "电竞天才", cost: 3, description: "电子游戏能力提升" },
            { id: 31, name: "武术天赋", cost: 4, description: "武术格斗能力提升" },
            { id: 32, name: "超感知觉", cost: 5, description: "直觉敏锐" },
            { id: 33, name: "多重人格", cost: -3, description: "性格多变,偶尔会有意外收获" },
            { id: 34, name: "拖延症", cost: -2, description: "做事效率降低" },
            { id: 35, name: "社交恐惧", cost: -3, description: "社交能力降低" },
            { id: 36, name: "体弱多病", cost: -4, description: "健康-15" },
            { id: 37, name: "霉运连连", cost: -3, description: "倒霉事更容易发生" },
            { id: 38, name: "外貌平平", cost: -2, description: "外貌-10" },
            { id: 39, name: "学习障碍", cost: -4, description: "智力-10,学习效率降低" }
        ];

        // 职业数据
        const careerData = [
            { name: "无业", levels: ["无业"], salary: [0] },
            { name: "学生", levels: ["小学生", "初中生", "高中生", "大学生", "研究生"], salary: [0, 0, 0, 0, 0] },
            { name: "程序员", levels: ["初级程序员", "中级程序员", "高级程序员", "技术主管", "CTO"],
              salary: [60000, 120000, 240000, 500000, 1200000] },
            { name: "医生", levels: ["实习医生", "住院医师", "主治医师", "副主任医师", "主任医师"],
              salary: [50000, 100000, 250000, 500000, 1000000] },
            { name: "教师", levels: ["代课老师", "正式教师", "高级教师", "教研组长", "校长"],
              salary: [40000, 80000, 150000, 250000, 500000] },
            { name: "艺术家", levels: ["业余艺术家", "职业艺术家", "知名艺术家", "艺术大师", "传奇艺术家"],
              salary: [30000, 80000, 200000, 800000, 5000000] },
            { name: "运动员", levels: ["业余选手", "职业选手", "国家队选手", "世界级选手", "传奇运动员"],
              salary: [20000, 100000, 500000, 2000000, 10000000] },
            { name: "企业家", levels: ["小商贩", "小企业主", "中型企业家", "大型企业家", "商业大亨"],
              salary: [50000, 200000, 1000000, 5000000, 50000000] },
            { name: "公务员", levels: ["科员", "副科级", "正科级", "处级", "厅级"],
              salary: [60000, 100000, 200000, 500000, 1200000] },
            { name: "网红", levels: ["小主播", "中型网红", "大V", "顶级网红", "现象级网红"],
              salary: [30000, 150000, 500000, 2000000, 10000000] }
        ];

        // 事件数据
        const eventData = {
            // 童年事件 (0-12岁)
            childhood: [
                { minAge: 0, maxAge: 3, text: "你在{age}岁时学会了走路和说话", effects: { intelligence: 1 } },
                { minAge: 3, maxAge: 6, text: "{age}岁时,你上了幼儿园", effects: { intelligence: 2 } },
                { minAge: 4, maxAge: 8, text: "{age}岁时,你在幼儿园的表演中表现出色", effects: { happiness: 5, fame: 1 } },
                { minAge: 6, maxAge: 12, text: "{age}岁时,你上了小学", effects: { intelligence: 3 } },
                { minAge: 6, maxAge: 12, text: "{age}岁时,你在学校运动会上获得了奖牌", effects: { health: 3, happiness: 5, fame: 2 } },
                { minAge: 6, maxAge: 12, text: "{age}岁时,你参加了学校的文艺表演", effects: { happiness: 3, fame: 1 } },
                { minAge: 6, maxAge: 12, text: "{age}岁时,你因为成绩优秀获得了表扬", effects: { intelligence: 2, happiness: 3 } },
                { minAge: 6, maxAge: 12, text: "{age}岁时,你和小伙伴们玩得很开心", effects: { happiness: 5 } },
                { minAge: 6, maxAge: 12, text: "{age}岁时,你生了一场病,休息了好几天", effects: { health: -5 } },
                { minAge: 6, maxAge: 12, text: "{age}岁时,你参加了一次夏令营,学到了很多新知识", effects: { intelligence: 2, happiness: 3 } }
            ],

            // 青少年事件 (13-19岁)
            teenage: [
                { minAge: 12, maxAge: 15, text: "{age}岁时,你上了初中", effects: { intelligence: 3 } },
                { minAge: 12, maxAge: 18, text: "{age}岁时,你参加了学校的社团活动", effects: { happiness: 3 } },
                { minAge: 12, maxAge: 18, text: "{age}岁时,你在考试中取得了好成绩", effects: { intelligence: 2, happiness: 3 } },
                { minAge: 12, maxAge: 18, text: "{age}岁时,你第一次有了暗恋对象", effects: { happiness: 5 } },
                { minAge: 15, maxAge: 18, text: "{age}岁时,你上了高中", effects: { intelligence: 3 } },
                { minAge: 15, maxAge: 18, text: "{age}岁时,你参加了高考", effects: { intelligence: 5, happiness: -5 } },
                { minAge: 16, maxAge: 19, text: "{age}岁时,你获得了奖学金", effects: { wealth: 5000, happiness: 5, fame: 2 } },
                { minAge: 16, maxAge: 19, text: "{age}岁时,你参加了学科竞赛并获奖", effects: { intelligence: 3, fame: 3 } },
                { minAge: 16, maxAge: 19, text: "{age}岁时,你和朋友一起旅行", effects: { happiness: 5 } },
                { minAge: 16, maxAge: 19, text: "{age}岁时,你第一次打工赚到了钱", effects: { wealth: 2000, happiness: 3 } }
            ],

            // 青年事件 (20-39岁)
            youngAdult: [
                { minAge: 18, maxAge: 22, text: "{age}岁时,你上了大学", effects: { intelligence: 5 } },
                { minAge: 18, maxAge: 25, text: "{age}岁时,你开始了第一份正式工作", effects: { wealth: 10000 } },
                { minAge: 20, maxAge: 30, text: "{age}岁时,你升职了", effects: { wealth: 20000, happiness: 5 } },
                { minAge: 20, maxAge: 35, text: "{age}岁时,你投资了一个项目,赚了一笔", effects: { wealth: 50000 } },
                { minAge: 20, maxAge: 35, text: "{age}岁时,你买了一辆新车", effects: { wealth: -30000, happiness: 5 } },
                { minAge: 20, maxAge: 35, text: "{age}岁时,你买了一套房子", effects: { wealth: -200000, happiness: 10 } },
                { minAge: 20, maxAge: 35, text: "{age}岁时,你遇到了心仪的对象", effects: { happiness: 10 } },
                { minAge: 20, maxAge: 35, text: "{age}岁时,你结婚了", effects: { happiness: 15, isMarried: true } },
                { minAge: 20, maxAge: 40, text: "{age}岁时,你的孩子出生了", effects: { happiness: 10, children: 1, wealth: -5000 } },
                { minAge: 20, maxAge: 40, text: "{age}岁时,你创业了", effects: { wealth: -100000 } },
                { minAge: 20, maxAge: 40, text: "{age}岁时,你的公司获得了投资", effects: { wealth: 500000 } },
                { minAge: 20, maxAge: 40, text: "{age}岁时,你出版了一本书", effects: { fame: 10, wealth: 20000 } },
                { minAge: 20, maxAge: 40, text: "{age}岁时,你参加了一个电视节目", effects: { fame: 15 } },
                { minAge: 20, maxAge: 40, text: "{age}岁时,你获得了行业大奖", effects: { fame: 20, wealth: 50000 } },
                { minAge: 20, maxAge: 40, text: "{age}岁时,你离婚了", effects: { happiness: -20, isMarried: false, wealth: -100000 } },
                { minAge: 20, maxAge: 40, text: "{age}岁时,你经历了一次严重的健康问题", effects: { health: -20 } },
                { minAge: 20, maxAge: 40, text: "{age}岁时,你中了彩票", effects: { wealth: 1000000 } },
                { minAge: 20, maxAge: 40, text: "{age}岁时,你进行了一次环球旅行", effects: { happiness: 15, wealth: -50000 } }
            ],

            // 中年事件 (40-59岁)
            middleAge: [
                { minAge: 40, maxAge: 60, text: "{age}岁时,你的事业达到了巅峰", effects: { wealth: 100000, fame: 10 } },
                { minAge: 40, maxAge: 60, text: "{age}岁时,你开始注重健康养生", effects: { health: 10 } },
                { minAge: 40, maxAge: 60, text: "{age}岁时,你的孩子上大学了", effects: { wealth: -50000, happiness: 5 } },
                { minAge: 40, maxAge: 60, text: "{age}岁时,你写了一本自传", effects: { fame: 15, wealth: 30000 } },
                { minAge: 40, maxAge: 60, text: "{age}岁时,你开始了一项新爱好", effects: { happiness: 10 } },
                { minAge: 40, maxAge: 60, text: "{age}岁时,你参加了一次同学聚会", effects: { happiness: 5 } },
                { minAge: 40, maxAge: 60, text: "{age}岁时,你投资失败损失了一笔钱", effects: { wealth: -100000 } },
                { minAge: 40, maxAge: 60, text: "{age}岁时,你购买了一栋度假别墅", effects: { wealth: -500000, happiness: 10 } },
                { minAge: 40, maxAge: 60, text: "{age}岁时,你获得了终身成就奖", effects: { fame: 20, happiness: 15 } },
                { minAge: 40, maxAge: 60, text: "{age}岁时,你开始考虑退休计划", effects: { } },
                { minAge: 40, maxAge: 60, text: "{age}岁时,你经历了一次中年危机", effects: { happiness: -10 } },
                { minAge: 40, maxAge: 60, text: "{age}岁时,你开始了一项慈善事业", effects: { wealth: -100000, fame: 15, happiness: 10 } }
            ],

            // 老年事件 (60-150岁) - 修改:扩展了老年阶段
            oldAge: [
                { minAge: 60, maxAge: 150, text: "{age}岁时,你退休了", effects: { happiness: 5 } },
                { minAge: 60, maxAge: 150, text: "{age}岁时,你的孙子出生了", effects: { happiness: 10 } },
                { minAge: 60, maxAge: 150, text: "{age}岁时,你开始写回忆录", effects: { happiness: 5 } },
                { minAge: 60, maxAge: 150, text: "{age}岁时,你和老伴去旅行", effects: { happiness: 10, wealth: -20000 } },
                { minAge: 60, maxAge: 150, text: "{age}岁时,你参加了一次家族聚会", effects: { happiness: 8 } },
                { minAge: 60, maxAge: 150, text: "{age}岁时,你获得了一枚荣誉勋章", effects: { fame: 10, happiness: 5 } },
                { minAge: 60, maxAge: 150, text: "{age}岁时,你生了一场大病", effects: { health: -15 } },  // 修改:从-20调整为-15
                { minAge: 60, maxAge: 150, text: "{age}岁时,你开始学习一项新技能", effects: { intelligence: 2, happiness: 5 } },
                { minAge: 60, maxAge: 150, text: "{age}岁时,你搬到了养老社区", effects: { wealth: -100000, happiness: 5 } },
                { minAge: 60, maxAge: 150, text: "{age}岁时,你回顾一生感到满足", effects: { happiness: 15 } },
                { minAge: 80, maxAge: 150, text: "{age}岁时,你被邀请分享长寿秘诀", effects: { fame: 5, happiness: 5 } },
                { minAge: 90, maxAge: 150, text: "{age}岁时,你成为当地最年长的居民", effects: { fame: 10, happiness: 10 } },
                { minAge: 100, maxAge: 150, text: "{age}岁时,你庆祝了自己的百岁生日,成为当地的名人", effects: { fame: 20, happiness: 15 } },
                { minAge: 100, maxAge: 150, text: "{age}岁时,电视台采访了你这位百岁老人", effects: { fame: 15 } },
                { minAge: 110, maxAge: 150, text: "{age}岁时,你被认证为超级百岁老人", effects: { fame: 30, happiness: 20 } },
                { minAge: 120, maxAge: 150, text: "{age}岁时,科学家研究你的长寿基因", effects: { fame: 40 } }
            ],

            // 死亡事件 - 修改:提高了年龄阈值
            death: [
                { text: "你在{age}岁时因年老去世", minAge: 90, healthThreshold: 0 },  // 修改:从70提高到90
                { text: "你在{age}岁时因疾病去世", minAge: 0, healthThreshold: 20 },
                { text: "你在{age}岁时因意外事故去世", minAge: 0, healthThreshold: 30, chance: 0.1 },
                { text: "你在{age}岁时安详地离开了人世", minAge: 100, healthThreshold: 40 },  // 修改:从80提高到100
                { text: "你在{age}岁时无疾而终,创造了新的长寿记录", minAge: 130, healthThreshold: 50 }  // 新增:超高寿死亡事件
            ]
        };

        // 成就数据
        const achievementData = [
            { id: 1, name: "学业有成", condition: (s) => s.education === "研究生" },
            { id: 2, name: "百万富翁", condition: (s) => s.wealth >= 1000000 },
            { id: 3, name: "亿万富翁", condition: (s) => s.wealth >= 100000000 },
            { id: 4, name: "事业巅峰", condition: (s) => s.careerLevel >= 4 },
            { id: 5, name: "家庭美满", condition: (s) => s.isMarried && s.children >= 2 },
            { id: 6, name: "健康长寿", condition: (s) => s.age >= 90 && s.health >= 60 },  // 修改:从80提高到90
            { id: 7, name: "名声显赫", condition: (s) => s.fame >= 50 },
            { id: 8, name: "环球旅行家", condition: (s) => s.events.filter(e => e.includes("环球旅行")).length >= 3 },
            { id: 9, name: "多才多艺", condition: (s) => s.intelligence >= 80 && s.looks >= 70 && s.health >= 70 },
            { id: 10, name: "人生赢家", condition: (s) => s.wealth >= 5000000 && s.fame >= 30 && s.isMarried && s.children >= 1 && s.health >= 60 },
            { id: 11, name: "百岁老人", condition: (s) => s.age >= 100 },  // 新增:百岁成就
            { id: 12, name: "超级人瑞", condition: (s) => s.age >= 110 }   // 新增:超高寿成就
        ];

        // DOM元素
        const elements = {
            talentPhase: document.getElementById('talentPhase'),
            lifePhase: document.getElementById('lifePhase'),
            talentsContainer: document.getElementById('talentsContainer'),
            talentPoints: document.getElementById('talentPoints'),
            talentProgress: document.getElementById('talentProgress'),
            startLife: document.getElementById('startLife'),

            age: document.getElementById('age'),
            health: document.getElementById('health'),
            happiness: document.getElementById('happiness'),
            intelligence: document.getElementById('intelligence'),
            looks: document.getElementById('looks'),
            wealth: document.getElementById('wealth'),
            fame: document.getElementById('fame'),
            eventLog: document.getElementById('eventLog'),
            achievementsList: document.getElementById('achievementsList'),
            nextYear: document.getElementById('nextYear'),
            fastForward: document.getElementById('fastForward'),
            restart: document.getElementById('restart'),
            lifeSummary: document.getElementById('lifeSummary'),
            summaryContent: document.getElementById('summaryContent')
        };

        // 初始化天赋选择
        function initTalents() {
            elements.talentsContainer.innerHTML = '';
            talentData.forEach(talent => {
                const talentEl = document.createElement('div');
                talentEl.className = 'talent';
                talentEl.innerHTML = `
                    <h3>${talent.name} <span class="talent-cost">${talent.cost > 0 ? '+' : ''}${talent.cost}</span></h3>
                    <p>${talent.description}</p>
                `;
                talentEl.dataset.id = talent.id;
                talentEl.dataset.cost = talent.cost;
                talentEl.addEventListener('click', () => toggleTalent(talent.id, talent.cost));
                elements.talentsContainer.appendChild(talentEl);
            });
        }

        // 切换天赋选择
        function toggleTalent(id, cost) {
            const talentEl = document.querySelector(`.talent[data-id="${id}"]`);

            // 检查是否已选中
            const index = state.selectedTalents.indexOf(id);
            if (index === -1) {
                // 尝试选中
                if (state.selectedTalents.length >= state.maxTalents) {
                    alert(`最多只能选择${state.maxTalents}个天赋`);
                    return;
                }
                if (state.talentPoints - cost < 0) {
                    alert("天赋点不足");
                    return;
                }

                state.selectedTalents.push(id);
                state.talentPoints -= cost;
                talentEl.classList.add('selected');
            } else {
                // 取消选中
                state.selectedTalents.splice(index, 1);
                state.talentPoints += cost;
                talentEl.classList.remove('selected');
            }

            updateTalentUI();
        }

        // 更新天赋选择UI
        function updateTalentUI() {
            elements.talentPoints.textContent = state.talentPoints;
            const progress = (state.maxTalents - (state.maxTalents - state.selectedTalents.length)) / state.maxTalents * 100;
            elements.talentProgress.style.width = `${progress}%`;

            // 禁用无法选择的天赋
            document.querySelectorAll('.talent').forEach(el => {
                const cost = parseInt(el.dataset.cost);
                if (state.talentPoints < cost && !el.classList.contains('selected')) {
                    el.classList.add('disabled');
                } else {
                    el.classList.remove('disabled');
                }
            });
        }

        // 开始人生
        function startLife() {
            // 应用天赋效果
            state.selectedTalents.forEach(id => {
                const talent = talentData.find(t => t.id === id);
                if (!talent) return;

                switch(talent.name) {
                    case "天才儿童":
                        state.intelligence += 20;
                        break;
                    case "运动健将":
                        state.health += 15;
                        break;
                    case "天生丽质":
                        state.looks += 20;
                        break;
                    case "富二代":
                        state.wealth += 1000000;
                        break;
                    case "长寿基因":
                        state.health += 15;  // 修改:从+10提高到+15
                        break;
                    case "外貌平平":
                        state.looks -= 10;
                        break;
                    case "体弱多病":
                        state.health -= 15;
                        break;
                    case "学习障碍":
                        state.intelligence -= 10;
                        break;
                }
            });

            // 切换到人生阶段
            state.phase = "life";
            elements.talentPhase.classList.remove('active');
            elements.lifePhase.classList.add('active');

            // 初始化人生状态
            state.career = careerData[0];
            state.careerLevel = 0;

            updateLifeUI();
        }

        // 进入下一年
        function nextYear() {
            if (!state.isAlive) return;

            state.age++;

            // 年龄相关变化
            if (state.age === 6) {
                // 上小学
                state.career = careerData[1];
                state.careerLevel = 0;
                addEvent("你上了小学,成为一名小学生");
            } else if (state.age === 12) {
                // 上初中
                state.careerLevel = 1;
                addEvent("你小学毕业,升入初中");
            } else if (state.age === 15) {
                // 上高中
                state.careerLevel = 2;
                addEvent("你初中毕业,升入高中");
            } else if (state.age === 18) {
                // 上大学或工作
                if (Math.random() > 0.3 || state.intelligence < 50) {
                    state.careerLevel = 3;
                    addEvent("你高中毕业,考入大学");
                } else {
                    state.career = getRandomCareer();
                    state.careerLevel = 0;
                    addEvent(`你高中毕业,开始工作成为一名${state.career.levels[0]}`);
                }
            } else if (state.age === 22 && state.career.name === "学生") {
                // 大学毕业
                if (Math.random() > 0.7 && state.intelligence >= 60) {
                    state.careerLevel = 4;
                    addEvent("你大学毕业,继续攻读研究生");
                } else {
                    state.career = getRandomCareer();
                    state.careerLevel = 0;
                    addEvent(`你大学毕业,开始工作成为一名${state.career.levels[0]}`);
                }
            } else if (state.age === 25 && state.career.name === "学生" && state.careerLevel === 4) {
                // 研究生毕业
                state.career = getRandomCareer();
                state.careerLevel = 1; // 研究生起点更高
                addEvent(`你研究生毕业,开始工作成为一名${state.career.levels[1]}`);
            }

            // 职业发展
            if (state.career.name !== "学生" && state.career.name !== "无业") {
                // 升职机会
                if (state.age >= 22 && state.careerLevel < state.career.levels.length - 1) {
                    const promotionChance = 0.2 + (state.intelligence - 50) * 0.01;
                    if (Math.random() < promotionChance) {
                        state.careerLevel++;
                        addEvent(`你升职了!现在是${state.career.levels[state.careerLevel]}`);
                    }
                }

                // 工资收入
                if (state.career.salary[state.careerLevel] > 0) {
                    const salary = state.career.salary[state.careerLevel];
                    // 天赋加成
                    const hasEntrepreneur = state.selectedTalents.includes(talentData.find(t => t.name === "企业家精神").id);
                    const bonus = hasEntrepreneur ? salary * 0.2 : 0;
                    const totalIncome = salary + bonus;

                    state.wealth += totalIncome;
                    if (bonus > 0) {
                        addEvent(`你获得了工资收入$${salary.toLocaleString()},因企业家精神天赋额外获得$${bonus.toLocaleString()}`);
                    } else {
                        addEvent(`你获得了工资收入$${salary.toLocaleString()}`);
                    }
                }
            }

            // 随机事件
            triggerRandomEvent();

            // 属性自然变化 - 修改:调整了健康衰减公式
            let healthDecline = 0.3 + Math.random() * 1.5;  // 基础衰减从0.5-2.5降低到0.3-1.8
            if (state.age > 60) healthDecline += 0.5;
            if (state.age > 80) healthDecline += 1;
            if (state.age > 100) healthDecline += 1;

            // 长寿基因天赋减少健康衰减
            if (state.selectedTalents.includes(talentData.find(t => t.name === "长寿基因").id)) {
                healthDecline *= 0.7;  // 减少30%健康衰减
            }

            state.health -= healthDecline;

            state.happiness += (Math.random() - 0.5) * 5;
            if (state.wealth > 1000000) state.happiness += 2;
            if (state.fame > 30) state.happiness += 2;

            // 属性限制
            state.health = Math.max(0, Math.min(100, state.health));
            state.happiness = Math.max(0, Math.min(100, state.happiness));

            // 检查死亡
            checkDeath();

            // 检查成就
            checkAchievements();

            updateLifeUI();
        }

        // 快进5年
        function fastForward() {
            if (!state.isAlive) return;

            for (let i = 0; i < 5; i++) {
                nextYear();
                if (!state.isAlive) break;
            }
        }

        // 触发随机事件
        function triggerRandomEvent() {
            let possibleEvents = [];

            // 根据年龄段选择事件
            if (state.age <= 12) {
                possibleEvents = eventData.childhood;
            } else if (state.age <= 19) {
                possibleEvents = eventData.teenage;
            } else if (state.age <= 39) {
                possibleEvents = eventData.youngAdult;
            } else if (state.age <= 59) {
                possibleEvents = eventData.middleAge;
            } else {
                possibleEvents = eventData.oldAge;
            }

            // 过滤符合年龄条件的事件
            possibleEvents = possibleEvents.filter(e =>
                state.age >= e.minAge && state.age <= e.maxAge
            );

            if (possibleEvents.length === 0) return;

            // 触发1-3个事件
            const eventCount = Math.floor(Math.random() * 3) + 1;
            for (let i = 0; i < eventCount; i++) {
                const event = possibleEvents[Math.floor(Math.random() * possibleEvents.length)];
                if (!event) continue;

                // 替换文本中的变量
                let eventText = event.text.replace("{age}", state.age);

                // 应用效果
                if (event.effects) {
                    for (const [key, value] of Object.entries(event.effects)) {
                        if (key === "isMarried" && value) {
                            // 结婚事件
                            const spouseNames = ["李华", "张伟", "王芳", "李娜", "张敏", "王伟", "李强", "张丽"];
                            state.spouse = spouseNames[Math.floor(Math.random() * spouseNames.length)];
                            eventText = eventText.replace("心仪的对象", state.spouse);
                            eventText = eventText.replace("结婚了", `与${state.spouse}结婚了`);
                        }

                        if (key in state) {
                            state[key] += value;
                        }
                    }
                }

                addEvent(eventText);
            }

            // 特殊事件:财富变化
            if (Math.random() < 0.3) {
                const wealthChange = Math.floor(Math.random() * 50000) - 20000;
                if (wealthChange > 0) {
                    state.wealth += wealthChange;
                    addEvent(`你意外获得了$${wealthChange.toLocaleString()}的额外收入`);
                } else if (wealthChange < 0) {
                    state.wealth += wealthChange; // wealthChange是负数
                    addEvent(`你损失了$${Math.abs(wealthChange).toLocaleString()}的财富`);
                }
            }
        }

        // 获取随机职业
        function getRandomCareer() {
            // 排除"无业"和"学生"
            const possibleCareers = careerData.slice(2);
            return possibleCareers[Math.floor(Math.random() * possibleCareers.length)];
        }

        // 检查死亡
        function checkDeath() {
            if (state.health <= 0) {
                state.isAlive = false;
                const deathEvents = eventData.death.filter(e =>
                    state.age >= e.minAge && state.health <= e.healthThreshold
                );

                let deathEvent;
                if (deathEvents.length > 0) {
                    deathEvent = deathEvents[Math.floor(Math.random() * deathEvents.length)];
                } else {
                    deathEvent = eventData.death[0]; // 默认年老去世
                }

                addEvent(deathEvent.text.replace("{age}", state.age));
                state.maxAge = state.age;
                endLife();
                return;
            }

            // 极小概率意外死亡
            if (Math.random() < 0.001) {
                state.isAlive = false;
                addEvent(`你在${state.age}岁时遭遇意外不幸去世`);
                state.maxAge = state.age;
                endLife();
            }
        }

        // 检查成就
        function checkAchievements() {
            achievementData.forEach(achievement => {
                if (!state.achievements.includes(achievement.name) && achievement.condition(state)) {
                    state.achievements.push(achievement.name);
                    addEvent(`<strong>成就解锁: ${achievement.name}</strong>`);
                }
            });
        }

        // 结束人生
        function endLife() {
            elements.nextYear.disabled = true;
            elements.fastForward.disabled = true;

            // 生成人生总结
            generateLifeSummary();
            elements.lifeSummary.style.display = 'block';
        }

        // 生成人生总结
        function generateLifeSummary() {
            let summary = `
                <p>你在${state.maxAge}岁时结束了这一生。</p>
                <p>最终财富: $${state.wealth.toLocaleString()}</p>
                <p>最终声望: ${state.fame}</p>
                <p>健康状况: ${state.health >= 70 ? "良好" : state.health >= 40 ? "一般" : "较差"}</p>
            `;

            if (state.isMarried) {
                summary += `<p>婚姻状况: 与${state.spouse}结婚${state.children > 0 ? `,育有${state.children}个孩子` : ''}</p>`;
            } else {
                summary += `<p>婚姻状况: 未婚</p>`;
            }

            if (state.career) {
                summary += `<p>职业发展: ${state.career.levels[state.careerLevel]}</p>`;
            }

            if (state.achievements.length > 0) {
                summary += `<p>人生成就: ${state.achievements.join(", ")}</p>`;
            }

            // 人生评价
            let evaluation = "";
            const score = calculateLifeScore();
            if (score >= 90) {
                evaluation = "传奇人生!你的一生将被世人铭记。";
            } else if (score >= 70) {
                evaluation = "成功人生!你取得了令人羡慕的成就。";
            } else if (score >= 50) {
                evaluation = "平凡但充实的人生。";
            } else if (score >= 30) {
                evaluation = "充满挑战的一生。";
            } else {
                evaluation = "艰难的一生。";
            }

            summary += `<p>人生评价: ${evaluation}</p>`;
            summary += `<p>人生得分: ${score}/100</p>`;

            elements.summaryContent.innerHTML = summary;
        }

        // 计算人生得分
        function calculateLifeScore() {
            let score = 0;

            // 寿命得分 (0-25) - 修改:提高了寿命得分上限
            score += Math.min(25, state.maxAge / 6);

            // 财富得分 (0-20)
            score += Math.min(20, Math.log10(state.wealth + 1) * 4);

            // 幸福得分 (0-15)
            score += state.happiness * 0.15;

            // 健康得分 (0-15)
            score += state.health * 0.15;

            // 成就得分 (0-15)
            score += state.achievements.length * 3;

            // 家庭得分 (0-10)
            if (state.isMarried) score += 5;
            score += Math.min(5, state.children * 2);

            return Math.round(score);
        }

        // 添加事件
        function addEvent(event) {
            const eventEl = document.createElement('div');
            eventEl.className = 'event';
            eventEl.innerHTML = `<span class="event-age">[${state.age}岁]</span> ${event}`;
            elements.eventLog.appendChild(eventEl);
            elements.eventLog.scrollTop = elements.eventLog.scrollHeight;

            // 记录事件
            state.events.push(`[${state.age}岁] ${event}`);
        }

        // 更新人生UI
        function updateLifeUI() {
            elements.age.textContent = state.age;
            elements.health.textContent = Math.round(state.health);
            elements.happiness.textContent = Math.round(state.happiness);
            elements.intelligence.textContent = Math.round(state.intelligence);
            elements.looks.textContent = Math.round(state.looks);
            elements.wealth.textContent = state.wealth.toLocaleString();
            elements.fame.textContent = Math.round(state.fame);

            // 更新成就列表
            elements.achievementsList.innerHTML = state.achievements.map(a =>
                `<div class="achievement">${a}</div>`
            ).join('');
        }

        // 重新开始
        function restart() {
            // 重置状态
            state.phase = "talent";
            state.selectedTalents = [];
            state.talentPoints = 20;

            state.age = 0;
            state.maxAge = 0;
            state.health = 100;
            state.happiness = 100;
            state.intelligence = 50;
            state.looks = 50;
            state.wealth = 0;
            state.fame = 0;

            state.isAlive = true;
            state.isMarried = false;
            state.spouse = null;
            state.children = 0;
            state.career = null;
            state.careerLevel = 0;
            state.education = "无";
            state.house = null;
            state.car = null;

            state.events = ["你出生了!开始了新的人生旅程..."];
            state.achievements = [];
            state.annualEvents = [];

            // 重置UI
            elements.talentPhase.classList.add('active');
            elements.lifePhase.classList.remove('active');
            elements.lifeSummary.style.display = 'none';
            elements.nextYear.disabled = false;
            elements.fastForward.disabled = false;

            initTalents();
            updateTalentUI();
        }

        // 初始化
        function init() {
            initTalents();
            updateTalentUI();

            // 事件监听
            elements.startLife.addEventListener('click', startLife);
            elements.nextYear.addEventListener('click', nextYear);
            elements.fastForward.addEventListener('click', fastForward);
            elements.restart.addEventListener('click', restart);
        }

        // 启动游戏
        init();
    </script>
</body>
</html>
原文