本人前一段时间受焦虑影响,于是自己用python写了一个焦虑症自测软件在此分享给各位

[复制链接]
111 |10
发表于 3 小时前 | 显示全部楼层 |阅读模式
上个月因为工作原因自我焦虑了,经过一个月治疗有所好转,于是出于焦虑就用python写了一个小软件。不知道论坛中有没有平常会焦虑的朋友,可以下载来看看,其中有20道焦虑症自测题(题目来源是GAD-7焦虑测试题),还有几个缓解压力的小游戏随便写着玩的(不保证有效果),还有一个环境音乐播放我没下载音乐素材,有会的大佬可以自己找几首环境音素材来添加进去。已经打包成EXE文件。


下载
蓝奏云https://wwto.lanzouu.com/iW086363ua2f


我把代码附到下面,大家可以自行添加环境音素材。


[Python]  
  1. import pygame
  2. import sys
  3. import random
  4. import math
  5. import time
  6. import os
  7. from pygame import gfxdraw
  8. # 初始化pygame
  9. pygame.init()
  10. pygame.font.init()
  11. pygame.mixer.init()
  12. # 屏幕尺寸
  13. SCREEN_WIDTH = 1000
  14. SCREEN_HEIGHT = 700
  15. screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
  16. pygame.display.set_caption("焦虑症患者工具箱")
  17. # 颜色定义
  18. BACKGROUND = (240, 245, 255)
  19. ACCENT = (70, 130, 180)
  20. LIGHT_ACCENT = (100, 160, 210)
  21. BUTTON_COLOR = (70, 130, 180)
  22. BUTTON_HOVER = (90, 150, 200)
  23. TEXT_COLOR = (50, 70, 100)
  24. LIGHT_TEXT = (240, 245, 255)
  25. WHITE = (255, 255, 255)
  26. GREEN = (100, 200, 100)
  27. RED = (220, 100, 100)
  28. YELLOW = (250, 200, 100)
  29. PURPLE = (180, 120, 200)
  30. LIGHT_GREEN = (200, 240, 200)
  31. LIGHT_RED = (240, 200, 200)
  32. LIGHT_YELLOW = (255, 240, 200)
  33. # 字体
  34. title_font = pygame.font.SysFont("simhei", 48)
  35. heading_font = pygame.font.SysFont("simhei", 36)
  36. normal_font = pygame.font.SysFont("simhei", 24)
  37. small_font = pygame.font.SysFont("simhei", 20)
  38. # 免责声明
  39. disclaimer_text = [
  40.     "免责声明:",
  41.     "1. 本工具箱提供的所有内容,包括焦虑自测工具和解压游戏,仅供娱乐和参考用途,",
  42.     "   不能替代专业医疗诊断、治疗或建议。",
  43.     "2. 如果您正在经历严重的焦虑症状或有心理健康问题,请务必咨询专业的医疗人员、",
  44.     "   心理医生或其他合格的健康服务提供者。",
  45.     "3. 本程序的开发者和分发者不对因使用本程序而导致的任何直接或间接损失承担责任,",
  46.     "   包括但不限于因依赖程序内容而导致的任何健康问题。",
  47.     "4. 自测结果仅供参考,不能作为任何临床诊断的依据。",
  48.     "5. 解压游戏的效果因人而异,不能保证对每个人都有效。",
  49.     "6. 继续使用本程序即表示您理解并同意上述免责条款。"
  50. ]
  51. # 焦虑自测题目 - 扩展版 (基于GAD-7和附加问题)
  52. test_questions = [
  53.     "1. 我感到紧张、焦虑或心烦意乱",
  54.     "2. 我无法停止或控制担忧",
  55.     "3. 我对各种事情过度担忧",
  56.     "4. 我很难放松",
  57.     "5. 我由于不安而无法静坐",
  58.     "6. 我变得容易烦恼或易怒",
  59.     "7. 我感到害怕,好像会发生可怕的事情",
  60.     "8. 我感到疲劳或容易疲倦",
  61.     "9. 我注意力难以集中或头脑一片空白",
  62.     "10. 我有睡眠问题(难以入睡、易醒或睡眠过多)",
  63.     "11. 我感到肌肉紧张或身体不适",
  64.     "12. 我避免可能引起焦虑的情境",
  65.     "13. 我出现心悸或心跳加速",
  66.     "14. 我出汗过多(并非因炎热或运动)",
  67.     "15. 我感到颤抖或手脚发抖",
  68.     "16. 我呼吸急促或有窒息感",
  69.     "17. 我感到恶心或腹部不适",
  70.     "18. 我感到头晕、头昏或不稳定",
  71.     "19. 我有不真实感或分离感",
  72.     "20. 我害怕失去控制或'发疯'"
  73. ]
  74. test_options = [
  75.     "完全没有",
  76.     "有几天",
  77.     "一半以上时间",
  78.     "几乎每天"
  79. ]
  80. # 游戏状态
  81. class State:
  82.     DISCLAIMER = 0
  83.     MAIN_MENU = 1
  84.     ANXIETY_TEST = 2
  85.     BREATHING_EXERCISE = 3
  86.     COLORING_GAME = 4
  87.     BALLOON_POP = 5
  88.     NATURE_SOUNDS = 6
  89.     TEST_RESULT = 7
  90. current_state = State.DISCLAIMER
  91. # 测试分数
  92. test_score = 0
  93. current_question = 0
  94. test_answers = []
  95. # 游戏变量
  96. breath_progress = 0
  97. breath_phase = 0  # 0: inhale, 1: hold, 2: exhale
  98. breath_colors = [(100, 180, 255), (150, 220, 150), (255, 200, 100)]
  99. breath_times = [4, 4, 6]  # 吸气、屏息、呼气时间(秒)
  100. breath_start_time = 0
  101. coloring_shapes = []
  102. for i in range(30):
  103.     size = random.randint(30, 80)
  104.     x = random.randint(50, SCREEN_WIDTH - 50)
  105.     y = random.randint(100, SCREEN_HEIGHT - 50)
  106.     color = (random.randint(150, 230), random.randint(150, 230), random.randint(150, 230))
  107.     shape_type = random.choice(["circle", "square", "triangle", "star"])
  108.     coloring_shapes.append({"x": x, "y": y, "size": size, "color": color, "type": shape_type, "filled": False})
  109. balloons = []
  110. for i in range(20):
  111.     balloons.append({
  112.         "x": random.randint(50, SCREEN_WIDTH - 50),
  113.         "y": SCREEN_HEIGHT + random.randint(0, 100),
  114.         "speed": random.uniform(0.5, 2.0),
  115.         "color": (random.randint(100, 255), random.randint(100, 255), random.randint(100, 255)),
  116.         "size": random.randint(30, 60),
  117.         "popped": False,
  118.         "pop_time": 0
  119.     })
  120. # 创建声音对象
  121. try:
  122.     # 尝试加载声音文件(如果存在)
  123.     ocean_sound = pygame.mixer.Sound("ocean.wav") if os.path.exists("ocean.wav") else None
  124.     rain_sound = pygame.mixer.Sound("rain.wav") if os.path.exists("rain.wav") else None
  125.     forest_sound = pygame.mixer.Sound("forest.wav") if os.path.exists("forest.wav") else None
  126.     birds_sound = pygame.mixer.Sound("birds.wav") if os.path.exists("birds.wav") else None
  127.     stream_sound = pygame.mixer.Sound("stream.wav") if os.path.exists("stream.wav") else None
  128. except:
  129.     # 如果加载失败,设置为None
  130.     ocean_sound = rain_sound = forest_sound = birds_sound = stream_sound = None
  131. sounds = [
  132.     {"name": "海浪声", "color": (70, 130, 180), "sound_obj": ocean_sound},
  133.     {"name": "雨声", "color": (100, 150, 200), "sound_obj": rain_sound},
  134.     {"name": "森林", "color": (80, 160, 120), "sound_obj": forest_sound},
  135.     {"name": "鸟鸣", "color": (180, 200, 100), "sound_obj": birds_sound},
  136.     {"name": "溪流", "color": (100, 180, 230), "sound_obj": stream_sound}
  137. ]
  138. selected_sound = None
  139. sound_timer = 0
  140. # 按钮类
  141. class Button:
  142.     def __init__(self, x, y, width, height, text, action=None):
  143.         self.rect = pygame.Rect(x, y, width, height)
  144.         self.text = text
  145.         self.action = action
  146.         self.hovered = False
  147.     def draw(self, surface):
  148.         color = BUTTON_HOVER if self.hovered else BUTTON_COLOR
  149.         pygame.draw.rect(surface, color, self.rect, border_radius=10)
  150.         pygame.draw.rect(surface, LIGHT_ACCENT, self.rect, width=2, border_radius=10)
  151.         text_surf = normal_font.render(self.text, True, LIGHT_TEXT)
  152.         text_rect = text_surf.get_rect(center=self.rect.center)
  153.         surface.blit(text_surf, text_rect)
  154.     def check_hover(self, pos):
  155.         self.hovered = self.rect.collidepoint(pos)
  156.     def handle_event(self, event):
  157.         if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
  158.             if self.hovered and self.action:
  159.                 self.action()
  160.                 return True
  161.         return False
  162. # 创建按钮
  163. disclaimer_agree_button = Button(SCREEN_WIDTH//2 - 100, SCREEN_HEIGHT - 100, 200, 50, "同意并继续", lambda: set_state(State.MAIN_MENU))
  164. main_menu_buttons = [
  165.     Button(SCREEN_WIDTH//2 - 150, 200, 300, 60, "焦虑症自测", lambda: set_state(State.ANXIETY_TEST)),
  166.     Button(SCREEN_WIDTH//2 - 150, 280, 300, 60, "呼吸练习", lambda: set_state(State.BREATHING_EXERCISE)),
  167.     Button(SCREEN_WIDTH//2 - 150, 360, 300, 60, "填色游戏", lambda: set_state(State.COLORING_GAME)),
  168.     Button(SCREEN_WIDTH//2 - 150, 440, 300, 60, "气球游戏", lambda: set_state(State.BALLOON_POP)),
  169.     Button(SCREEN_WIDTH//2 - 150, 520, 300, 60, "自然声音", lambda: set_state(State.NATURE_SOUNDS))
  170. ]
  171. test_buttons = [
  172.     Button(SCREEN_WIDTH//2 - 300, 500, 150, 40, "上一题", lambda: navigate_question(-1)),
  173.     Button(SCREEN_WIDTH//2 + 150, 500, 150, 40, "下一题", lambda: navigate_question(1))
  174. ]
  175. result_button = Button(SCREEN_WIDTH//2 - 100, 600, 200, 50, "返回主菜单", lambda: set_state(State.MAIN_MENU))
  176. back_button = Button(50, 50, 120, 40, "返回", lambda: set_state(State.MAIN_MENU))
  177. # 状态管理
  178. def set_state(state):
  179.     global current_state, test_score, current_question, test_answers, selected_sound
  180.     # 停止任何正在播放的声音
  181.     if selected_sound and selected_sound["sound_obj"]:
  182.         selected_sound["sound_obj"].stop()
  183.         selected_sound = None
  184.     if state == State.MAIN_MENU:
  185.         test_score = 0
  186.         current_question = 0
  187.         test_answers = []
  188.     current_state = state
  189. # 测试导航
  190. def navigate_question(direction):
  191.     global current_question
  192.     if direction == 1 and current_question < len(test_questions):
  193.         current_question += 1
  194.     elif direction == -1 and current_question > 0:
  195.         current_question -= 1
  196. # 处理测试选项选择
  197. def handle_test_selection(option_index):
  198.     global test_answers, test_score, current_question
  199.     if current_question < len(test_questions):
  200.         # 确保answers列表足够长
  201.         while len(test_answers)  current_question and test_answers[current_question] == i
  202.             color = LIGHT_ACCENT if hovered or selected else ACCENT
  203.             pygame.draw.rect(screen, color, option_rect, border_radius=8)
  204.             option_text = normal_font.render(option, True, LIGHT_TEXT)
  205.             screen.blit(option_text, (option_rect.centerx - option_text.get_width()//2,
  206.                                      option_rect.centery - option_text.get_height()//2))
  207.     if current_question > 0:
  208.         test_buttons[0].draw(screen)
  209.     if current_question < len(test_questions):
  210.         test_buttons[1].draw(screen)
  211. # 绘制测试结果
  212. def draw_test_result():
  213.     screen.fill(BACKGROUND)
  214.     title = heading_font.render("测试结果", True, ACCENT)
  215.     screen.blit(title, (SCREEN_WIDTH//2 - title.get_width()//2, 50))
  216.     score_text = heading_font.render(f"您的得分: {test_score}/{len(test_questions)*3}", True, TEXT_COLOR)
  217.     screen.blit(score_text, (SCREEN_WIDTH//2 - score_text.get_width()//2, 120))
  218.     if test_score  phase_duration:
  219.         breath_start_time = current_time
  220.         breath_phase = (breath_phase + 1) % 3
  221.         elapsed = 0
  222.     breath_progress = elapsed / phase_duration
  223.     if breath_phase == 0:  # 吸气
  224.         radius = int(max_radius * breath_progress)
  225.     elif breath_phase == 1:  # 屏息
  226.         radius = max_radius
  227.     else:  # 呼气
  228.         radius = int(max_radius * (1 - breath_progress))
  229.     color = breath_colors[breath_phase]
  230.     # 绘制同心圆
  231.     for i in range(5, 0, -1):
  232.         alpha = 100 - i * 20
  233.         circle_color = (color[0], color[1], color[2], alpha)
  234.         pygame.gfxdraw.filled_circle(screen, center_x, center_y, radius + i*5, circle_color)
  235.     pygame.draw.circle(screen, color, (center_x, center_y), radius)
  236.     pygame.draw.circle(screen, ACCENT, (center_x, center_y), radius, 3)
  237.     phase_texts = ["吸气...", "屏息...", "呼气..."]
  238.     text = heading_font.render(phase_texts[breath_phase], True, color)
  239.     screen.blit(text, (SCREEN_WIDTH//2 - text.get_width()//2, center_y + max_radius + 30))
  240.     # 绘制计时器
  241.     timer_text = normal_font.render(f"{int(elapsed)}秒", True, TEXT_COLOR)
  242.     screen.blit(timer_text, (SCREEN_WIDTH//2 - timer_text.get_width()//2, center_y + max_radius + 70))
  243. # 绘制填色游戏
  244. def draw_coloring_game():
  245.     screen.fill(BACKGROUND)
  246.     back_button.draw(screen)
  247.     title = heading_font.render("填色游戏", True, ACCENT)
  248.     screen.blit(title, (SCREEN_WIDTH//2 - title.get_width()//2, 50))
  249.     instruction = normal_font.render("点击图形进行填色 - 创建您自己的放松图案", True, TEXT_COLOR)
  250.     screen.blit(instruction, (SCREEN_WIDTH//2 - instruction.get_width()//2, 100))
  251.     for shape in coloring_shapes:
  252.         color = shape["color"] if shape["filled"] else (220, 220, 220)
  253.         border_color = (180, 180, 180) if not shape["filled"] else (color[0]//2, color[1]//2, color[2]//2)
  254.         if shape["type"] == "circle":
  255.             pygame.draw.circle(screen, color, (shape["x"], shape["y"]), shape["size"])
  256.             pygame.draw.circle(screen, border_color, (shape["x"], shape["y"]), shape["size"], 2)
  257.         elif shape["type"] == "square":
  258.             rect = pygame.Rect(shape["x"] - shape["size"]//2, shape["y"] - shape["size"]//2,
  259.                               shape["size"], shape["size"])
  260.             pygame.draw.rect(screen, color, rect, border_radius=5)
  261.             pygame.draw.rect(screen, border_color, rect, width=2, border_radius=5)
  262.         elif shape["type"] == "triangle":
  263.             points = [
  264.                 (shape["x"], shape["y"] - shape["size"]//2),
  265.                 (shape["x"] - shape["size"]//2, shape["y"] + shape["size"]//2),
  266.                 (shape["x"] + shape["size"]//2, shape["y"] + shape["size"]//2)
  267.             ]
  268.             pygame.draw.polygon(screen, color, points)
  269.             pygame.draw.polygon(screen, border_color, points, width=2)
  270.         else:  # star
  271.             points = []
  272.             for i in range(10):
  273.                 angle = math.pi/2 + i * math.pi/5
  274.                 radius = shape["size"] if i % 2 == 0 else shape["size"]//2
  275.                 x = shape["x"] + radius * math.cos(angle)
  276.                 y = shape["y"] - radius * math.sin(angle)
  277.                 points.append((x, y))
  278.             pygame.draw.polygon(screen, color, points)
  279.             pygame.draw.polygon(screen, border_color, points, width=2)
  280. # 绘制气球游戏
  281. def draw_balloon_pop():
  282.     global balloons
  283.     screen.fill(BACKGROUND)
  284.     back_button.draw(screen)
  285.     title = heading_font.render("气球游戏", True, ACCENT)
  286.     screen.blit(title, (SCREEN_WIDTH//2 - title.get_width()//2, 50))
  287.     instruction = normal_font.render("点击上升的气球 - 专注于目标有助于分散焦虑", True, TEXT_COLOR)
  288.     screen.blit(instruction, (SCREEN_WIDTH//2 - instruction.get_width()//2, 100))
  289.     # 更新气球位置
  290.     for balloon in balloons:
  291.         if balloon["popped"]:
  292.             # 处理爆炸效果
  293.             if time.time() - balloon["pop_time"] > 1.0:
  294.                 balloon["y"] = SCREEN_HEIGHT + random.randint(0, 50)
  295.                 balloon["x"] = random.randint(50, SCREEN_WIDTH - 50)
  296.                 balloon["popped"] = False
  297.             else:
  298.                 # 绘制爆炸效果
  299.                 explosion_size = balloon["size"] * 2 * (time.time() - balloon["pop_time"])
  300.                 pygame.draw.circle(screen, (255, 200, 100), (int(balloon["x"]), int(balloon["y"])), int(explosion_size), 2)
  301.                 for i in range(8):
  302.                     angle = i * math.pi/4
  303.                     end_x = balloon["x"] + explosion_size * math.cos(angle)
  304.                     end_y = balloon["y"] + explosion_size * math.sin(angle)
  305.                     pygame.draw.line(screen, (255, 150, 50), (balloon["x"], balloon["y"]), (end_x, end_y), 2)
  306.         else:
  307.             balloon["y"] -= balloon["speed"]
  308.             if balloon["y"] < -50:
  309.                 balloon["y"] = SCREEN_HEIGHT + random.randint(0, 50)
  310.                 balloon["x"] = random.randint(50, SCREEN_WIDTH - 50)
  311.             # 绘制气球
  312.             pygame.draw.circle(screen, balloon["color"], (int(balloon["x"]), int(balloon["y"])), balloon["size"])
  313.             # 气球高光
  314.             highlight_size = balloon["size"] // 3
  315.             highlight_pos = (balloon["x"] - highlight_size, balloon["y"] - highlight_size)
  316.             pygame.draw.circle(screen, (255, 255, 255, 150), highlight_pos, highlight_size)
  317.             # 气球底部
  318.             pygame.draw.line(screen, TEXT_COLOR,
  319.                             (balloon["x"], balloon["y"] + balloon["size"]),
  320.                             (balloon["x"] + random.randint(-10, 10), balloon["y"] + balloon["size"] + 15), 2)
  321. # 绘制自然声音
  322. def draw_nature_sounds():
  323.     global selected_sound, sound_timer
  324.     screen.fill(BACKGROUND)
  325.     back_button.draw(screen)
  326.     title = heading_font.render("自然声音", True, ACCENT)
  327.     screen.blit(title, (SCREEN_WIDTH//2 - title.get_width()//2, 50))
  328.     instruction = normal_font.render("选择一种自然声音进行放松 - 自然声音有助于降低压力水平", True, TEXT_COLOR)
  329.     screen.blit(instruction, (SCREEN_WIDTH//2 - instruction.get_width()//2, 100))
  330.     # 绘制声音选项
  331.     for i, sound in enumerate(sounds):
  332.         button_rect = pygame.Rect(SCREEN_WIDTH//2 - 150, 150 + i*60, 300, 50)
  333.         hovered = button_rect.collidepoint(pygame.mouse.get_pos())
  334.         # 检查是否是当前选中的声音
  335.         is_selected = selected_sound == sound
  336.         color = LIGHT_ACCENT if hovered or is_selected else sound["color"]
  337.         pygame.draw.rect(screen, color, button_rect, border_radius=8)
  338.         sound_text = normal_font.render(sound["name"], True, LIGHT_TEXT)
  339.         screen.blit(sound_text, (button_rect.centerx - sound_text.get_width()//2,
  340.                                 button_rect.centery - sound_text.get_height()//2))
  341.         # 如果声音文件不存在,显示提示
  342.         if sound["sound_obj"] is None:
  343.             warning = small_font.render("(声音文件未找到)", True, (255, 100, 100))
  344.             screen.blit(warning, (button_rect.right - warning.get_width() - 10,
  345.                                  button_rect.centery - warning.get_height()//2))
  346.     # 显示当前选择的声音
  347.     if selected_sound is not None:
  348.         text = normal_font.render(f"正在播放: {selected_sound['name']}", True, TEXT_COLOR)
  349.         screen.blit(text, (SCREEN_WIDTH//2 - text.get_width()//2, SCREEN_HEIGHT - 100))
  350.         # 绘制声波动画
  351.         center_x, center_y = SCREEN_WIDTH//2, SCREEN_HEIGHT - 150
  352.         max_radius = 50
  353.         for i in range(3):
  354.             radius = max_radius + math.sin(sound_timer + i) * 15
  355.             alpha = 200 - i * 70
  356.             wave_color = (selected_sound["color"][0], selected_sound["color"][1], selected_sound["color"][2], alpha)
  357.             pygame.gfxdraw.filled_circle(screen, center_x, center_y, int(radius), wave_color)
  358.         sound_timer += 0.1
  359.         # 停止按钮
  360.         stop_button = pygame.Rect(SCREEN_WIDTH//2 + 150, SCREEN_HEIGHT - 100, 100, 30)
  361.         pygame.draw.rect(screen, (200, 100, 100), stop_button, border_radius=5)
  362.         stop_text = small_font.render("停止", True, LIGHT_TEXT)
  363.         screen.blit(stop_text, (stop_button.centerx - stop_text.get_width()//2,
  364.                                stop_button.centery - stop_text.get_height()//2))
  365. # 主游戏循环
  366. clock = pygame.time.Clock()
  367. running = True
  368. while running:
  369.     mouse_pos = pygame.mouse.get_pos()
  370.     for event in pygame.event.get():
  371.         if event.type == pygame.QUIT:
  372.             running = False
  373.         if current_state == State.DISCLAIMER:
  374.             disclaimer_agree_button.check_hover(mouse_pos)
  375.             if event.type == pygame.MOUSEBUTTONDOWN:
  376.                 disclaimer_agree_button.handle_event(event)
  377.         elif current_state == State.MAIN_MENU:
  378.             for button in main_menu_buttons:
  379.                 button.check_hover(mouse_pos)
  380.                 if event.type == pygame.MOUSEBUTTONDOWN:
  381.                     button.handle_event(event)
  382.         elif current_state == State.ANXIETY_TEST:
  383.             back_button.check_hover(mouse_pos)
  384.             test_buttons[0].check_hover(mouse_pos)
  385.             test_buttons[1].check_hover(mouse_pos)
  386.             if event.type == pygame.MOUSEBUTTONDOWN:
  387.                 if back_button.handle_event(event):
  388.                     continue
  389.                 if current_question > 0:
  390.                     test_buttons[0].handle_event(event)
  391.                 if current_question < len(test_questions):
  392.                     test_buttons[1].handle_event(event)
  393.                 # 检查选项点击
  394.                 for i in range(len(test_options)):
  395.                     option_rect = pygame.Rect(SCREEN_WIDTH//2 - 150, 250 + i*60, 300, 50)
  396.                     if option_rect.collidepoint(mouse_pos):
  397.                         handle_test_selection(i)
  398.         elif current_state == State.TEST_RESULT:
  399.             result_button.check_hover(mouse_pos)
  400.             if event.type == pygame.MOUSEBUTTONDOWN:
  401.                 result_button.handle_event(event)
  402.         elif current_state in [State.BREATHING_EXERCISE, State.COLORING_GAME,
  403.                               State.BALLOON_POP, State.NATURE_SOUNDS]:
  404.             back_button.check_hover(mouse_pos)
  405.             if event.type == pygame.MOUSEBUTTONDOWN:
  406.                 if back_button.handle_event(event):
  407.                     continue
  408.                 if current_state == State.COLORING_GAME:
  409.                     for shape in coloring_shapes:
  410.                         dist = math.sqrt((mouse_pos[0] - shape["x"])**2 + (mouse_pos[1] - shape["y"])**2)
  411.                         if dist < shape["size"]:
  412.                             shape["filled"] = not shape["filled"]
  413.                             if shape["filled"]:
  414.                                 shape["color"] = (random.randint(100, 255), random.randint(100, 255), random.randint(100, 255))
  415.                 elif current_state == State.BALLOON_POP:
  416.                     for balloon in balloons:
  417.                         dist = math.sqrt((mouse_pos[0] - balloon["x"])**2 + (mouse_pos[1] - balloon["y"])**2)
  418.                         if dist < balloon["size"] and not balloon["popped"]:
  419.                             balloon["popped"] = True
  420.                             balloon["pop_time"] = time.time()
  421.                 elif current_state == State.NATURE_SOUNDS:
  422.                     # 检查声音选项点击
  423.                     for i, sound in enumerate(sounds):
  424.                         button_rect = pygame.Rect(SCREEN_WIDTH//2 - 150, 150 + i*60, 300, 50)
  425.                         if button_rect.collidepoint(mouse_pos):
  426.                             # 停止当前声音
  427.                             if selected_sound and selected_sound["sound_obj"]:
  428.                                 selected_sound["sound_obj"].stop()
  429.                             # 播放新声音
  430.                             if sound["sound_obj"]:
  431.                                 sound["sound_obj"].play(-1)  # -1表示循环播放
  432.                                 selected_sound = sound
  433.                     # 检查停止按钮点击
  434.                     if selected_sound:
  435.                         stop_button = pygame.Rect(SCREEN_WIDTH//2 + 150, SCREEN_HEIGHT - 100, 100, 30)
  436.                         if stop_button.collidepoint(mouse_pos):
  437.                             selected_sound["sound_obj"].stop()
  438.                             selected_sound = None
  439.     # 绘制当前状态
  440.     if current_state == State.DISCLAIMER:
  441.         draw_disclaimer()
  442.     elif current_state == State.MAIN_MENU:
  443.         draw_main_menu()
  444.     elif current_state == State.ANXIETY_TEST:
  445.         draw_anxiety_test()
  446.     elif current_state == State.TEST_RESULT:
  447.         draw_test_result()
  448.     elif current_state == State.BREATHING_EXERCISE:
  449.         draw_breathing_exercise()
  450.     elif current_state == State.COLORING_GAME:
  451.         draw_coloring_game()
  452.     elif current_state == State.BALLOON_POP:
  453.         draw_balloon_pop()
  454.     elif current_state == State.NATURE_SOUNDS:
  455.         draw_nature_sounds()
  456.     pygame.display.flip()
  457.     clock.tick(60)
  458. # 退出前停止所有声音
  459. if selected_sound and selected_sound["sound_obj"]:
  460.     selected_sound["sound_obj"].stop()
  461. pygame.quit()
  462. sys.exit()
复制代码












本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

发表于 3 小时前 | 显示全部楼层
感谢分享,心病用佛法化解,念念心经、金刚经,让你心如止水。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

发表于 3 小时前 | 显示全部楼层
如果能支持看治疗焦虑的带声音的视频,那将是更棒的存在,特别是最近手机APP“今日头条”上一些个治疗型视频,我的天,简直让人如看仙景,如聆静心妙音,瞬间似有治愈感,非常震憾。希望做成此事。技术上不难,就是视频播放,音视频可以自己录制或制作好,也可以网上收集。
回复

使用道具 举报

发表于 3 小时前 | 显示全部楼层
这还是焦虑吗,
回复

使用道具 举报

发表于 3 小时前 | 显示全部楼层
感谢分享
回复

使用道具 举报

发表于 3 小时前 | 显示全部楼层
还能这么玩?下载过来测测自己不错
回复

使用道具 举报

发表于 3 小时前 | 显示全部楼层
做的很帮,告别焦虑,支持支持
回复

使用道具 举报

发表于 3 小时前 | 显示全部楼层
这个时代太匆忙。大家的内心太焦虑。
回复

使用道具 举报

发表于 3 小时前 | 显示全部楼层
感谢大佬分享,告别焦虑,支持支持
回复

使用道具 举报

发表于 3 小时前 | 显示全部楼层
感谢分享,测下焦虑挺不错的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表