{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "31f3b322",
   "metadata": {},
   "source": [
    "# 14-09 · Mini-projekt: Player\n",
    "\n",
    "Praktyka do rozdziału [„Mini-projekt: Player”](/pl/chapters/rozdzial-14/14-09-mini-proekt-player.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6d1d744",
   "metadata": {},
   "source": [
    "## Cel\n",
    "\n",
    "Skonstruuj klasę Player z sprawdzonymi zmianami stanu."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae1aee60",
   "metadata": {},
   "source": [
    "## Sprawa robocza"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "34b54644",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Player:\n",
    "    def __init__(self, name, health=100):\n",
    "        self.name = name\n",
    "        self.health = health\n",
    "        self.score = 0\n",
    "\n",
    "    def take_damage(self, amount):\n",
    "        self.health -= amount\n",
    "        if self.health < 0:\n",
    "            self.health = 0\n",
    "\n",
    "    def heal(self, amount):\n",
    "        self.health += amount\n",
    "        if self.health > 100:\n",
    "            self.health = 100\n",
    "\n",
    "    def add_score(self, points):\n",
    "        self.score += points\n",
    "\n",
    "p = Player(\"Anna\")\n",
    "p.take_damage(30)\n",
    "p.add_score(15)\n",
    "print(p.health, p.score)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f0849725",
   "metadata": {},
   "source": [
    "## Zadanie niezależne od zadania ★★\n",
    "\n",
    "Dodaj `Player` metoda `is_alive()`który wraca `True`jeśli `health` większe niż 0."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1c83064",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Player:\n",
    "    def __init__(self, name, health=100):\n",
    "        self.name = name\n",
    "        self.health = health\n",
    "        self.score = 0\n",
    "\n",
    "    def take_damage(self, amount):\n",
    "        self.health -= amount\n",
    "        if self.health < 0:\n",
    "            self.health = 0\n",
    "\n",
    "    def heal(self, amount):\n",
    "        self.health += amount\n",
    "        if self.health > 100:\n",
    "            self.health = 100\n",
    "\n",
    "    def add_score(self, points):\n",
    "        self.score += points\n",
    "\n",
    "    def is_alive(self):\n",
    "        return self.health > 0\n",
    "\n",
    "p = Player(\"Anna\")\n",
    "p.take_damage(30)\n",
    "p.add_score(15)\n",
    "print(p.health, p.score, p.is_alive())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "language_info": {
   "name": "python",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
