This commit is contained in:
gcn
2026-11-25 16:00:02 +03:00
parent 49d0a17ec4
commit bc9b5d33b5
2 changed files with 456 additions and 27 deletions
+456 -24
View File
@@ -1,34 +1,466 @@
class Pokemon
//ЗАДАНИЕ 11111111111111111111111
// class Program
// {
// static void Main()
// {
// Console.WriteLine("=== ЗАДАНИЕ 1 ===");
// Console.WriteLine("=== ПОКЕДЕКС: АТАКИ ===");
// Pokemon pika = new Pikachu("Пикачу", 5);
// pika.ShowInfo();
// Pokemon squirtle = new Squirtle("Сквиртл", 7);
// squirtle.ShowInfo();
// Pokemon charmander = new Charmander("Бульбазавр", 6);
// charmander.ShowInfo();
//
// Console.WriteLine("=== ЗАДАНИЕ 2 ===");
// Console.WriteLine("=== ТУРНИР: ВСЕ ПРОТИВ ВСЕХ ===");
// pika.ShowInfo();
// squirtle.ShowInfo();
// charmander.ShowInfo();
//
// }
//
// public class Pokemon
// {
//
// private string name;
// private int level;
//
// public string Name
// {
// get { return name; }
// set
// {
// if (string.IsNullOrWhiteSpace(value))
// {
// name = "Безымянный";
// }
// else
// {
// name = value;
// }
// }
// }
//
// public int Level
// {
// get { return level; }
// set
// {
// if (value < 1) level = 1;
// else if (value > 100) level = 100;
// else level = value;
// }
// }
//
//
// public Pokemon(string name, int level)
// {
// Name = name;
// Level = level;
// }
//
// public virtual void Attack()
// {
// Console.WriteLine($"Покемон{Name} атакует.");
// }
//
// public virtual void ShowInfo()
// {
// Console.WriteLine($"{name} (Ур.{level})");
// }
//
// }
//
// public class Pikachu : Pokemon
// {
// public Pikachu(string name, int level) : base(name, level) { }
//
// public override void Attack()
// {
// Console.WriteLine("Пика-пика! Удар током!");
// }
// public override void ShowInfo()
// {
// Console.WriteLine("Пикачу (Ур. " + Level + "): Пика-пика! Удар током!");
// }
//
// }
// public class Squirtle : Pokemon // наследник2
// {
// public Squirtle (string name, int level) : base(name, level)
// {}
// public override void Attack()
// {
// Console.WriteLine("Сквирт-сквирт! Водяной пистолет!");
// }
// public override void ShowInfo()
// {
// Console.WriteLine("Сквиртл (Ур. " + Level + "): Сквирт-сквиртл! Водяной пистолет!");
//
//
// }
// }
//
// public class Charmander : Pokemon // наследник3
// {
// public Charmander(string name, int level) : base(name, level)
// {
//
// }
//
// public override void Attack()
// {
// Console.WriteLine("Чар-чар! Огненный хвост!");
// }
//
// public override void ShowInfo()
// {
// Console.WriteLine("Чармандер (Ур. " + Level + "): Чар-чар! Огненный хвост!");
// }
// }
// }
//ЗАДАНИЕ 222222222222222222222
// class Program
// {
// static void Main()
// {
// Console.WriteLine("=== ЗАДАНИЕ 2 ===");
// Console.WriteLine("=== ТУРНИР: ВСЕ ПРОТИВ ВСЕХ ===");
//
// // Эту строку нельзя раскомментировать!
// // Pokemon p = new Pokemon("Тест", 1);
// // Ошибка: нельзя создать объект абстрактного класса.
//
//
// Pokemon[] pokemons = new Pokemon[4];
// pokemons[0] = new Pikachu("Пикачу", 5);
// pokemons[1] = new Squirtle("Сквиртл", 7);
// pokemons[2] = new Charmander("Чармандер", 6);
// pokemons[3] = new Bulbasaur("Бульбазавр", 4);
//
// Console.WriteLine($"Всего покемонов: {pokemons.Length}");
// Console.WriteLine();
//
// Console.WriteLine("--- Раунд 1 ---");
//
// foreach (Pokemon pokemon in pokemons)
// {
// pokemon.ShowInfo();
// pokemon.Attack();
// }
//
// Console.WriteLine($"\nВсего атак проведено: {Pokemon.TotalAttacks}");
//
// }
// }
// abstract class Pokemon
// {
//
// private string name;
// private int level;
// public static int TotalAttacks = 0;
// public string Name
// {
// get { return name; }
// set
// {
// if (string.IsNullOrWhiteSpace(value))
// {
// name = "Безымянный";
// }
// else
// {
// name = value;
// }
// }
// }
//
// public int Level
// {
// get { return level; }
// set
// {
// if (value < 1) level = 1;
// else if (value > 100) level = 100;
// else level = value;
// }
// }
//
//
// public Pokemon(string name, int level)
// {
// Name = name;
// Level = level;
// }
//
// public abstract void Attack();
//
//
// public virtual void ShowInfo()
// {
// Console.WriteLine($"{name} (Ур.{level})");
// }
//
// }
//
// class Pikachu : Pokemon
// {
// public Pikachu(string name, int level) : base(name, level) { }
//
// public override void Attack()
// {
// TotalAttacks++;
// Console.WriteLine("Пика-пика! Удар током!");
// }
// public override void ShowInfo()
// {
// Console.WriteLine("Пикачу (Ур. " + Level + "): Пика-пика! Удар током!");
// }
//
// }
// class Squirtle : Pokemon // наследник2
// {
// public Squirtle (string name, int level) : base(name, level)
// {}
// public override void Attack()
// {
// TotalAttacks++;
// Console.WriteLine("Сквирт-сквирт! Водяной пистолет!");
// }
// public override void ShowInfo()
// {
// Console.WriteLine("Сквиртл (Ур. " + Level + "): Сквирт-сквиртл! Водяной пистолет!");
//
//
// }
// }
//
// class Charmander : Pokemon // наследник3
// {
// public Charmander(string name, int level) : base(name, level)
// {
//
// }
//
// public override void Attack()
// {
// TotalAttacks++;
// Console.WriteLine("Чар-чар! Огненный хвост!");
// }
//
// public override void ShowInfo()
// {
// Console.WriteLine("Чармандер (Ур. " + Level + "): Чар-чар! Огненный хвост!");
// }
// }
// class Bulbasaur : Pokemon // наследник3
// {
// public Bulbasaur (string name, int level) : base(name, level)
// {
//
// }
//
// public override void Attack()
// {
// TotalAttacks++;
// Console.WriteLine("Бульба! Листовой удар!");
// }
//
// public override void ShowInfo()
// {
// Console.WriteLine("Бульбазавр (Ур. " + Level + "): Бульба! Листовой удар!");
// }
// }
//ЗАДАНИЕ 333333333333333333333333333333333
class Program
{
public string Name;
public int Level;
public int HP;
public int HP
static void Main()
{
get { return hp; }
set
Console.WriteLine("=== ЗАДАНИЕ 3 ===");
Console.WriteLine("=== СПОСОБНОСТИ ПОКЕМОНОВ ===");
Pokemon[] pokemons = new Pokemon[3];
pokemons[0] = new Magikarp("Магикарп", 5);
pokemons[1] = new Pidgeotto("Пиджеотто", 7);
pokemons[2] = new Charmander("Чармандер", 6);
int canEvolve = 0;
int canFly = 0;
foreach (Pokemon p in pokemons)
{
if (value < 0) hp = 0;
else if (value > 100) hp = 100;
else hp = value;
p.ShowInfo();
if (p is IEvolvable) canEvolve++;
if (p is IFlyable) canFly++;
}
foreach (Pokemon p in pokemons)
{
if (p is IEvolvable evolvable)
{
evolvable.Evolve();
}
if (p is IFlyable flyable)
{
flyable.Fly();
}
if (p is Magikarp)
{
Console.WriteLine("Магикарп ничего не умеет, кроме Splash.");
}
Console.WriteLine();
Console.WriteLine("Итого:");
Console.WriteLine($"Эволюционируют: {canEvolve}");
Console.WriteLine($"Летают: {canFly}");
}
}
interface IEvolvable
{
void Evolve();
}
interface IFlyable
{
void Fly();
}
public class Pokemon
{
private string name;
private int level;
public string Name
{
get { return name; }
set
{
if (string.IsNullOrWhiteSpace(value))
{
name = "Безымянный";
}
else
{
name = value;
}
}
}
public int Level
{
get { return level; }
set
{
if (value < 1) level = 1;
else if (value > 100) level = 100;
else level = value;
}
}
public Pokemon(string name, int level)
{
Name = name;
Level = level;
}
public virtual void Attack()
{
Console.WriteLine("Покемон атакует!");
}
public virtual void ShowInfo()
{
Console.WriteLine($"{Name} (Ур. {Level}) умеет: атаковать");
}
}
public class Magikarp : Pokemon
{
public Magikarp(string name, int level) : base(name, level)
{
}
public override void Attack()
{
Console.WriteLine("Плеск! Splash!");
}
// Ничего не реализует — и это нормально
public override void ShowInfo()
{
Console.WriteLine($"{Name} (Ур. {Level}) умеет: только атаковать (пока что...)");
}
}
public class Pidgeotto : Pokemon, IFlyable, IEvolvable // наследник2
{
public Pidgeotto(string name, int level) : base(name, level)
{
}
public override void Attack()
{
Console.WriteLine("Вжух! Порыв ветра!");
}
public void Fly()
{
Console.WriteLine($"{Name} взлетает!");
}
public void Evolve()
{
Console.WriteLine($"{Name} эволюционирует!");
}
public override void ShowInfo()
{
Console.WriteLine($"{Name} (Ур. {Level}) умеет: атаковать, летать, эволюционировать");
}
}
public class Charmander : Pokemon, IEvolvable // наследник3
{
public Charmander(string name, int level) : base(name, level)
{
}
public override void Attack()
{
Console.WriteLine("Чар-чар! Огненный хвост!");
}
public override void ShowInfo()
{
Console.WriteLine("Чармандер (Ур. " + Level + "): Чар-чар! Огненный хвост!");
}
public void Fly()
{
Console.WriteLine(" -> Бульбазавр взлетает на лозах!");
}
public void Evolve()
{
Console.WriteLine("\n -> Бульбазавр готовится к эволюции!");
}
}
}
class Pikachu : Pokemon
{
public Pikachu(string name, int level) : base(name, level)
{
// тут можно добавить что-то своё
}
}
Console.WriteLine("=== ТУРНИР: ВСЕ ПРОТИВ ВСЕХ ===");
abstract class Pokemon
{
public abstract void Attack();
}