# -*- coding: utf-8 -*-
import pygame
import sys
import os

# 初始化Pygame
pygame.init()
W, H = 800, 600
screen = pygame.display.set_mode((W, H))
pygame.display.set_caption("中国历史上下五千年")
clock = pygame.time.Clock()

# ====================== 关键：解决中文方框的终极字体方案 ======================
# 直接指定Windows系统自带的宋体完整路径，100%不会报错、不会方框
font_path = r"C:\Windows\Fonts\simsun.ttc"
# 加载字体（字号20，正常显示）
font = pygame.font.Font(font_path, 20)
# 标题字体（字号30，加粗）
title_font = pygame.font.Font(font_path, 25)

# ====================== 历史内容 ======================
history = [
    "【中国历史上下五千年】",
    "",
    "约前2070年：夏朝建立 · 中国第一个王朝",
    "约前1600年：商朝 · 甲骨文出现",
    "约前1046年：西周建立 · 礼乐文明",
    "前770年：春秋开始 · 诸侯争霸",
    "前475年：战国时代 · 百家争鸣",
    "前221年：秦始皇统一六国",
    "前202年：西汉建立 · 张骞出使西域",
    "8年：新朝建立 · 王莽夺汉",
    "25年：东汉 · 蔡伦造纸",
    "220年：三国鼎立",
    "581年：隋朝统一 · 大运河",
    "618年：唐朝 · 贞观之治",
    "960年：北宋 · 科技繁荣",
    "1271年：元朝大一统",
    "1368年：明朝 · 郑和下西洋",
    "1636年：清朝 · 康乾盛世",
    "1840年：鸦片战争 · 近代史开端",
    "1912年：中华民国成立",
    "1949年：中华人民共和国成立",
    "",
    "上下五千年 · 文明从未中断"
]

# 滚动相关变量
y_pos = H  # 初始位置在屏幕底部
scroll_speed = 1  # 滚动速度

# ====================== 主循环 ======================
while True:
    # 填充背景色（深蓝色）
    screen.fill((0, 0, 40))

    # 事件处理（关闭窗口）
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    # 绘制标题
    title_surf = title_font.render("中国历史动态时间轴 · 东台市实验小学 · 520 · 韩孟泽", True, (255, 200, 0))
    screen.blit(title_surf, (W//2 - title_surf.get_width()//2, 20))

    # 绘制历史内容
    current_y = y_pos
    for line in history:
        # 渲染中文文字（白色）
        text_surf = font.render(line, True, (255, 255, 255))
        screen.blit(text_surf, (60, current_y))
        current_y += 30  # 每行间距30像素

    # 实现向上滚动
    y_pos -= scroll_speed
    # 当所有内容滚出屏幕后，重置位置，循环播放
    if current_y < 0:
        y_pos = H

    # 更新屏幕
    pygame.display.flip()
    # 控制帧率60帧/秒
    clock.tick(60)