From bc9b5d33b5aae2b0075c6920202ee14e6ec5bec5 Mon Sep 17 00:00:00 2001 From: Puzanova Date: Wed, 25 Nov 2026 16:00:02 +0300 Subject: [PATCH] new --- works/CSharp/lab-07/Program.cs | 480 ++++++++++++++++++++++++-- works/Kotlin/works/lab-05/src/Main.kt | 3 - 2 files changed, 456 insertions(+), 27 deletions(-) diff --git a/works/CSharp/lab-07/Program.cs b/works/CSharp/lab-07/Program.cs index 283c3aa..a077093 100644 --- a/works/CSharp/lab-07/Program.cs +++ b/works/CSharp/lab-07/Program.cs @@ -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(); -} \ No newline at end of file diff --git a/works/Kotlin/works/lab-05/src/Main.kt b/works/Kotlin/works/lab-05/src/Main.kt index 384dc18..da575a8 100644 --- a/works/Kotlin/works/lab-05/src/Main.kt +++ b/works/Kotlin/works/lab-05/src/Main.kt @@ -68,7 +68,4 @@ fun main() { -println("ddtlbnt bvz ") - val name = readln() -var number = readln().toInt()