1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
| import pygame
import random
import time
import tkinter as tk
from tkinter import simpledialog
# Инициализация Pygame
pygame.init()
# Установка размеров окна
WIDTH, HEIGHT = 800, 600
window = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Реакция на круг")
# Определение цветов
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
YELLOW = (255, 255, 0)
ORANGE = (255, 165, 0)
# Параметры круга
CIRCLE_RADIUS = 50
CIRCLE_TIME_DISAPPEAR = 1000
MIN_APPEAR_INTERVAL = 500 # 0.5 секунды в миллисекундах
MAX_APPEAR_INTERVAL = 3000 # 3 секунды в миллисекундах
# Загрузка звуковых эффектов
pygame.mixer.init()
good_reaction_sound = pygame.mixer.Sound("good_reaction.wav")
bad_reaction_sound = pygame.mixer.Sound("bad_reaction.wav")
def write_reaction_time(reaction_time, file_name, experiment_info, circle_number):
with open(file_name, "a") as file:
if file.tell() == 0:
file.write(f"Информация об эксперименте: {experiment_info}\n\n")
file.write(f"Круг {circle_number}: Время реакции: {reaction_time:.2f} секунд\n")
# Основная функция игры (основная версия)
def reaction_game_basic(file_name):
running = True
WAIT_TIME_MS = 3000
clock = pygame.time.Clock()
circle_x, circle_y = 0, 0
circle_visible = False
circle_appear_time = 0
space_pressed_time = 0
anticipation_time = 0
circle_number = 1 # Порядковый номер круга
while running:
window.fill(WHITE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
current_time = pygame.time.get_ticks()
if circle_visible:
reaction_time = current_time - circle_appear_time
print(f"Круг {circle_number}: Время реакции: {reaction_time / 1000:.2f} секунд")
write_reaction_time(reaction_time / 1000, file_name, "Основная версия", circle_number)
circle_visible = False
space_pressed_time = current_time
anticipation_time = 0
circle_number += 1
else:
anticipation_time = max(-3.0, (current_time - space_pressed_time - WAIT_TIME_MS) / 1000)
print(f"Круг {circle_number}: Время Ожидания: {anticipation_time:.2f} секунд")
write_reaction_time(anticipation_time, file_name, "Основная версия", circle_number)
if not circle_visible:
current_time = pygame.time.get_ticks()
if current_time - space_pressed_time >= WAIT_TIME_MS:
circle_visible = True
circle_appear_time = current_time
circle_x = random.randint(CIRCLE_RADIUS, WIDTH - CIRCLE_RADIUS)
circle_y = random.randint(CIRCLE_RADIUS, HEIGHT - CIRCLE_RADIUS)
if circle_visible:
pygame.draw.circle(window, RED, (circle_x, circle_y), CIRCLE_RADIUS)
pygame.display.flip()
clock.tick(60)
pygame.quit()
# Функция игры с отображением времени
def reaction_game_with_time_display(file_name):
pygame.init()
window = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Reaction Game")
running = True
WAIT_TIME_MS = 3000
clock = pygame.time.Clock()
circle_x, circle_y = 0, 0
circle_visible = False
circle_appear_time = 0
space_pressed_time = 0
circle_number = 1 # Порядковый номер круга
DISPLAY_TIME_MS = 500
# Создание объекта шрифта для вывода текста на экран
font = pygame.font.Font(None, 36)
reaction_time_display = "" # Переменная для отображения времени реакции
display_timer = 0 # Таймер для отображения времени реакции на экране
while running:
window.fill(WHITE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
current_time = pygame.time.get_ticks()
if circle_visible:
reaction_time = current_time - circle_appear_time
write_reaction_time(reaction_time / 1000, file_name, "Основная версия", circle_number)
reaction_time_display = f"Время реакции: {reaction_time / 1000:.2f} секунд"
circle_visible = False
space_pressed_time = current_time
circle_number += 1
display_timer = current_time # Старт таймера отображения времени реакции
else:
anticipation_time = max(-3.0, (current_time - space_pressed_time - WAIT_TIME_MS) / 1000)
write_reaction_time(anticipation_time, file_name, "Основная версия", circle_number)
if not circle_visible:
current_time = pygame.time.get_ticks()
if current_time - space_pressed_time >= WAIT_TIME_MS:
circle_visible = True
circle_appear_time = current_time
circle_x = random.randint(CIRCLE_RADIUS, WIDTH - CIRCLE_RADIUS)
circle_y = random.randint(CIRCLE_RADIUS, HEIGHT - CIRCLE_RADIUS)
if circle_visible:
pygame.draw.circle(window, RED, (circle_x, circle_y), CIRCLE_RADIUS)
# Отображение времени реакции на экране в течение 0.5 секунд после реакции
if display_timer > 0 and pygame.time.get_ticks() - display_timer < DISPLAY_TIME_MS:
text_surface = font.render(reaction_time_display, True, RED)
window.blit(text_surface, (10, 10))
pygame.display.flip()
clock.tick(60)
pygame.quit()
# Функция игры с визуальной обратной связью
def reaction_game_with_visual_feedback(file_name):
running = True
WAIT_TIME_MS = 3000
clock = pygame.time.Clock()
circle_x, circle_y = 0, 0
circle_visible = False
circle_appear_time = 0
space_pressed_time = 0
anticipation_time = 0
circle_number = 1 # Порядковый номер круга
while running:
window.fill(WHITE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
current_time = pygame.time.get_ticks()
if not circle_visible:
# Закрашиваем экран оранжевым, если игрок нажал пробел до появления круга
window.fill(ORANGE)
pygame.display.flip()
pygame.time.wait(200) # Маленькая задержка для отображения оранжевого цвета
if circle_visible:
reaction_time = current_time - circle_appear_time
print(f"Круг {circle_number}: Время реакции: {reaction_time / 1000:.2f} секунд")
if reaction_time < 500: # Время реакции < 0.5 секунды
window.fill(GREEN) # Закрашиваем экран зеленым
else:
window.fill(YELLOW) # Закрашиваем экран желтым
pygame.display.flip()
pygame.time.wait(200) # Маленькая задержка для отображения цвета
window.fill(WHITE) # Очищаем экран
pygame.display.flip()
write_reaction_time(reaction_time / 1000, file_name, "Основная версия", circle_number)
circle_visible = False
space_pressed_time = current_time
anticipation_time = 0
circle_number += 1
else:
anticipation_time = max(-3.0, (current_time - space_pressed_time - WAIT_TIME_MS) / 1000)
print(f"Круг {circle_number}: Время Ожидания: {anticipation_time:.2f} секунд")
write_reaction_time(anticipation_time, file_name, "Основная версия", circle_number)
if not circle_visible:
current_time = pygame.time.get_ticks()
if current_time - space_pressed_time >= WAIT_TIME_MS:
circle_visible = True
circle_appear_time = current_time
circle_x = random.randint(CIRCLE_RADIUS, WIDTH - CIRCLE_RADIUS)
circle_y = random.randint(CIRCLE_RADIUS, HEIGHT - CIRCLE_RADIUS)
if circle_visible:
pygame.draw.circle(window, RED, (circle_x, circle_y), CIRCLE_RADIUS)
pygame.display.flip()
clock.tick(60)
pygame.quit()
# Функция игры с звуковой обратной связью
def reaction_game_with_sound_feedback(file_name):
running = True
WAIT_TIME_MS = 3000
clock = pygame.time.Clock()
circle_x, circle_y = 0, 0
circle_visible = False
circle_appear_time = 0
space_pressed_time = 0
anticipation_time = 0
circle_number = 1 # Порядковый номер круга
while running:
window.fill(WHITE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
current_time = pygame.time.get_ticks()
if not circle_visible:
bad_reaction_sound.play()
if circle_visible:
reaction_time = current_time - circle_appear_time
print(f"Круг {circle_number}: Время реакции: {reaction_time / 1000:.2f} секунд")
if reaction_time < 500: # Время реакции < 0.5 секунды
good_reaction_sound.play() # Закрашиваем экран зеленым
else:
bad_reaction_sound.play()
write_reaction_time(reaction_time / 1000, file_name, "Основная версия", circle_number)
circle_visible = False
space_pressed_time = current_time
anticipation_time = 0
circle_number += 1
else:
anticipation_time = max(-3.0, (current_time - space_pressed_time - WAIT_TIME_MS) / 1000)
print(f"Круг {circle_number}: Время Ожидания: {anticipation_time:.2f} секунд")
write_reaction_time(anticipation_time, file_name, "Основная версия", circle_number)
if not circle_visible:
current_time = pygame.time.get_ticks()
if current_time - space_pressed_time >= WAIT_TIME_MS:
circle_visible = True
circle_appear_time = current_time
circle_x = random.randint(CIRCLE_RADIUS, WIDTH - CIRCLE_RADIUS)
circle_y = random.randint(CIRCLE_RADIUS, HEIGHT - CIRCLE_RADIUS)
if circle_visible:
pygame.draw.circle(window, RED, (circle_x, circle_y), CIRCLE_RADIUS)
pygame.display.flip()
clock.tick(60)
pygame.quit()
# Функция игры с генерацией случайных времен появления кругов
def reaction_game_random_time(file_name):
running = True
clock = pygame.time.Clock()
circle_x, circle_y = 0, 0
circle_visible = False
space_pressed_time = 0
anticipation_time = 0
circle_number = 1 # Порядковый номер круга
WAIT_TIME_SEC = random.randint(500, 3000) # Объявляем здесь, чтобы значение не сбрасывалось
while running:
window.fill(WHITE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
current_time = pygame.time.get_ticks()
if circle_visible:
reaction_time = current_time - circle_appear_time
print(f"Круг {circle_number}: Время реакции: {reaction_time / 1000:.2f} секунд")
# Здесь можно вызвать функцию записи времени реакции в файл
circle_visible = False
space_pressed_time = current_time
anticipation_time = 0
circle_number += 1
else:
anticipation_time = max(-3.0, (current_time - space_pressed_time - WAIT_TIME_SEC) / 1000)
print(f"Круг {circle_number}: Время Ожидания: {anticipation_time:.2f} секунд")
# Здесь можно вызвать функцию записи времени ожидания в файл
if not circle_visible:
current_time = pygame.time.get_ticks()
if current_time - space_pressed_time >= WAIT_TIME_SEC: # Преобразование в миллисекунды
circle_visible = True
circle_appear_time = current_time
circle_x = WIDTH // 2 # центр окна по X
circle_y = HEIGHT // 2 # центр окна по Y
WAIT_TIME_SEC = random.randint(500, 3000) # Обновляем время ожидания
if circle_visible:
pygame.draw.circle(window, RED, (circle_x, circle_y), CIRCLE_RADIUS)
pygame.display.flip()
clock.tick(60)
pygame.quit()
# Функция игры с появлением круга в центре окна
def reaction_game_centered_circle(file_name):
running = True
WAIT_TIME_MS = 3000
clock = pygame.time.Clock()
circle_x, circle_y = 0, 0
circle_visible = False
circle_appear_time = 0
space_pressed_time = 0
anticipation_time = 0
circle_number = 1 # Порядковый номер круга
while running:
window.fill(WHITE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
current_time = pygame.time.get_ticks()
if circle_visible:
reaction_time = current_time - circle_appear_time
print(f"Круг {circle_number}: Время реакции: {reaction_time / 1000:.2f} секунд")
write_reaction_time(reaction_time / 1000, file_name, "Основная версия", circle_number)
circle_visible = False
space_pressed_time = current_time
anticipation_time = 0
circle_number += 1
else:
anticipation_time = max(-3.0, (current_time - space_pressed_time - WAIT_TIME_MS) / 1000)
print(f"Круг {circle_number}: Время Ожидания: {anticipation_time:.2f} секунд")
write_reaction_time(anticipation_time, file_name, "Основная версия", circle_number)
if not circle_visible:
current_time = pygame.time.get_ticks()
if current_time - space_pressed_time >= WAIT_TIME_MS:
circle_visible = True
circle_appear_time = current_time
circle_x = WIDTH // 2 # центр окна по X
circle_y = HEIGHT // 2 # центр окна по Y
if circle_visible:
pygame.draw.circle(window, RED, (circle_x, circle_y), CIRCLE_RADIUS)
pygame.display.flip()
clock.tick(60)
pygame.quit()
# Функция создания файла с данными пользователя
def create_user_file(participant_number):
file_name = f"participant_{participant_number}_reaction_times.txt"
with open(file_name, "w") as file:
file.write(f"Номер испытуемого: {participant_number}\n\n")
return file_name
# Функция выбора имени и фамилии с помощью Tkinter
def get_participant_number():
root = tk.Tk()
root.withdraw() # Скрыть корневое окно
participant_number = simpledialog.askinteger("Введите номер испытуемого", "Введите номер испытуемого:")
return participant_number
# Главное меню
def main_menu():
participant_number = get_participant_number()
if not participant_number:
return
file_name = create_user_file(participant_number)
root = tk.Tk()
root.title("Меню выбора версии игры")
label = tk.Label(root, text="Выберите версию игры:")
label.pack()
def start_basic():
root.destroy()
reaction_game_basic(file_name)
def start_with_time_display():
root.destroy()
reaction_game_with_time_display(file_name)
def start_with_visual_feedback():
root.destroy()
reaction_game_with_visual_feedback(file_name)
def start_with_sound_feedback():
root.destroy()
reaction_game_with_sound_feedback(file_name)
def start_with_random_time():
root.destroy()
reaction_game_random_time(file_name)
def start_centered_circle():
root.destroy()
reaction_game_centered_circle(file_name)
basic_button = tk.Button(root, text="Основная версия", command=start_basic)
basic_button.pack()
time_display_button = tk.Button(root, text="Версия с отображением времени", command=start_with_time_display)
time_display_button.pack()
visual_feedback_button = tk.Button(root, text="Версия с визуальной обратной связью", command=start_with_visual_feedback)
visual_feedback_button.pack()
sound_feedback_button = tk.Button(root, text="Версия с звуковой обратной связью", command=start_with_sound_feedback)
sound_feedback_button.pack()
random_time_button = tk.Button(root, text="Версия с генерацией случайных времен", command=start_with_random_time)
random_time_button.pack()
centered_circle_button = tk.Button(root, text="Версия с кругом в центре", command=start_centered_circle)
centered_circle_button.pack()
root.mainloop()
if __name__ == "__main__":
main_menu() |