Files

401 lines
9.9 KiB
Plaintext

ЗАДАНИЕ №1
using System;
namespace PokemonHierarchy
{
public class Pokemon
{
protected string name;
protected int level;
protected int hp;
public string Name
{
get => name;
set => name = string.IsNullOrWhiteSpace(value) ? "Неизвестный покемон" : value;
}
public int Level
{
get => level;
set => level = value < 1 ? 1 : value;
}
public int HP
{
get => hp;
set => hp = value < 0 ? 0 : value;
}
public Pokemon(string name, int level, int hp)
{
Name = name;
Level = level;
HP = hp;
}
public virtual void Attack()
{
Console.WriteLine($"{Name} атакует базовой атакой!");
}
public void ShowInfo()
{
Console.Write($"{Name} (Ур. {Level}): ");
}
}
public class Pikachu : Pokemon
{
public Pikachu(int level, int hp) : base("Пикачу", level, hp) { }
public override void Attack()
{
Console.WriteLine("Пика-пика! Удар током!");
}
}
public class Wartortle : Pokemon
{
public Wartortle(int level, int hp) : base("Вартотл", level, hp) { }
public override void Attack()
{
Console.WriteLine("Вар-вар! Водомет!");
}
}
public class Bulbasaur : Pokemon
{
public Bulbasaur(int level, int hp) : base("Бульбазавр", level, hp) { }
public override void Attack()
{
Console.WriteLine("Бульба-бульба! Режущие листья!");
}
}
class Program
{
static void Main(string[] args)
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
Pokemon pikachu = new Pikachu(5, 45);
Pokemon wartortle = new Wartortle(16, 59);
Pokemon bulbasaur = new Bulbasaur(6, 45);
Console.WriteLine("=== ПОКЕДЕКС: АТАКИ ===");
pikachu.ShowInfo();
pikachu.Attack();
wartortle.ShowInfo();
wartortle.Attack();
bulbasaur.ShowInfo();
bulbasaur.Attack();
Console.ReadLine();
}
}
}
ЗАДАНИЕ №2
using System;
using System.Collections.Generic;
namespace PokemonTournament
{
public abstract class Pokemon
{
protected string name;
protected int level;
protected int hp;
private static int totalAttacksCount = 0;
public static int TotalAttacksCount => totalAttacksCount;
public string Name
{
get => name;
set => name = string.IsNullOrWhiteSpace(value) ? "Неизвестный покемон" : value;
}
public int Level
{
get => level;
set => level = value < 1 ? 1 : value;
}
public int HP
{
get => hp;
set => hp = value < 0 ? 0 : value;
}
public Pokemon(string name, int level, int hp)
{
Name = name;
Level = level;
HP = hp;
}
public abstract void Attack();
public void ShowInfo()
{
Console.Write($"{Name} (Ур. {Level}): ");
}
protected static void RegisterAttack()
{
totalAttacksCount++;
}
}
public class Pikachu : Pokemon
{
public Pikachu(int level, int hp) : base("Пикачу", level, hp) { }
public override void Attack()
{
Console.WriteLine("Пика-пика! Удар током!");
}
}
public class Wartortle : Pokemon
{
public Wartortle(int level, int hp) : base("Вартотл", level, hp) { }
public override void Attack()
{
RegisterAttack();
Console.WriteLine("Вар-вар! Водомет высокого давления!");
}
}
public class Bulbasaur : Pokemon
{
public Bulbasaur(int level, int hp) : base("Бульбазавр", level, hp) { }
public override void Attack()
{
RegisterAttack();
Console.WriteLine("Бульба! Листовой удар!");
}
}
public class Psyduck : Pokemon
{
public Psyduck(int level, int hp) : base("Псайдак", level, hp) { }
public override void Attack()
{
RegisterAttack();
Console.WriteLine("Псай-псай... Ментальный взрыв!");
}
}
class Program
{
static void Main(string[] args)
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
List<Pokemon> tournamentParticipants = new List<Pokemon>
{
new Pikachu(5, 45),
new Wartortle(16, 59),
new Bulbasaur(4, 45),
new Psyduck(8, 50)
};
Console.WriteLine("=== ТУРНИР: ВСЕ ПРОТИВ ВСЕХ ===");
Console.WriteLine($"Всего покемонов: {tournamentParticipants.Count}");
Console.WriteLine();
Console.WriteLine("--- Раунд 1 ---");
foreach (Pokemon pokemon in tournamentParticipants)
{
pokemon.ShowInfo();
pokemon.Attack();
}
Console.WriteLine();
Console.WriteLine($"Всего атак проведено: {Pokemon.TotalAttacksCount}");
Console.ReadLine();
}
}
}
ЗАДАНИЕ №3
using System;
using System.Collections.Generic;
namespace PokemonInterfaces
{
public interface IEvolvable
{
void Evolve();
}
public interface IFlyable
{
void Fly();
}
public abstract class Pokemon
{
protected string name;
protected int level;
protected int hp;
public string Name { get => name; set => name = value; }
public int Level { get => level; set => level = value; }
public int HP { get => hp; set => hp = value; }
public Pokemon(string name, int level, int hp)
{
Name = name;
Level = level;
HP = hp;
}
public abstract void Attack();
public void ShowInfo()
{
Console.Write($"{Name} (Ур. {Level})");
}
}
public class Charmander : Pokemon, IEvolvable
{
public Charmander(int level, int hp) : base("Чармандер", level, hp) { }
public override void Attack()
{
Console.WriteLine("Чар-чар! Огненный хвост!");
}
public void Evolve()
{
Console.WriteLine("Чармандер эволюционирует!");
}
}
public class Pidgeotto : Pokemon, IFlyable, IEvolvable
{
public Pidgeotto(int level, int hp) : base("Пиджеотто", level, hp) { }
public override void Attack()
{
Console.WriteLine("Пидж! Стальные крылья!");
}
public void Fly()
{
Console.WriteLine("Пиджеотто взлетает!");
}
public void Evolve()
{
Console.WriteLine("Пиджеотто эволюционирует!");
}
}
public class Magikarp : Pokemon
{
public Magikarp(int level, int hp) : base("Магикарп", level, hp) { }
public override void Attack()
{
Console.WriteLine("Маги-маги... Сплеш!");
}
}
class Program
{
static void Main(string[] args)
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
List<Pokemon> pokedex = new List<Pokemon>
{
new Charmander(6, 39),
new Pidgeotto(9, 63),
new Magikarp(3, 20)
};
Console.WriteLine("=== СПОСОБНОСТИ ПОКЕМОНОВ ===\n");
foreach (var pokemon in pokedex)
{
pokemon.ShowInfo();
List<string> skills = new List<string> { "атаковать" };
if (pokemon is IFlyable) skills.Add("летать");
if (pokemon is IEvolvable) skills.Add("эволюционировать");
if (skills.Count == 1)
{
Console.WriteLine(" умеет: только атаковать");
}
else
{
Console.WriteLine($" умеет: {string.Join(", ", skills)}");
}
}
Console.WriteLine("\n--- Проверка способностей ---");
int evolvableCount = 0;
int flyableCount = 0;
foreach (var pokemon in pokedex)
{
bool hasSpecialSkills = false;
if (pokemon is IFlyable flyable)
{
flyable.Fly();
flyableCount++;
hasSpecialSkills = true;
}
if (pokemon is IEvolvable evolvable)
{
evolvable.Evolve();
evolvableCount++;
hasSpecialSkills = true;
}
if (!hasSpecialSkills)
{
Console.WriteLine($"{pokemon.Name} ничего не умеет, кроме Splash.");
}
}
Console.WriteLine("\nИтого:");
Console.WriteLine($"Эволюционируют: {evolvableCount}");
Console.WriteLine($"Летают: {flyableCount}");
Console.ReadLine();
}
}
}