From 902bf7aa2251b954f531db8443743053a7a7bcd4 Mon Sep 17 00:00:00 2001 From: AntonKat <9+antonkat@noreply.localhost> Date: Mon, 23 Nov 2026 06:49:03 +0000 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20=C2=AB?= =?UTF-8?q?/=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Laba8Task1-2.kt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Laba8Task1-2.kt diff --git a/Laba8Task1-2.kt b/Laba8Task1-2.kt new file mode 100644 index 0000000..b1abf8c --- /dev/null +++ b/Laba8Task1-2.kt @@ -0,0 +1,29 @@ +class PokemonTask1(val name: String, var hp: Int) { + fun isAlive(): Boolean = hp > 0 + fun takeDamage(amount: Int) { + hp -= amount + } +} + +fun main() { + // Задание 1 + val pikachu = PokemonTask1("Pikachu", 100) + println(pikachu) + + pikachu.takeDamage(30) + println("HP: ${pikachu.hp}, жив: ${pikachu.isAlive()}") + + pikachu.takeDamage(80) + println("HP: ${pikachu.hp}, жив: ${pikachu.isAlive()}") + + // Задание 2 + pikachu.hp = 50 + + // pikachu.name = "Raichu" + + + // pikachu = PokemonTask1("Raichu", 100) + + val team = mutableListOf() + team.add(pikachu) // Компилируется! Мы меняем содержимое списка, а не саму ссылку team +}