{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e7c2d1c2",
   "metadata": {},
   "source": [
    "# 20-03 · Персонажи\n",
    "\n",
    "Практика к разделу [«Рисуем первые игровые объекты»](../../site/chapters/glava-20/20-03-personazhi.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f2cc977f",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Нарисовать персонажей простыми фигурами."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ffd95529",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d88ddef3",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T10:11:57.023846Z",
     "iopub.status.busy": "2026-09-03T10:11:57.023693Z",
     "iopub.status.idle": "2026-09-03T10:11:57.195731Z",
     "shell.execute_reply": "2026-09-03T10:11:57.194420Z"
    }
   },
   "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": "9232e160",
   "metadata": {},
   "source": [
    "## Проверка результата"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "07522bae",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T10:11:57.197824Z",
     "iopub.status.busy": "2026-09-03T10:11:57.197597Z",
     "iopub.status.idle": "2026-09-03T10:11:57.339782Z",
     "shell.execute_reply": "2026-09-03T10:11:57.339136Z"
    }
   },
   "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": "32fbc9d1",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Нарисуйте трёх врагов в ряд разными цветами."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e89c5ea8",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T10:11:57.341585Z",
     "iopub.status.busy": "2026-09-03T10:11:57.341387Z",
     "iopub.status.idle": "2026-09-03T10:11:57.479239Z",
     "shell.execute_reply": "2026-09-03T10:11:57.478540Z"
    }
   },
   "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
}
