import pygame
import random

# ===================== 配置区（自行修改）=====================
NAME_LIST = [
    "张三", "李四", "王五", "赵六",
    "小明", "小红", "小华", "小李",
    "小陈", "小周", "小吴", "郑同学"
]
WIDTH, HEIGHT = 800, 500
FPS = 60
# ==========================================================

pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("随机点名抽签器")
clock = pygame.time.Clock()

# 字体设置（系统黑体，兼容Windows/Mac）
try:
    font_big = pygame.font.SysFont("simhei", 120)   # 名字大字
    font_tip = pygame.font.SysFont("simhei", 32)    # 提示文字
except:
    font_big = pygame.font.Font(None, 120)
    font_tip = pygame.font.Font(None, 32)

is_running = False    # 是否正在滚动抽签
current_name = "点击空格开始抽签"

def get_random_name():
    """随机获取一名"""
    return random.choice(NAME_LIST)

# 主循环
running = True
while running:
    clock.tick(FPS)
    screen.fill((25, 25, 35))  # 背景深色

    # 事件监听
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN:
            # 空格键切换启动/停止
            if event.key == pygame.K_SPACE:
                is_running = not is_running

    # 滚动状态持续刷新名字
    if is_running:
        current_name = get_random_name()

    # 绘制文字
    # 显示名字
    text_surface = font_big.render(current_name, True, (255, 220, 80))
    text_rect = text_surface.get_rect(center=(WIDTH//2, HEIGHT//2))
    screen.blit(text_surface, text_rect)

    # 底部提示
    tip_text = "【空格键】开始 / 停止抽签"
    tip_surface = font_tip.render(tip_text, True, (180, 180, 180))
    tip_rect = tip_surface.get_rect(center=(WIDTH//2, HEIGHT - 60))
    screen.blit(tip_surface, tip_rect)

    pygame.display.flip()

pygame.quit()