{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cc093325",
   "metadata": {},
   "source": [
    "# 20-03 · Персонажи\n",
    "\n",
    "Практика к разделу [«Создаём персонажей на экране»](../../site/chapters/glava-20/20-03-personazhi.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "af12f3cc",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Нарисовать персонажей простыми фигурами."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bc4bbcac",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ddceaa7c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:59:22.772465Z",
     "iopub.status.busy": "2026-08-14T20:59:22.772299Z",
     "iopub.status.idle": "2026-08-14T20:59:22.952273Z",
     "shell.execute_reply": "2026-08-14T20:59:22.951456Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pygame-ce 2.5.8 (SDL 2.32.10, Python 3.14.6)\n",
      "Цвет в центре игрока: Color(100, 200, 255, 255)\n",
      "Цвет в центре врага: Color(255, 80, 80, 255)\n"
     ]
    }
   ],
   "source": [
    "import pygame\n",
    "\n",
    "pygame.init()\n",
    "screen = pygame.display.set_mode((600, 400))\n",
    "\n",
    "CVET_IGROKA = (100, 200, 255)\n",
    "CVET_VRAGA = (255, 80, 80)\n",
    "\n",
    "x_igroka, y_igroka = 300, 350\n",
    "x_vraga, y_vraga = 300, 50\n",
    "\n",
    "screen.fill((0, 0, 0))\n",
    "pygame.draw.rect(screen, CVET_IGROKA, (x_igroka, y_igroka, 40, 40))\n",
    "pygame.draw.circle(screen, CVET_VRAGA, (x_vraga, y_vraga), 20)\n",
    "pygame.display.flip()\n",
    "\n",
    "print(\"Цвет в центре игрока:\", screen.get_at((x_igroka + 20, y_igroka + 20)))\n",
    "print(\"Цвет в центре врага:\", screen.get_at((x_vraga, y_vraga)))\n",
    "pygame.quit()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "059c12e8",
   "metadata": {},
   "source": [
    "## Проверка результата"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c5d16aa0",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:59:22.953952Z",
     "iopub.status.busy": "2026-08-14T20:59:22.953765Z",
     "iopub.status.idle": "2026-08-14T20:59:23.085324Z",
     "shell.execute_reply": "2026-08-14T20:59:23.084718Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Верно: прямоугольник игрока нарисован правильным цветом.\n"
     ]
    }
   ],
   "source": [
    "import pygame\n",
    "\n",
    "pygame.init()\n",
    "screen = pygame.display.set_mode((600, 400))\n",
    "screen.fill((0, 0, 0))\n",
    "pygame.draw.rect(screen, (100, 200, 255), (300, 350, 40, 40))\n",
    "pygame.display.flip()\n",
    "\n",
    "assert screen.get_at((320, 370))[:3] == (100, 200, 255)\n",
    "print(\"Верно: прямоугольник игрока нарисован правильным цветом.\")\n",
    "pygame.quit()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0e852b6a",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Нарисуйте трёх врагов в ряд разными цветами."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ac60e948",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:59:23.086712Z",
     "iopub.status.busy": "2026-08-14T20:59:23.086536Z",
     "iopub.status.idle": "2026-08-14T20:59:23.223262Z",
     "shell.execute_reply": "2026-08-14T20:59:23.222581Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Три врага нарисованы.\n"
     ]
    }
   ],
   "source": [
    "import pygame\n",
    "\n",
    "pygame.init()\n",
    "screen = pygame.display.set_mode((600, 400))\n",
    "screen.fill((0, 0, 0))\n",
    "\n",
    "cveta = [(255, 0, 0), (0, 255, 0), (0, 0, 255)]\n",
    "for i, cvet in enumerate(cveta):\n",
    "    pygame.draw.circle(screen, cvet, (150 + i * 150, 100), 20)\n",
    "\n",
    "pygame.display.flip()\n",
    "print(\"Три врага нарисованы.\")\n",
    "pygame.quit()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
