{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5fa07f1f",
   "metadata": {},
   "source": [
    "# 20-26 · Architektura: klasa Game\n",
    "\n",
    "Praktyka do sekcji [„Architektura: klasa Game”](/pl/chapters/rozdzial-20/20-26-arhitektura-class-game.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "30761f2d",
   "metadata": {},
   "source": [
    "## Cel\n",
    "\n",
    "Złóż klasę minimalnej Game z handle_events/update/render metodami i upewnij się, że pauza zatrzymuje update()."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1551afbf",
   "metadata": {},
   "source": [
    "## Sprawa robocza"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c3e31960",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T10:12:23.457854Z",
     "iopub.status.busy": "2026-09-03T10:12:23.457664Z",
     "iopub.status.idle": "2026-09-03T10:12:23.650920Z",
     "shell.execute_reply": "2026-09-03T10:12:23.650429Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pygame-ce 2.5.8 (SDL 2.32.10, Python 3.14.6)\n",
      "Позиция после 30 кадров (игра идёт): 49.999999999999986\n"
     ]
    }
   ],
   "source": [
    "import pygame\n",
    "from enum import Enum, auto\n",
    "\n",
    "class Sostoyanie(Enum):\n",
    "    IGRA = auto()\n",
    "    PAUZA = auto()\n",
    "\n",
    "class MiniGame:\n",
    "    def __init__(self):\n",
    "        pygame.init()\n",
    "        self.screen = pygame.display.set_mode((600, 400))\n",
    "        self.state = Sostoyanie.IGRA\n",
    "        self.x = 0\n",
    "\n",
    "    def update(self, dt):\n",
    "        if self.state is not Sostoyanie.IGRA:\n",
    "            return\n",
    "        self.x += 100 * dt   # 100 пикселей в секунду\n",
    "\n",
    "    def render(self):\n",
    "        self.screen.fill((20, 20, 40))\n",
    "        pygame.draw.rect(self.screen, (255, 255, 255), (self.x, 180, 20, 20))\n",
    "        pygame.display.flip()\n",
    "\n",
    "igra = MiniGame()\n",
    "for _ in range(30):\n",
    "    igra.update(1 / 60)\n",
    "    igra.render()\n",
    "\n",
    "print(\"Позиция после 30 кадров (игра идёт):\", igra.x)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7bef7289",
   "metadata": {},
   "source": [
    "## Sprawdzenie wyniku"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8d8baf45",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T10:12:23.657580Z",
     "iopub.status.busy": "2026-09-03T10:12:23.657342Z",
     "iopub.status.idle": "2026-09-03T10:12:23.716922Z",
     "shell.execute_reply": "2026-09-03T10:12:23.715670Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Верно: на паузе update() не двигает объект, хотя render() продолжает вызываться.\n"
     ]
    }
   ],
   "source": [
    "assert igra.x > 0\n",
    "pozicziya_do_pauzy = igra.x\n",
    "\n",
    "igra.state = Sostoyanie.PAUZA\n",
    "for _ in range(30):\n",
    "    igra.update(1 / 60)\n",
    "    igra.render()\n",
    "\n",
    "assert igra.x == pozicziya_do_pauzy\n",
    "print(\"Верно: на паузе update() не двигает объект, хотя render() продолжает вызываться.\")"
   ]
  }
 ],
 "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
}
