This commit is contained in:
328p
2026-10-07 11:54:01 +03:00
parent d7c43ece7b
commit ad75ca6665
3 changed files with 111 additions and 1 deletions
+47
View File
@@ -0,0 +1,47 @@
# Лабораторная работа №5
* **Студент:** [Саженина Александра]
* **Вариант / Карточка:** [Классы и объекты в C#. Инкапсуляция, конструкторы, свойства и статические члены]
---
## Ключевой код
```csharp
public int Hp
{
get { return hp; }
set
{
if (value < 0) hp = 0;
else if (value > 100) hp = 100;
else hp = value;
}
}
//метод для покемона
public Pokemon(string name, int level, int hp)
{
this.Name = name;
this.Level = level;
this.Hp = hp;
}
//метод вызова
public void ShowInfo(int number)
{
Console.WriteLine($"{number}. Имя: {Name}, Уровень: {Level}, HP: {Hp}");
}
}
//создание покемонов и их вызов
class Program
{
static void Main(string[] args)
{
Pokemon pikachu = new Pokemon("Pikachu", 5, 100);
Pokemon squirtle = new Pokemon("squirtle", 7, 90);
pikachu.ShowInfo(1);
squirtle.ShowInfo(2);
}