def showmainmenudisplay(gs, configmodule): """Отображает главное меню."""…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
def show_main_menu_display(gs, config_module): """Отображает главное меню.""" gs.custom_mode_active = False gs.WIDTH, gs.HEIGHT = config_module.DEFAULT_WIDTH, config_module.DEFAULT_HEIGHT gs.update_display_mode()
buttons = []
available_lengths = sorted([length for length, words in gs.WORD_SETS.items() if words])
btn_y_start, btn_spacing = 180, 70
running = True
while running:
draw_gradient_background(gs.screen, gs.WIDTH, gs.HEIGHT, config_module.COLORS['MENU_BG_GRAD1'], config_module.COLORS['MENU_BG_GRAD2'])
draw_text_centered(gs.screen, "Выберите сложность", gs.get_font('main'), config_module.COLORS['BLACK'], gs.WIDTH // 2, 100)
buttons.clear()
displayed_btns = 0
for length in available_lengths:
if not (3 <= length <= 10) and (len(available_lengths) > 4 and not (4 <= length <= 7)):
continue
btn_text = f"{length} букв ({len(gs.WORD_SETS.get(length, []))} слов)"
rect = pygame.Rect(gs.WIDTH // 2 - 150, btn_y_start + displayed_btns * btn_spacing, 300, 50)
pygame.draw.rect(gs.screen, config_module.COLORS['GRAY'], rect, border_radius=12)
draw_text_centered(gs.screen, btn_text, gs.get_font('small'), config_module.COLORS['BLACK'], rect.centerx, rect.centery)
buttons.append((rect, length))
displayed_btns += 1
if displayed_btns >= 5 and len(available_lengths) > 6: break
custom_btn_rect = pygame.Rect(gs.WIDTH // 2 - 100, btn_y_start + displayed_btns * btn_spacing, 200, 50)
pygame.draw.rect(gs.screen, config_module.COLORS['GRAY'], custom_btn_rect, border_radius=12)
draw_text_centered(gs.screen, "Своя сложность", gs.get_font('custom_difficulty_button'), config_module.COLORS['BLACK'], custom_btn_rect.centerx, custom_btn_rect.centery)
buttons.append((custom_btn_rect, 'custom'))
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
for rect, choice in buttons:
if rect.collidepoint(event.pos):
if choice == 'custom':
result = prompt_custom_difficulty_settings(gs, config_module)
if result is not None:
return result
elif isinstance(choice, int) and gs.WORD_SETS.get(choice):
return choice
склоняйте слово "букв" в зависимости от правильной формы. Например 3,4 буквы, но 5,6,7 букв
Нужно добавить функцию, которая по числу возвращает правильную форму слова «буква». Например:
def decline_letters(n):
"""
Возвращает правильную форму слова «буква» для числа n.
Примеры:
1 -> "буква"
2-4 -> "буквы"
5-0 и исключения -> "букв"
"""
# Если число заканчивается на 1, но не на 11 — то «буква»
if n % 10 == 1 and n % 100 != 11:
return "буква"
# Если число заканчивается на 2-4, но не 12-14 — то «буквы»
elif n % 10 in (2, 3, 4) and n % 100 not in (12, 13, 14):
return "буквы"
else:
return "букв"
Далее в функции show_main_menu_display вместо того, чтобы жёстко писать слово "букв", можно использовать эту функцию. Например, строку
btn_text = f"{length} букв ({len(gs.WORD_SETS.get(length, []))} слов)"
заменить на
btn_text = f"{length} {decline_letters(length)} ({len(gs.WORD_SETS.get(length, []))} слов)"
Таким образом, при значениях 3 и 4 выведется «3 буквы», «4 буквы», а при 5, 6, 7 — «5 букв», «6 букв», «7 букв».
Полный вариант фрагмента кода может выглядеть так:
def decline_letters(n):
"""
Возвращает правильную форму слова «буква» для числа n.
Примеры:
1 -> "буква"
2-4 -> "буквы"
5-0 и исключения -> "букв"
"""
if n % 10 == 1 and n % 100 != 11:
return "буква"
elif n % 10 in (2, 3, 4) and n % 100 not in (12, 13, 14):
return "буквы"
else:
return "букв"
def show_main_menu_display(gs, config_module):
"""Отображает главное меню."""
gs.custom_mode_active = False
gs.WIDTH, gs.HEIGHT = config_module.DEFAULT_WIDTH, config_module.DEFAULT_HEIGHT
gs.update_display_mode()
buttons = []
available_lengths = sorted([length for length, words in gs.WORD_SETS.items() if words])
btn_y_start, btn_spacing = 180, 70
running = True
while running:
draw_gradient_background(gs.screen, gs.WIDTH, gs.HEIGHT,
config_module.COLORS['MENU_BG_GRAD1'],
config_module.COLORS['MENU_BG_GRAD2'])
draw_text_centered(gs.screen, "Выберите сложность", gs.get_font('main'),
config_module.COLORS['BLACK'], gs.WIDTH // 2, 100)
buttons.clear()
displayed_btns = 0
for length in available_lengths:
if not (3 <= length <= 10) and (len(available_lengths) > 4 and not (4 <= length <= 7)):
continue
btn_text = f"{length} {decline_letters(length)} ({len(gs.WORD_SETS.get(length, []))} слов)"
rect = pygame.Rect(gs.WIDTH // 2 - 150, btn_y_start + displayed_btns * btn_spacing, 300, 50)
pygame.draw.rect(gs.screen, config_module.COLORS['GRAY'], rect, border_radius=12)
draw_text_centered(gs.screen, btn_text, gs.get_font('small'),
config_module.COLORS['BLACK'], rect.centerx, rect.centery)
buttons.append((rect, length))
displayed_btns += 1
if displayed_btns >= 5 and len(available_lengths) > 6:
break
custom_btn_rect = pygame.Rect(gs.WIDTH // 2 - 100, btn_y_start + displayed_btns * btn_spacing, 200, 50)
pygame.draw.rect(gs.screen, config_module.COLORS['GRAY'], custom_btn_rect, border_radius=12)
draw_text_centered(gs.screen, "Своя сложность", gs.get_font('custom_difficulty_button'),
config_module.COLORS['BLACK'], custom_btn_rect.centerx, custom_btn_rect.centery)
buttons.append((custom_btn_rect, 'custom'))
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
for rect, choice in buttons:
if rect.collidepoint(event.pos):
if choice == 'custom':
result = prompt_custom_difficulty_settings(gs, config_module)
if result is not None:
return result
elif isinstance(choice, int) and gs.WORD_SETS.get(choice):
return choice
Таким образом, строка, отображающая количество букв, автоматически подбирает правильную форму слова «буква».