generated from admin/template
Добавлено 6 по 7 ПЗ
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
using System;
|
||||
|
||||
abstract class Pokemon
|
||||
{
|
||||
protected string name;
|
||||
protected int level;
|
||||
protected int hp;
|
||||
|
||||
public static int TotalAttacks = 0;
|
||||
|
||||
public string Name { get { return name; } }
|
||||
public int Level { get { return level; } }
|
||||
public int HP { get { return hp; } }
|
||||
|
||||
public Pokemon(string name, int level, int hp)
|
||||
{
|
||||
this.name = name;
|
||||
this.level = level;
|
||||
this.hp = hp;
|
||||
}
|
||||
|
||||
public abstract void Attack();
|
||||
|
||||
public void ShowInfo()
|
||||
{
|
||||
Console.WriteLine($" {Name} (Ур. {Level}), HP: {HP}");
|
||||
}
|
||||
}
|
||||
|
||||
interface IEvolvable
|
||||
{
|
||||
void Evolve();
|
||||
}
|
||||
|
||||
interface IFlyable
|
||||
{
|
||||
void Fly();
|
||||
}
|
||||
|
||||
class Pikachu : Pokemon
|
||||
{
|
||||
public Pikachu(string name, int level, int hp) : base(name, level, hp) { }
|
||||
|
||||
public override void Attack()
|
||||
{
|
||||
Console.WriteLine($" {Name} (Ур. {Level}): Пика-пика! Удар током!");
|
||||
TotalAttacks++;
|
||||
}
|
||||
}
|
||||
|
||||
class Squirtle : Pokemon
|
||||
{
|
||||
public Squirtle(string name, int level, int hp) : base(name, level, hp) { }
|
||||
|
||||
public override void Attack()
|
||||
{
|
||||
Console.WriteLine($" {Name} (Ур. {Level}): Сквирт-сквирт! Водяной пистолет!");
|
||||
TotalAttacks++;
|
||||
}
|
||||
}
|
||||
|
||||
class Charmander : Pokemon, IEvolvable
|
||||
{
|
||||
public Charmander(string name, int level, int hp) : base(name, level, hp) { }
|
||||
|
||||
public override void Attack()
|
||||
{
|
||||
Console.WriteLine($" {Name} (Ур. {Level}): Чар-чар! Огненный хвост!");
|
||||
TotalAttacks++;
|
||||
}
|
||||
|
||||
public void Evolve()
|
||||
{
|
||||
Console.WriteLine($" {Name} эволюционирует в Чармелеона!");
|
||||
}
|
||||
}
|
||||
|
||||
class Pidgeotto : Pokemon, IFlyable, IEvolvable
|
||||
{
|
||||
public Pidgeotto(string name, int level, int hp) : base(name, level, hp) { }
|
||||
|
||||
public override void Attack()
|
||||
{
|
||||
Console.WriteLine($" {Name} (Ур. {Level}): Пиджеотто атакует с воздуха!");
|
||||
TotalAttacks++;
|
||||
}
|
||||
|
||||
public void Fly()
|
||||
{
|
||||
Console.WriteLine($" {Name} взлетает!");
|
||||
}
|
||||
|
||||
public void Evolve()
|
||||
{
|
||||
Console.WriteLine($" {Name} эволюционирует!");
|
||||
}
|
||||
}
|
||||
|
||||
class Magikarp : Pokemon
|
||||
{
|
||||
public Magikarp(string name, int level, int hp) : base(name, level, hp) { }
|
||||
|
||||
public override void Attack()
|
||||
{
|
||||
Console.WriteLine($" {Name} (Ур. {Level}): Splash... ничего не произошло.");
|
||||
TotalAttacks++;
|
||||
}
|
||||
}
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
Console.WriteLine("=== ПОКЕДЕКС: АТАКИ ===");
|
||||
|
||||
var pika = new Pikachu("Пикачу", 5, 50);
|
||||
var squirt = new Squirtle("Сквиртл", 7, 60);
|
||||
var charm = new Charmander("Чармандер", 6, 55);
|
||||
|
||||
pika.Attack();
|
||||
squirt.Attack();
|
||||
charm.Attack();
|
||||
|
||||
// var p = new Pokemon("Просто покемон", 1, 100); // ОШИБКА: класс абстрактный
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine("=== ТУРНИР: ВСЕ ПРОТИВ ВСЕХ ===");
|
||||
|
||||
Pokemon[] team = {
|
||||
new Pikachu("Пикачу", 5, 50),
|
||||
new Squirtle("Сквиртл", 7, 60),
|
||||
new Charmander("Чармандер", 6, 55),
|
||||
new Magikarp("Магикарп", 3, 30)
|
||||
};
|
||||
|
||||
Console.WriteLine($"Всего покемонов: {team.Length}\n--- Раунд 1 ---");
|
||||
|
||||
foreach (Pokemon p in team)
|
||||
{
|
||||
p.Attack();
|
||||
}
|
||||
|
||||
Console.WriteLine($"\nВсего атак проведено: {Pokemon.TotalAttacks}");
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine("=== СПОСОБНОСТИ ПОКЕМОНОВ ===\n");
|
||||
|
||||
Pokemon[] team2 = {
|
||||
new Charmander("Чармандер", 6, 55),
|
||||
new Pidgeotto("Пиджеотто", 9, 70),
|
||||
new Magikarp("Магикарп", 3, 30)
|
||||
};
|
||||
|
||||
int evolvers = 0;
|
||||
int flyers = 0;
|
||||
|
||||
foreach (Pokemon p in team2)
|
||||
{
|
||||
Console.Write($" {p.Name} (Ур. {p.Level}) умеет: атаковать");
|
||||
if (p is IEvolvable) Console.Write(", эволюционировать");
|
||||
if (p is IFlyable) Console.Write(", летать");
|
||||
Console.WriteLine();
|
||||
|
||||
if (p is IEvolvable evolvable)
|
||||
{
|
||||
evolvable.Evolve();
|
||||
evolvers++;
|
||||
}
|
||||
if (p is IFlyable flyable)
|
||||
{
|
||||
flyable.Fly();
|
||||
flyers++;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"\nИтого:");
|
||||
Console.WriteLine($" Эволюционируют: {evolvers}");
|
||||
Console.WriteLine($" Летают: {flyers}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user