лаба номер 6, задание второе

This commit is contained in:
2026-10-09 11:17:14 +03:00
parent 974bb5ecbf
commit 2f6ee181b6
+29 -9
View File
@@ -5,10 +5,14 @@ public class two_ex
static void Main(string[] args) static void Main(string[] args)
{ {
Pokemon pikachu = new Pokemon(100, 5, "Пикачу"); Pokemon pikachu = new Pokemon(100, 5, "Пикачу");
Pokemon sqr = new Pokemon(90, 7, "Сквиртл"); pikachu.HP = 100;
Console.WriteLine(pikachu.HP);
pikachu.ShowInfo(); pikachu.TakeDamage(30);
sqr.ShowInfo(); Console.WriteLine(pikachu.HP);
pikachu.Heal();
Console.WriteLine(pikachu.HP);
Pokemon egg = new Pokemon();
Console.WriteLine(egg.HP+" "+egg.Level+" "+egg.Name);
} }
} }
@@ -55,17 +59,20 @@ class Pokemon
} }
public void Heal()
{
hp = 100;
}
public Pokemon(int hp, int level, string name) public Pokemon(int hp, int level, string name)
{ {
this.name = name; this.name = name;
this.level = level; this.level = level;
this.hp = hp; this.hp = hp;
} }
public void ShowInfo()
{
Console.WriteLine($"HP: {this.HP}, Level: {this.Level}, Name: {this.Name}");
}
public int TakeDamage(int damage) public int TakeDamage(int damage)
{ {
@@ -73,6 +80,19 @@ class Pokemon
if (hp <= 0) return 0; if (hp <= 0) return 0;
return this.hp; return this.hp;
} }
public Pokemon()
{
Name = "Яйцо";
Level = 1;
hp = 100;
}
} }