python
import pygame
import sys
# --- Настройки ---
WIDTH, HEIGHT = 600, 700
FPS = 60
CELL_SIZE = 60
FONT_SIZE = 48
GUESSES = 6
WORD_LENGTH = 5
# Цвета
WHITE = (255, 255, 255)
GRAY = (120, 124, 126)
YELLOW = (201, 180, 88)
GREEN = (106, 170, 100)
BLACK = (0, 0, 0)
# Загаданное слово (можно выбрать случайное)
SECRET_WORD = 'мирок'
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Русский Wordle")
clock = pygame.time.Clock()
font = pygame.font.SysFont('Arial', FONT_SIZE)
small_font = pygame.font.SysFont('Arial', 24)
# Массив для ввода слов
user_guesses = ['' for _ in range(GUESSES)]
current_guess = 0
# функция для отрисовки ячеек
def draw_board():
screen.fill(WHITE)
for row in range(GUESSES):
for col in range(WORD_LENGTH):
x = (WIDTH - WORD_LENGTH * CELL_SIZE) // 2 + col * CELL_SIZE
y = 50 + row * CELL_SIZE
pygame.draw.rect(screen, GRAY, (x, y, CELL_SIZE, CELL_SIZE), 2)
if col < len(user_guesses[row]):
letter = user_guesses[row][col].upper()
guess_word = user_guesses[row]
color = GRAY
if len(guess_word) == WORD_LENGTH:
if SECRET_WORD[col] == guess_word[col]:
color = GREEN
elif guess_word[col] in SECRET_WORD:
color = YELLOW
pygame.draw.rect(screen, color, (x, y, CELL_SIZE, CELL_SIZE))
text = font.render(letter, True, BLACK)
text_rect = text.get_rect(center=(x + CELL_SIZE // 2, y + CELL_SIZE // 2))
screen.blit(text, text_rect)
# Вывод информации
info_text = small_font.render("Введите 5-буквенное слово на русском", True, BLACK)
screen.blit(info_text, (WIDTH//2 - info_text.get_width()//2, HEIGHT - 100))
# Основной цикл
running = True
while running:
clock.tick(FPS)
draw_board()
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Клавиатурный ввод
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_BACKSPACE:
user_guesses[current_guess] = user_guesses[current_guess][:-1]
elif event.key == pygame.K_RETURN:
if len(user_guesses[current_guess]) == WORD_LENGTH:
if user_guesses[current_guess] == SECRET_WORD:
print("Вы угадали!")
running = False
else:
current_guess += 1
if current_guess >= GUESSES:
print("Вы проиграли! Загаданное слово:", SECRET_WORD)
running = False
else:
char = event.unicode.lower()
if char.isalpha() and len(char) == 1 and ord(char) >= ord('а'):
if len(user_guesses[current_guess]) < WORD_LENGTH:
user_guesses[current_guess] += char
pygame.quit()
sys.exit()