Files
prog-belyaev/CSharp/lab-07/lab-07/Program.cs
T
2026-10-15 14:48:16 +03:00

166 lines
4.3 KiB
C#

class Program
{
static void Main(string[] args)
{
// Pokemon pika = new Pikachu("Пикачу", 5, 100);
// Pokemon squirtle = new Squirtle("Сквиртл", 7, 90);
// Pokemon charmander = new Charmander("Charmander", 9, 80);
Console.WriteLine("=== ЗАДАНИЕ 1 ===");
Console.WriteLine("=== ПОКЕДЕКС: АТАКИ ===\n");
List<Pokemon> pokemons = new List<Pokemon>(4)
{
new Pikachu("Пикачу", 5, 100),
new Squirtle("Сквиртл", 7, 90),
new Charmander("Чармандер", 9, 80),
new Bulbasaur("Бульбазавр", 6, 95)
};
foreach (Pokemon pokemon in pokemons)
{
pokemon.ShowInfo();
pokemon.Attack();
Console.WriteLine();
}
}
// class Pokemon
// {
// protected string name;
//
// protected int hp;
//
// protected int level;
//
// public int HP
// {
// get { return hp; }
// set
// {
// if (value < 0) hp = 0;
// else if (value > 100) hp = 100;
// else hp = value;
// }
// }
//
// public int Level
// {
// get { return level; }
// set
// {
// if (value < 1) level = 1;
// else if (value > 100) level = 100;
// else level = value;
// }
// }
//
// public string Name;
//
// public Pokemon(string name, int level, int hp)
// {
// this.Name = name == "" ? "Безымянный" : name;
// this.Level = level;
// this.HP = hp;
// }
//
// public abstract void Attack()
// {
// Console.WriteLine("Покемон аттакует");
// }
//
// public void ShowInfo()
// {
// Console.WriteLine($"Name: {Name}, Уровень: {Level}, HP: {HP}");
// }
// }
abstract class Pokemon
{
protected string name;
protected int hp;
protected int level;
public int HP
{
get { return hp; }
set
{
if (value < 0) hp = 0;
else if (value > 100) hp = 100;
else hp = value;
}
}
public int Level
{
get { return level; }
set
{
if (value < 1) level = 1;
else if (value > 100) level = 100;
else level = value;
}
}
public string Name;
public Pokemon(string name, int level, int hp)
{
this.Name = name == "" ? "Безымянный" : name;
this.Level = level;
this.HP = hp;
}
virtual public void Attack()
{
Console.WriteLine("Покемон аттакует");
}
public void ShowInfo()
{
Console.WriteLine($"Name: {Name}, Уровень: {Level}, HP: {HP}");
}
}
class Pikachu : Pokemon
{
public Pikachu(string name, int level, int hp) : base(name, level, hp)
{
}
public override void Attack()
{
Console.WriteLine($"{Name} бьёт током! Пика-пика!");
}
}
class Charmander : Pokemon
{
public Charmander(string name, int level, int hp) : base(name, level, hp)
{
}
public override void Attack()
{
Console.WriteLine($"{Name} Чар-чар! Огненный хвост!");
}
}
class Squirtle : Pokemon
{
public Squirtle(string name, int level, int hp) : base(name, level, hp)
{
}
public override void Attack()
{
Console.WriteLine($"{Name} Сквирт-сквирт! Водяной пистолет!");
}
}
class Bulbasaur : Pokemon
{
public Bulbasaur(string name, int level, int hp) : base(name, level, hp)
{
}
public override void Attack()
{
Console.WriteLine($"{Name} Бульба! Листовой удар!");
}
}
}