generated from admin/template
lul
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{74627BD7-88A5-4E5C-8652-021FE2E2CEA2}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{74627BD7-88A5-4E5C-8652-021FE2E2CEA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{74627BD7-88A5-4E5C-8652-021FE2E2CEA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{74627BD7-88A5-4E5C-8652-021FE2E2CEA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{74627BD7-88A5-4E5C-8652-021FE2E2CEA2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Console.WriteLine("Hello, World!");
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp2", "ConsoleApp2\ConsoleApp2.csproj", "{0FF0DB59-0521-4E46-8BDB-1A1EF5411896}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{0FF0DB59-0521-4E46-8BDB-1A1EF5411896}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{0FF0DB59-0521-4E46-8BDB-1A1EF5411896}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{0FF0DB59-0521-4E46-8BDB-1A1EF5411896}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0FF0DB59-0521-4E46-8BDB-1A1EF5411896}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,271 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace PokemonInheritanceApp
|
||||||
|
{
|
||||||
|
// =========================================================================
|
||||||
|
// ЧАСТЬ 3. ИНТЕРФЕЙСЫ (КОНТРАКТЫ СПОСОБНОСТЕЙ)
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
|
// Интерфейс-способность эволюционировать
|
||||||
|
public interface IEvolvable
|
||||||
|
{
|
||||||
|
void Evolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Интерфейс-способность летать
|
||||||
|
public interface IFlyable
|
||||||
|
{
|
||||||
|
void Fly();
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// ЧАСТЬ 2. АБСТРАКТНЫЙ БАЗОВЫЙ КЛАСС (КАРКАС РОДСТВА)
|
||||||
|
// =========================================================================
|
||||||
|
public abstract class Pokemon
|
||||||
|
{
|
||||||
|
// Статическое поле для подсчета атак во всех раундах турнира (Задание 2)
|
||||||
|
private static int _totalAttacksCount = 0;
|
||||||
|
public static int TotalAttacksCount => _totalAttacksCount;
|
||||||
|
|
||||||
|
// Поля с модификатором protected — видны только внутри этого класса и его наследникам
|
||||||
|
protected string name;
|
||||||
|
protected int level;
|
||||||
|
protected int hp;
|
||||||
|
|
||||||
|
// Публичные свойства с инкапсуляцией и валидацией (как в Лабе 6)
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get => name;
|
||||||
|
set => name = string.IsNullOrWhiteSpace(value) ? "Дикий покемон" : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Level
|
||||||
|
{
|
||||||
|
get => level;
|
||||||
|
set => level = (value < 1 || value > 100) ? 1 : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int HP
|
||||||
|
{
|
||||||
|
get => hp;
|
||||||
|
set => hp = (value < 0) ? 0 : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Конструктор базового класса
|
||||||
|
protected Pokemon(string name, int level, int hp)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Level = level;
|
||||||
|
HP = hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обычный (невиртуальный) метод — работает одинаково для всех наследников
|
||||||
|
public void ShowInfo()
|
||||||
|
{
|
||||||
|
Console.Write(\$"{Name} (Ур. {Level}, HP: {HP})");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Абстрактный метод (Задание 2) — не имеет тела.
|
||||||
|
// Базовый класс гарантирует, что у КАЖДОГО покемона есть атака,
|
||||||
|
// но КАК атаковать — наследники РЕШАЮТ САМИ.
|
||||||
|
public abstract void Attack();
|
||||||
|
|
||||||
|
// Вспомогательный метод для инкремента общего счетчика атак
|
||||||
|
protected void RegisterAttack()
|
||||||
|
{
|
||||||
|
_totalAttacksCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// ЧАСТЬ 1 & 2. КОНКРЕТНЫЕ КЛАССЫ-НАСЛЕДНИКИ
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
|
// Пикачу является Покемоном. Умеет атаковать.
|
||||||
|
public class Pikachu : Pokemon
|
||||||
|
{
|
||||||
|
// Вызов конструктора базового класса через `: base(...)`
|
||||||
|
public Pikachu(string name, int level, int hp) : base(name, level, hp) { }
|
||||||
|
|
||||||
|
// Реализация абстрактного метода через `override`
|
||||||
|
public override void Attack()
|
||||||
|
{
|
||||||
|
RegisterAttack();
|
||||||
|
Console.WriteLine(\$": Пика-пика! Молниеносный удар током (ThunderShock)!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Сквиртл является Покемоном. Умеет атаковать.
|
||||||
|
public class Squirtle : Pokemon
|
||||||
|
{
|
||||||
|
public Squirtle(string name, int level, int hp) : base(name, level, hp) { }
|
||||||
|
|
||||||
|
public override void Attack()
|
||||||
|
{
|
||||||
|
RegisterAttack();
|
||||||
|
Console.WriteLine(\$": Сквирт-сквирт! Струя воды под давлением (Water Gun)!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Чармандер является Покемоном. Умеет атаковать и УМЕЕТ эволюционировать.
|
||||||
|
public class Charmander : Pokemon, IEvolvable
|
||||||
|
{
|
||||||
|
public Charmander(string name, int level, int hp) : base(name, level, hp) { }
|
||||||
|
|
||||||
|
public override void Attack()
|
||||||
|
{
|
||||||
|
RegisterAttack();
|
||||||
|
Console.WriteLine(\$": Чар-чар! Огненный вихрь из хвоста (Flame Burst)!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация интерфейса IEvolvable
|
||||||
|
public void Evolve()
|
||||||
|
{
|
||||||
|
Console.WriteLine(\$"🔥 {Name} окутывается пламенем и эволюционирует в Чармелеона!");
|
||||||
|
Name = "Чармелеон";
|
||||||
|
Level += 5;
|
||||||
|
HP += 30;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Пиджеотто является Покемоном. Умеет атаковать, ЛЕТАТЬ и ЭВОЛЮЦИОНИРОВАТЬ.
|
||||||
|
public class Pidgeotto : Pokemon, IFlyable, IEvolvable
|
||||||
|
{
|
||||||
|
public Pidgeotto(string name, int level, int hp) : base(name, level, hp) { }
|
||||||
|
|
||||||
|
public override void Attack()
|
||||||
|
{
|
||||||
|
RegisterAttack();
|
||||||
|
Console.WriteLine(\$": Пиджеот! Мощный вихрь крыльями (Gust attack)!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация интерфейса IFlyable
|
||||||
|
public void Fly()
|
||||||
|
{
|
||||||
|
Console.WriteLine(\$"🦅 {Name} расправляет крылья и взмывает высоко в небо!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация интерфейса IEvolvable
|
||||||
|
public void Evolve()
|
||||||
|
{
|
||||||
|
Console.WriteLine(\$"✨ {Name} сияет ярким светом и эволюционирует в Пиджеота!");
|
||||||
|
Name = "Пиджеот";
|
||||||
|
Level += 7;
|
||||||
|
HP += 40;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Магикарп является Покемоном. Ничего дополнительного не умеет.
|
||||||
|
public class Magikarp : Pokemon
|
||||||
|
{
|
||||||
|
public Magikarp(string name, int level, int hp) : base(name, level, hp) { }
|
||||||
|
|
||||||
|
public override void Attack()
|
||||||
|
{
|
||||||
|
RegisterAttack();
|
||||||
|
Console.WriteLine(\$": Бесполезно плещется в воде (Splash)! Ничего не произошло...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// ТОЧКА ВХОДА ПРОГРАММЫ
|
||||||
|
// =========================================================================
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.OutputEncoding = System.Text.Encoding.UTF8;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------
|
||||||
|
// ЗАДАНIE 1. Проверка работы конструкторов и базового вызова
|
||||||
|
// -----------------------------------------------------------------
|
||||||
|
Console.WriteLine("=== ЗАДАНИЕ 1: ИНИЦИАЛИЗАЦИЯ И ОБЫЧНЫЕ ВЫЗОВЫ ===");
|
||||||
|
Pikachu pika = new Pikachu("Пикачу Райана", 5, 45);
|
||||||
|
pika.ShowInfo();
|
||||||
|
pika.Attack();
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------
|
||||||
|
// ЗАДАНIE 2. Абстракция и Полиморфизм (Один массив — разное поведение)
|
||||||
|
// -----------------------------------------------------------------
|
||||||
|
Console.WriteLine("=== ЗАДАНИЕ 2: ТУРНИР ПОКЕМОНОВ (ПОЛИМОРФИЗМ) ===");
|
||||||
|
|
||||||
|
// СТРОКА НИЖЕ НЕ КОМПИЛИРУЕТСЯ, так как класс Pokemon абстрактный:
|
||||||
|
// Pokemon abstractPikachu = new Pokemon("Абстрактный", 1, 10); // КРИТИЧЕСКАЯ ОШИБКА COMPILER С#
|
||||||
|
|
||||||
|
// Создаем полиморфный список (коллекцию базового типа Pokemon)
|
||||||
|
List<Pokemon> tournamentBracket = new List<Pokemon>
|
||||||
|
{
|
||||||
|
new Pikachu("Пикачу", 12, 60),
|
||||||
|
new Squirtle("Сквиртл", 10, 55),
|
||||||
|
new Charmander("Чармандер", 15, 70),
|
||||||
|
new Pidgeotto("Пиджеотто", 18, 85)
|
||||||
|
};
|
||||||
|
|
||||||
|
Console.WriteLine(\$"Всего участников в сетке: {tournamentBracket.Count}\n");
|
||||||
|
Console.WriteLine("--- Раунд 1: Демонстрация всех атак ---");
|
||||||
|
|
||||||
|
foreach (Pokemon pokemon in tournamentBracket)
|
||||||
|
{
|
||||||
|
// Вызов общего метода сведений
|
||||||
|
pokemon.ShowInfo();
|
||||||
|
|
||||||
|
// ВАЖНО: Переменная имеет тип Pokemon, но благодаря полиморфизму
|
||||||
|
// среда выполнения (CLR) вызывает переопределенный метод (override) конкретного класса!
|
||||||
|
pokemon.Attack();
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine(\$"\nВсего атак проведено за турнир: {Pokemon.TotalAttacksCount}");
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------
|
||||||
|
// ЗАДАНIE 3. Интерфейсы и безопасная проверка способностей через `is`
|
||||||
|
// -----------------------------------------------------------------
|
||||||
|
Console.WriteLine("=== ЗАДАНИЕ 3: ПРОВЕРКА СПОСОБНОСТЕЙ (ИНТЕРФЕЙСЫ) ===");
|
||||||
|
|
||||||
|
// Добавим в наш список Магикарпа, который не умеет летать и расти
|
||||||
|
tournamentBracket.Add(new Magikarp("Магикарп", 5, 20));
|
||||||
|
|
||||||
|
int evolvableCount = 0;
|
||||||
|
int flyableCount = 0;
|
||||||
|
|
||||||
|
foreach (Pokemon pokemon in tournamentBracket)
|
||||||
|
{
|
||||||
|
Console.Write(\$"Покемон ");
|
||||||
|
pokemon.ShowInfo();
|
||||||
|
Console.WriteLine(" оценивается профессором:");
|
||||||
|
|
||||||
|
// Безопасное приведение типов (Pattern Matching с ключевым словом 'is')
|
||||||
|
// Если текущий 'pokemon' реализует интерфейс 'IEvolvable',
|
||||||
|
// переменная 'evolvable' мгновенно получает на него ссылку.
|
||||||
|
if (pokemon is IEvolvable evolvable)
|
||||||
|
{
|
||||||
|
evolvableCount++;
|
||||||
|
evolvable.Evolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pokemon is IFlyable flyable)
|
||||||
|
{
|
||||||
|
flyableCount++;
|
||||||
|
flyable.Fly();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Если покемон не унаследовал ни один интерфейс
|
||||||
|
if (pokemon is not IEvolvable && pokemon is not IFlyable)
|
||||||
|
{
|
||||||
|
Console.WriteLine("❌ Этот покемон не имеет особых способностей.");
|
||||||
|
}
|
||||||
|
Console.WriteLine(new string('-', 50));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Вывод итоговой статистики
|
||||||
|
Console.WriteLine("\n--- ИТОГОВАЯ СТАТИСТИКА СПОСОБНОСТЕЙ ---");
|
||||||
|
Console.WriteLine(\$"Способны к эволюции: {evolvableCount}");
|
||||||
|
Console.WriteLine(\$"Способны к полету: {flyableCount}");
|
||||||
|
|
||||||
|
Console.ReadLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+167
-98
@@ -1,83 +1,102 @@
|
|||||||
class Program
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
// Pokemon pika = new Pikachu("Пикачу", 5, 100);
|
Console.WriteLine("=== ЗАДАНИЕ 1: ИЕРАРХИЯ И ВИРТУАЛЬНЫЕ МЕТОДЫ ===");
|
||||||
// Pokemon squirtle = new Squirtle("Сквиртл", 7, 90);
|
|
||||||
// Pokemon charmander = new Charmander("Charmander", 9, 80);
|
Pokemon basePokemon = new Pokemon("Дикий покемон", 1, 10);
|
||||||
Console.WriteLine("=== ЗАДАНИЕ 1 ===");
|
Console.Write("Базовый вызов: ");
|
||||||
Console.WriteLine("=== ПОКЕДЕКС: АТАКИ ===\n");
|
basePokemon.ShowInfo();
|
||||||
List<Pokemon> pokemons = new List<Pokemon>(4)
|
basePokemon.Attack();
|
||||||
|
Console.WriteLine(new string('-', 40));
|
||||||
|
|
||||||
|
/*
|
||||||
|
Console.WriteLine("=== ЗАДАНИЕ 2: ТУРНИР И ПОЛИМОРФИЗМ (АБСТРАКТНЫЙ КЛАСС) ===");
|
||||||
|
// Pokemon test = new Pokemon("Абстрактный", 1, 10); // КРИТИЧЕСКАЯ ОШИБКА КОМПИЛЯЦИИ!
|
||||||
|
*/
|
||||||
|
|
||||||
|
List<Pokemon> pokemons = new List<Pokemon>()
|
||||||
{
|
{
|
||||||
new Pikachu("Пикачу", 5, 100),
|
new Pikachu("Пикачу", 5, 100),
|
||||||
new Squirtle("Сквиртл", 7, 90),
|
new Squirtle("Сквиртл", 7, 90),
|
||||||
new Charmander("Чармандер", 9, 80),
|
new Charmander("Чармандер", 6, 80),
|
||||||
new Bulbasaur("Бульбазавр", 6, 95)
|
new Bulbasaur("Бульбазавр", 4, 95)
|
||||||
};
|
};
|
||||||
foreach (Pokemon pokemon in pokemons)
|
|
||||||
|
Console.WriteLine($"Всего покемонов в списке: {pokemons.Count}");
|
||||||
|
Console.WriteLine("\n--- Раунд 1 ---");
|
||||||
|
|
||||||
|
foreach (Pokemon pokemon in pokemons)
|
||||||
{
|
{
|
||||||
pokemon.ShowInfo();
|
pokemon.ShowInfo();
|
||||||
pokemon.Attack();
|
pokemon.Attack();
|
||||||
Console.WriteLine();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"\nВсего атак проведено: {Pokemon.TotalAttacks}");
|
||||||
|
|
||||||
|
|
||||||
|
Console.WriteLine("\n=== ЗАДАНИЕ 3: СПОСОБНОСТИ ПОКЕМОНОВ ===");
|
||||||
|
|
||||||
|
foreach (Pokemon pokemon in pokemons)
|
||||||
|
{
|
||||||
|
Console.Write($"\n{pokemon.Name} (Ур. {pokemon.Level}) умеет: ");
|
||||||
|
|
||||||
|
if (pokemon is IEvolvable evolvable)
|
||||||
|
{
|
||||||
|
CapabilityCounter.EvolvableCount++;
|
||||||
|
evolvable.Evolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pokemon is IFlyable flyable)
|
||||||
|
{
|
||||||
|
CapabilityCounter.FlyableCount++;
|
||||||
|
flyable.Fly();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pokemon is not IEvolvable && pokemon is not IFlyable)
|
||||||
|
{
|
||||||
|
Console.WriteLine(" -> Особых способностей пока нет (только атака).");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("\nИтого:");
|
||||||
|
Console.WriteLine($"Эволюционируют: {CapabilityCounter.EvolvableCount}");
|
||||||
|
Console.WriteLine($"Летают: {CapabilityCounter.FlyableCount}");
|
||||||
|
|
||||||
|
Console.ReadLine();
|
||||||
}
|
}
|
||||||
// class Pokemon
|
|
||||||
// {
|
// ИНТЕРФЕЙСЫ (ЗАДАНИЕ 3)
|
||||||
// protected string name;
|
interface IEvolvable
|
||||||
//
|
|
||||||
// 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;
|
void Evolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IFlyable
|
||||||
|
{
|
||||||
|
void Fly();
|
||||||
|
}
|
||||||
|
|
||||||
|
static class CapabilityCounter
|
||||||
|
{
|
||||||
|
public static int EvolvableCount { get; set; }
|
||||||
|
public static int FlyableCount { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
class Pokemon
|
||||||
|
{
|
||||||
|
private static int totalAttacks = 0;
|
||||||
|
|
||||||
|
public static int TotalAttacks
|
||||||
|
{
|
||||||
|
get { return totalAttacks; }
|
||||||
|
set { totalAttacks = value; }
|
||||||
|
}
|
||||||
|
|
||||||
protected int hp;
|
protected int hp;
|
||||||
|
|
||||||
protected int level;
|
|
||||||
|
|
||||||
public int HP
|
public int HP
|
||||||
{
|
{
|
||||||
get { return hp; }
|
get { return hp; }
|
||||||
@@ -89,17 +108,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Level
|
public int Level { get; set; }
|
||||||
{
|
|
||||||
get { return level; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (value < 1) level = 1;
|
|
||||||
else if (value > 100) level = 100;
|
|
||||||
else level = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Name;
|
public string Name;
|
||||||
|
|
||||||
public Pokemon(string name, int level, int hp)
|
public Pokemon(string name, int level, int hp)
|
||||||
@@ -109,58 +118,118 @@
|
|||||||
this.HP = hp;
|
this.HP = hp;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual public void Attack()
|
public virtual void Attack()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Покемон аттакует");
|
Console.WriteLine("Покемон атакует!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowInfo()
|
public void ShowInfo()
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Name: {Name}, Уровень: {Level}, HP: {HP}");
|
Console.Write($"{Name} (Ур. {Level}): ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
// ВАРИАНТ ДЛЯ ЗАДАНИЯ 2: АБСТРАКТНЫЙ БАЗОВЫЙ КЛАСС С АБСТРАКТНЫМ МЕТОДОМ
|
||||||
|
abstract class Pokemon
|
||||||
|
{
|
||||||
|
private static int totalAttacks = 0;
|
||||||
|
|
||||||
|
public static int TotalAttacks
|
||||||
|
{
|
||||||
|
get { return totalAttacks; }
|
||||||
|
set { totalAttacks = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int hp;
|
||||||
|
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; set; }
|
||||||
|
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();
|
||||||
|
|
||||||
|
public void ShowInfo()
|
||||||
|
{
|
||||||
|
Console.Write($"{Name} (Ур. {Level}): ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
class Pikachu : Pokemon
|
class Pikachu : Pokemon
|
||||||
{
|
{
|
||||||
public Pikachu(string name, int level, int hp) : base(name, level, hp)
|
public Pikachu(string name, int level, int hp) : base(name, level, hp) { }
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
public override void Attack()
|
public override void Attack()
|
||||||
{
|
{
|
||||||
Console.WriteLine($"{Name} бьёт током! Пика-пика!");
|
Pokemon.TotalAttacks++;
|
||||||
|
Console.WriteLine("Пика-пика! Удар током!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class Charmander : Pokemon
|
|
||||||
|
class Charmander : Pokemon, IEvolvable
|
||||||
{
|
{
|
||||||
public Charmander(string name, int level, int hp) : base(name, level, hp)
|
public Charmander(string name, int level, int hp) : base(name, level, hp) { }
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
public override void Attack()
|
public override void Attack()
|
||||||
{
|
{
|
||||||
Console.WriteLine($"{Name} Чар-чар! Огненный хвост!");
|
Pokemon.TotalAttacks++;
|
||||||
|
Console.WriteLine("Чар-чар! Огненный хвост!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Evolve()
|
||||||
|
{
|
||||||
|
Console.WriteLine(" -> Чармандер готовится к эволюции!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Squirtle : Pokemon
|
class Squirtle : Pokemon
|
||||||
{
|
{
|
||||||
public Squirtle(string name, int level, int hp) : base(name, level, hp)
|
public Squirtle(string name, int level, int hp) : base(name, level, hp) { }
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
public override void Attack()
|
public override void Attack()
|
||||||
{
|
{
|
||||||
Console.WriteLine($"{Name} Сквирт-сквирт! Водяной пистолет!");
|
Pokemon.TotalAttacks++;
|
||||||
|
Console.WriteLine("Сквирт-сквирт! Водяной пистолет!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class Bulbasaur : Pokemon
|
|
||||||
{
|
|
||||||
public Bulbasaur(string name, int level, int hp) : base(name, level, hp)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
class Bulbasaur : Pokemon, IFlyable, IEvolvable
|
||||||
|
{
|
||||||
|
public Bulbasaur(string name, int level, int hp) : base(name, level, hp) { }
|
||||||
|
|
||||||
public override void Attack()
|
public override void Attack()
|
||||||
{
|
{
|
||||||
Console.WriteLine($"{Name} Бульба! Листовой удар!");
|
Pokemon.TotalAttacks++;
|
||||||
|
Console.WriteLine("Бульба! Листовой удар!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Fly()
|
||||||
|
{
|
||||||
|
Console.WriteLine(" -> Бульбазавр взлетает на лозах!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Evolve()
|
||||||
|
{
|
||||||
|
Console.WriteLine("\n -> Бульбазавр готовится к эволюции!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user