generated from admin/template
Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -0,0 +1,125 @@
|
|||||||
|
namespace DefaultNamespace;
|
||||||
|
|
||||||
|
public class laba_7
|
||||||
|
using System;
|
||||||
|
|
||||||
|
class Pokemon
|
||||||
|
{
|
||||||
|
protected string name;
|
||||||
|
protected int level;
|
||||||
|
protected int hp;
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get => name;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(value))
|
||||||
|
throw new ArgumentException("Имя покемона не может быть пустым.");
|
||||||
|
|
||||||
|
name = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Level
|
||||||
|
{
|
||||||
|
get => level;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value <= 0)
|
||||||
|
throw new ArgumentOutOfRangeException(
|
||||||
|
nameof(Level), "Уровень должен быть больше нуля.");
|
||||||
|
|
||||||
|
level = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int HP
|
||||||
|
{
|
||||||
|
get => hp;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(
|
||||||
|
nameof(HP), "Количество HP не может быть отрицательным.");
|
||||||
|
|
||||||
|
hp = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pokemon(string name, int level, int hp)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Level = level;
|
||||||
|
HP = hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Attack()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Покемон атакует!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowInfo()
|
||||||
|
{
|
||||||
|
Console.Write($"{Name} (Ур. {Level}): ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Pikachu : Pokemon
|
||||||
|
{
|
||||||
|
public Pikachu(string name, int level, int hp)
|
||||||
|
: base(name, level, hp)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Attack()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Пика-пика! Удар током!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Squirtle : Pokemon
|
||||||
|
{
|
||||||
|
public Squirtle(string name, int level, int hp)
|
||||||
|
: base(name, level, hp)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Attack()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Сквирт-сквирт! Водяной пистолет!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Charmander : Pokemon
|
||||||
|
{
|
||||||
|
public Charmander(string name, int level, int hp)
|
||||||
|
: base(name, level, hp)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Attack()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Чар-чар! Огненный хвост!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
Pokemon pikachu = new Pikachu("Пикачу", 5, 35);
|
||||||
|
Pokemon squirtle = new Squirtle("Сквиртл", 7, 44);
|
||||||
|
Pokemon charmander = new Charmander("Чармандер", 6, 39);
|
||||||
|
|
||||||
|
Pokemon[] pokemons = { pikachu, squirtle, charmander };
|
||||||
|
|
||||||
|
Console.WriteLine("=== ПОКЕДЕКС: АТАКИ ===");
|
||||||
|
|
||||||
|
foreach (Pokemon pokemon in pokemons)
|
||||||
|
{
|
||||||
|
pokemon.ShowInfo();
|
||||||
|
pokemon.Attack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user