import pygame
import random

# ========== 单词库 ==========
words = [
    ("apple", "苹果"),
    ("banana", "香蕉"),
    ("computer", "电脑"),
    ("library", "图书馆"),
    ("student", "学生"),
    ("teacher", "老师"),
    ("city", "城市"),
    ("country", "国家"),
]

random.shuffle(words)

# ========== pygame 初始化 ==========
pygame.init()
screen = pygame.display.set_mode((600, 400))
pygame.display.set_caption("英语单词背诵")

font_big = pygame.font.SysFont("simhei", 48)
font_small = pygame.font.SysFont("simhei", 26)

clock = pygame.time.Clock()

index = 0
show = False

# ========== 主循环 ==========
running = True
while running:
    screen.fill((20, 20, 30))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_SPACE:
                show = True
            if event.key == pygame.K_RIGHT:
                index += 1
                if index >= len(words):
                    index = 0
                show = False  # 自动隐藏释义

    word, meaning = words[index]

    # 单词
    w = font_big.render(word, True, (255, 255, 255))
    screen.blit(w, (300 - w.get_width() // 2, 120))

    # 释义
    if show:
        m = font_big.render(meaning, True, (0, 255, 150))
        screen.blit(m, (300 - m.get_width() // 2, 200))
    else:
        tip = font_small.render("按 空格 显示释义 | → 下一个", True, (180, 180, 180))
        screen.blit(tip, (300 - tip.get_width() // 2, 200))

    # 进度
    p = font_small.render(f"{index + 1} / {len(words)}", True, (200, 200, 200))
    screen.blit(p, (20, 360))

    pygame.display.flip()
    clock.tick(30)

pygame.quit()
