{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "31f3b322",
   "metadata": {},
   "source": [
    "# 14-09 · Мини-проект: Player\n",
    "\n",
    "Практика к разделу [«Мини-проект: Player»](../../site/chapters/glava-14/14-09-mini-proekt-player.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6d1d744",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Собрать класс Player с проверенными изменениями состояния."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae1aee60",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "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": [
    "## Задание ★★ Самостоятельная задача\n",
    "\n",
    "Добавьте классу `Player` метод `is_alive()`, возвращающий `True`, если `health` больше 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
}
