Загрузка данных


# ==========================================================
# РОЛЬ 2 — Венчинский: Renderer
# ==========================================================
class Renderer:
    def draw_grid(self, surface):
        surface.fill(BG_COLOR)
        for x in range(0, WIDTH, CELL):
            pygame.draw.line(surface, GRID_COLOR, (x, 0), (x, HEIGHT))
        for y in range(0, HEIGHT, CELL):
            pygame.draw.line(surface, GRID_COLOR, (0, y), (WIDTH, y))

    def draw_snake(self, surface, body):
        """Нарисовать змейку. body[0] — голова."""
        # Подсказка 1: цикл по всем сегментам змейки
        for i, (col, row) in enumerate(body):
            # Подсказка 2: переводим координаты клеток в пиксели
            x = col * CELL
            y = row * CELL
            
            # Подсказка 3: голова отличается по цвету от тела
            color = SNAKE_HEAD_COLOR if i == 0 else SNAKE_COLOR
            
            # Подсказка 4: рисуем сегмент змейки
            pygame.draw.rect(surface, color, (x + 1, y + 1, CELL - 2, CELL - 2), border_radius=5)
            
            # Бонус: рисуем глазки на голове
            if i == 0:
                # Левый глаз
                eye_x1 = x + CELL // 4
                eye_y = y + CELL // 4
                pygame.draw.circle(surface, (0, 0, 0), (eye_x1, eye_y), 3)
                
                # Правый глаз
                eye_x2 = x + 3 * CELL // 4
                pygame.draw.circle(surface, (0, 0, 0), (eye_x2, eye_y), 3)
                
                # Блики в глазах (белые точки)
                pygame.draw.circle(surface, (255, 255, 255), (eye_x1 - 1, eye_y - 1), 1)
                pygame.draw.circle(surface, (255, 255, 255), (eye_x2 - 1, eye_y - 1), 1)

    def draw_score(self, surface, score):
        text = font.render(f"Счёт: {score}", True, TEXT_COLOR)
        surface.blit(text, (10, 10))

    def draw_game_over(self, surface, score):
        overlay = pygame.Surface((WIDTH, HEIGHT), pygame.SRCALPHA)
        overlay.fill((0, 0, 0, 180))
        surface.blit(overlay, (0, 0))

        text1 = big_font.render("GAME OVER", True, (220, 80, 80))
        text2 = font.render(f"Твой счёт: {score}", True, TEXT_COLOR)
        text3 = font.render("R — заново   |   ESC — выход", True, TEXT_COLOR)
        surface.blit(text1, text1.get_rect(center=(WIDTH // 2, HEIGHT // 2 - 50)))
        surface.blit(text2, text2.get_rect(center=(WIDTH // 2, HEIGHT // 2 + 10)))
        surface.blit(text3, text3.get_rect(center=(WIDTH // 2, HEIGHT // 2 + 50)))