1

Тема: Допоможіть дописати іграшку

abstract class Warrior
    {
        private Names _name;
        private WarriorType _type;

        protected int _health;
        protected int _damage;
        protected bool _isAlive;
        protected int _battlesCount;
        protected int _armor;

        public Warrior(int health, int damage, bool isAlive, int battlesCount, int armor)
        {
            _armor = armor;
            _health = health;
            _damage = damage;
            _isAlive = isAlive = true;
            _battlesCount = battlesCount;

        }

        public string Name
        {
            get { return _name.ToString(); }
                   
        }
        public WarriorType Type
        {
            get { return _type; }
        }
        public abstract int Health { get; set; }
        public abstract int Damage { get; set; }
        public abstract int Armor { get; set; }

        public bool isAlive
        {
            get { return _isAlive ? Health >= 0 : false; }
        }
        public int BattlesCount
        {
            get { return _battlesCount; }
        }
        public override string ToString()
        {
            return string.Format("Name = {0}, Health = {1}, Armor = {2}, BattlesCount = {3}", Name, Health, Armor, BattlesCount);
        }
        public override int GetHashCode()
        {
            int hash = 13;
            hash = hash * 7 + _health.GetHashCode();
            hash = hash * 7 + _damage.GetHashCode();
            hash = hash * 7 + _battlesCount.GetHashCode();
            hash = hash * 7 + _isAlive.GetHashCode();
            hash = hash * 7 + _name.GetHashCode();
            hash = hash * 7 + _type.GetHashCode();
            return hash;
        }
        public override bool Equals(object obj)
        {
            Warrior warr = (Warrior) obj;
            if(obj == this) return true;
            if (obj == warr)
                return warr.Armor == Armor &&
                       warr.Damage == Damage &&
                       warr.Health == Health;
                return false;
        }
    }
    class Tribe
    {
        public TribeNames _name;
        public int _battlesCount;
        List<Warrior> _warriors;
        public int _aliveCount;
        public int _totalCount;

        public Tribe(int battlesCount, int totalCount)
        {
            _battlesCount = battlesCount;
            _totalCount = totalCount;
            _warriors = new List<Warrior>();
        }

        public string Name
        {
            get { return _name.ToString(); }
        }
        public int BattlesCount
        {
            get { return _battlesCount; }
        }
        public int AliveCount
        {
            get { return _aliveCount; }
            set { _aliveCount = value < 0 ? 0 : value; }
        }
        public int TotalCount
        {
            get { return _totalCount; }
            set { _totalCount = value < 0 ? 1000 : value; }
        }

       public Warrior this[int index]
       {
           get {return _warriors[index];}
           set {_warriors[index] = value;}
       }
       public void Add(Warrior war)
       {
           _warriors.Add(war);
       }
       public override int GetHashCode()
       {
           int hash = 13;
           hash = hash * 7 + _battlesCount.GetHashCode();
           hash = hash * 7 + _aliveCount.GetHashCode();
           hash = hash * 7 + _name.GetHashCode();
           hash = hash * 7 + _totalCount.GetHashCode();
           return hash;
       }
       public override bool Equals(object obj)
       {
           Warrior tribe = (Warrior)obj;
           if (obj == this) return true;
           if (obj == tribe)
               return tribe.Name == Name;
           return false;
       }
       public override string ToString()
       {
           return string.Format("Name of Tribe: {0} Count of Battles: {1} Own count of warrior: {2} ", Name, BattlesCount, TotalCount);
       }
    }
    class Battle
    {
        public Tribe[] _tribes;
        public int _round;
        public Tribe _winner;
        public bool _isOver;

        public Battle(int round, bool isOver, params Tribe[] tribes)
        {
            _round = round = 0;
            _isOver = isOver;
            _tribes = tribes;
        }

        public int RoundCount
        {
            get { return _round; }
        }
        public bool NextRound()
        {
           if( _isOver == true)
           {
               Console.WriteLine("Round is over!");
               
               _round++;
           }
            return true;
        }
        public Tribe Winner(Tribe _winner)
        {
            if (_isOver == true && _tribes.Length >= 0 && _tribes.Length < 2 )
            {
                Console.WriteLine("Winner of this round is - " + _winner);
            }
            return _winner;
       }
    }
    class TribeCreator
    {
        public int numIronMen;
        public int numRedWolfs;
        public int numWildAxes;
        public int numBrownGhoust;
        public Tribe CreateInstance(TribeNames vubor, Tribe number_war)
        {
            Console.WriteLine("Create Tribes: ");
            Console.Write("Maybe name for tribes:");
            TribeNames i;
            TribeNames my_tribe, first_tribe, second_tribe, thirsd_tribe;
            for (i = TribeNames.RedWolfs; i <= TribeNames.BrownGhoust; i++)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine("Create first your own tribe with name Iron Men");

            switch(vubor)
            {
                case TribeNames.IronMen:
                    {
                        my_tribe = TribeNames.IronMen;
                        Console.WriteLine("Enter number citizen for tribe: ");
                        string s = Console.ReadLine();
                        numIronMen = Convert.ToInt32(s);
                        break;
                        Console.WriteLine("Your tride will have  name: " + my_tribe + " and have " + numIronMen + " citizen");
                    }
                case TribeNames.RedWolfs:
                    {
                        first_tribe = TribeNames.RedWolfs;
                        Console.WriteLine("Enter number citizen for tribe: ");
                        string s = Console.ReadLine();
                        numRedWolfs = Convert.ToInt32(s);
                        break;
                        Console.WriteLine("Tride will have  name: " + first_tribe + " and have " + numRedWolfs + " citizen");
                    }
                case TribeNames.WildAxes:
                    {
                        second_tribe = TribeNames.WildAxes;
                        Console.WriteLine("Enter number citizen for tribe: ");
                        string s = Console.ReadLine();
                        numWildAxes = Convert.ToInt32(s);
                        break;
                        Console.WriteLine("Tride will have  name: " + second_tribe + " and have " + numWildAxes + " citizen");
                    }
                case TribeNames.BrownGhoust:
                    {
                        thirsd_tribe = TribeNames.BrownGhoust;
                        Console.WriteLine("Enter number citizen for tribe: ");
                        string s = Console.ReadLine();
                        numBrownGhoust = Convert.ToInt32(s);
                        break;
                        Console.WriteLine("Tride will have  name: " + thirsd_tribe + " and have " + numBrownGhoust + " citizen");
                    }
            }
            return number_war;
        }
    }
    class Triarius : Warrior
    {
        public Triarius(int health, int damage, bool isAlive, int battlesCount, int armor) : base(health, damage, isAlive, battlesCount, armor) { }
        public override string ToString()
        {
            return string.Format("Name = {0}, Health = {1}, Armor = {2}, BattlesCount = {3}", Name, Health, Armor, BattlesCount);
        }
    }
    class Princeps : Warrior
    {
        public Princeps(int health, int damage, bool isAlive, int battlesCount, int armor) : base(health, damage, isAlive, battlesCount, armor) { }
        public override string ToString()
        {
            return string.Format("Name = {0}, Health = {1}, Armor = {2}, BattlesCount = {3}", Name, Health, Armor, BattlesCount);
        }
    }
    class Hastatus : Warrior
    {
         public Hastatus(int health, int damage, bool isAlive, int battlesCount, int armor) : base(health, damage, isAlive, battlesCount, armor) { }
        public override string ToString()
        {
            return string.Format("Name = {0}, Health = {1}, Armor = {2}, BattlesCount = {3}", Name, Health, Armor, BattlesCount);
        }
    }
    class Accensi : Warrior
    {
        public Accensi(int health, int damage, bool isAlive, int battlesCount, int armor) : base(health, damage, isAlive, battlesCount, armor) { }
        public override string ToString()
        {
            return string.Format("Name = {0}, Health = {1}, Armor = {2}, BattlesCount = {3}", Name, Health, Armor, BattlesCount);
        }
    }
 enum TribeNames : int
    {
        RedWolfs, IronMen, WildAxes, BrownGhoust
    };
enum WarriorType
    {
        Tank, Dodge, Critical
    };

1. Створюється плем’я користувача з воїнами типу Accensi в кількості заданим користувачем N (TribeCreator)
При створенні воїна TribeCreator задає довільним чином показники воїнів в діапазоні 70-100%
Створюється (TribeCreator) 3 племені з N воїнами (Hastatus, Princeps, Triarius відповідно до кожного племені)
2. Розпочинається перша битва племені користувача з плем’ям воїнів Hastatus (Battle)
Удар (D), що наносить воїн залежить додатково від його здоров’я та є випадковою величино діапазону (0,7-1,0)*D
Втрати залежать від отриманого удару та захисту воїна
3. За умови перемоги племені користувача воїни, що вижили лікуються та отримують бонус до параметрів (Bonus)
4. Повторюються кроки 2-3 з племенами воїнів Princeps, Triarius

2 Востаннє редагувалося /KIT\ (08.07.2021 13:49:25)

Re: Допоможіть дописати іграшку

isAlive?health>=0:false

????? %)

Подякували: FakiNyan1

3

Re: Допоможіть дописати іграшку

/KIT\ написав:
isAlive?health>=0:false

????? %)

це якась наркоманія, правильно буде

isAlive = health>0
Подякували: /KIT\1

4

Re: Допоможіть дописати іграшку

FakiNyan написав:
/KIT\ написав:
isAlive?health>=0:false

????? %)

це якась наркоманія, правильно буде

isAlive = health>0

Звідки ви знаєте, що так буде правильно? У вас є техзавдання? А що ця функція має для зомбі повертати?

Подякували: leofun011

5

Re: Допоможіть дописати іграшку

koala написав:
FakiNyan написав:
/KIT\ написав:
isAlive?health>=0:false

????? %)

це якась наркоманія, правильно буде

isAlive = health>0

Звідки ви знаєте, що так буде правильно? У вас є техзавдання? А що ця функція має для зомбі повертати?

Я так бачу. Не пискуйте до мене.

6

Re: Допоможіть дописати іграшку

Пане Слюсаре, скажіть, у вас племена відрізняються поведінкою, чи тільки тим, що в різних племен різні назви воїнів? Якщо друге, то вам не треба їх успадковувати, всі вони - Warrior-и.

7

Re: Допоможіть дописати іграшку

Вже все зробив) Дякую

8

Re: Допоможіть дописати іграшку

Якщо кому цікаво.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace fianl_war
{
    class Program
    {
        static Battle _battle;
        static void Main(string[] args)
        {
            _battle = new Battle();
            _battle.NextRound();
            _battle.tribes[0].ShowWarrior();
            Console.ReadKey();
        }
    }
}
 enum TribeNames
    {
        RedWolfs,
        IronMans,
        WildAxes,
        HealtheMans,
        GodFachers,
        AmerinanFamily,
        OldHerous
    }
class Tribe
    {
        Random rand;
        TribeNames _name;
        int _battlesCount;
        List<Warrior> _warriors;
        public Tribe()
        {
            _warriors = new List<Warrior>();
            rand = new Random();
        }
        public TribeNames Name { get { return _name; } set { _name = value; } }
        public int BattlesCount { get { return _battlesCount; } set { _battlesCount = value; } }
        public int AliveCount
        {
            get
            {
                int count = 0;
                foreach (var x in _warriors)
                {
                    if (x.IsAlive) count++;
                }
                return count;
            }
        }
        public void Warrior(Warrior warrior) { _warriors.Add(warrior); }
        public int TotalCount { get { return _warriors.Count(); } }
        public List<Warrior> Warriors { get { return _warriors; } }
        public void Warrior(int countWarrior, TribeTypes type)
        {
            for (int i = 0; i < countWarrior; i++)
            {
                switch (type)
                {
                    case TribeTypes.Accensi:
                        {
                            Names name = (Names)rand.Next(12);
                            WarriorTypes wtype = (WarriorTypes)rand.Next(4);
                            _warriors.Add(new Accensi(name, wtype)); break;
                        }
                    case TribeTypes.Hastatus:
                        {
                            Names name = (Names)rand.Next(12);
                            WarriorTypes wtype = (WarriorTypes)rand.Next(4);
                            _warriors.Add(new Hastatus(name, wtype)); break;
                        }
                    case TribeTypes.Princepts:
                        {
                            Names name = (Names)rand.Next(12);
                            WarriorTypes wtype = (WarriorTypes)rand.Next(4);
                            _warriors.Add(new Princeps(name, wtype)); break;
                        }
                    case TribeTypes.Triarius:
                        {
                            Names name = (Names)rand.Next(12);
                            WarriorTypes wtype = (WarriorTypes)rand.Next(4);
                            _warriors.Add(new Triarius(name, wtype)); break;
                        }
                }
            }
        }
        public string ShowWarrior()
        {
            string s = null;
            int count = 0;
            foreach (var item in _warriors)
            {
                s = "" + s + "[" + count++ + "]" + item.ToString() + "\n";
            }
            return s;
        }

        public Warrior this[int index] { get { return _warriors[index]; } }
        public override bool Equals(object obj) { return this.ToString().Equals(obj.ToString()); }
        public override int GetHashCode() { return this.ToString().GetHashCode(); }
        public override string ToString()
        {
            return "Name: " + Name + "|Battle: " + BattlesCount + "|CountofAlive " + AliveCount + "|TotalCount " + TotalCount;
        }
    }
class Triarius : Warrior
    {
        public Triarius(Names name, WarriorTypes type, int battlecount = 0)
            : base(name, type, battlecount)
        {
            switch (Type)
            {
                case WarriorTypes.Critical:
                    {
                        MaxHealth = 130;
                        Armor = Armor;
                        Health = MaxHealth;
                        Damage = 6;
                        break;
                    }
                case WarriorTypes.Dodge:
                    {
                        MaxHealth = 130;
                        Armor = Armor;
                        Health = MaxHealth;
                        Damage = 3;
                        break;
                    }
                case WarriorTypes.Tank:
                    {
                        MaxHealth = 150;
                        Armor = Armor;
                        Health = MaxHealth;
                        Damage = 2;
                        break;
                    }
            }
        }
        public override int Damage { get { return _damage; } set { _damage = value; } }
        public override int Armor
        {
            get { return _armor; }
            set
            {
                _armor = (value > MaxHealth * 2) ? MaxHealth * 2 : (value > 0) ? value : 0;
            }
        }
        public override int Health
        {
            get { return _health; }
            set
            {
                _health = (value > MaxHealth) ? MaxHealth : (value > 0) ? value : 0;
            }
        }
        public override int MaxHealth
        {
            get { return _maxhealth; }
            set
            {
                if (value > 0) _maxhealth = value; else _maxhealth = 0;
            }
        }
    }
 class Princeps : Warrior
    {
        public Princeps(Names name, WarriorTypes type, int battlecount = 0)
            : base(name, type, battlecount)
        {
            switch (Type)
            {
                case WarriorTypes.Critical:
                    {
                        MaxHealth = 100;
                        Armor = Armor;
                        Health = MaxHealth;
                        Damage = 4;
                        break;
                    }
                case WarriorTypes.Dodge:
                    {
                        MaxHealth = 100;
                        Armor = Armor;
                        Health = MaxHealth;
                        Damage = 3;
                        break;
                    }
                case WarriorTypes.Tank:
                    {
                        MaxHealth = 60;
                        Armor = Armor;
                        Health = MaxHealth;
                        Damage = 1;
                        break;
                    }
            }
        }
        public override int Damage { get { return _damage; } set { _damage = value; } }
        public override int Armor
        {
            get { return _armor; }
            set
            {
                _armor = (value > MaxHealth * 2) ? MaxHealth * 2 : (value > 0) ? value : 0;
            }
        }
        public override int Health
        {
            get { return _health; }
            set
            {
                _health = (value > MaxHealth) ? MaxHealth : (value > 0) ? value : 0;
            }
        }
        public override int MaxHealth
        {
            get { return _maxhealth; }
            set
            {
                if (value > 0) _maxhealth = value; else _maxhealth = 0;
            }
        }
    }
 class Hastatus : Warrior
    {
        public Hastatus(Names name, WarriorTypes type, int battlecount = 0)
            : base(name, type, battlecount)
        {
            switch (Type)
            {
                case WarriorTypes.Critical:
                    {
                        MaxHealth = 100;
                        Armor = Armor;
                        Health = MaxHealth;
                        Damage = 5;
                        break;
                    }
                case WarriorTypes.Dodge:
                    {
                        MaxHealth = 100;
                        Armor = Armor;
                        Health = MaxHealth;
                        Damage = 3;
                        break;
                    }
                case WarriorTypes.Tank:
                    {
                        MaxHealth = 100;
                        Armor = Armor;
                        Health = MaxHealth;
                        Damage = 1;
                        break;
                    }
            }
        }
        public override int Damage { get { return _damage; } set { _damage = value; } }
        public override int Armor
        {
            get { return _armor; }
            set
            {
                _armor = (value > MaxHealth * 2) ? MaxHealth * 2 : (value > 0) ? value : 0;
            }
        }
        public override int Health
        {
            get { return _health; }
            set
            {
                _health = (value > MaxHealth) ? MaxHealth : (value > 0) ? value : 0;
            }
        }
        public override int MaxHealth
        {
            get { return _maxhealth; }
            set
            {
                if (value > 0) _maxhealth = value; else _maxhealth = 0;
            }
        }
    }
class Battle
    {
        public List<Tribe> tribes;
        int _round;
        int _next;
        Tribe _winner;
        bool _isOver;
        bool _Exit;
        public Battle(int countWarriors = 10)
        {
            tribes = new List<Tribe>();
            tribes.Add(TribeCreator.CreateInstance(countWarriors, TribeTypes.Accensi));
            tribes.Add(TribeCreator.CreateInstance(countWarriors, TribeTypes.Hastatus));
            tribes.Add(TribeCreator.CreateInstance(countWarriors, TribeTypes.Princepts));
            tribes.Add(TribeCreator.CreateInstance(countWarriors, TribeTypes.Triarius));
        }
        public bool NextRound()
        {

            if (_isOver && tribes[_next].AliveCount > 0)
            { _next--; _isOver = false; }
            else if (_isOver && tribes[0].AliveCount > 0)
            { _isOver = false; }
            if (!_isOver && tribes[tribes.Count - 1].AliveCount == 0)
            { _isOver = true; }
            if (!_isOver && tribes[tribes.Count - 1].AliveCount > 0 && _next + 1 < tribes.Count)
            {
                Battles(tribes[0], tribes[++_next]);
                return true;
            }
            else if (_isOver)
                Console.WriteLine("The end!");

            return false;
        }
        public int IdEnemy
        {
            get
            {
                return (_next == 0) ? 1 : _next + 1;
            }
        }
        public void Battles(Tribe first, Tribe second)
        {
            _Exit = true;
            BattleCount(first, second);
            while ((first.AliveCount > 0 && second.AliveCount > 0) && _Exit)
            {
                for (int i = 0; i < second.TotalCount; i++)
                {
                    for (int j = 0; j < first.TotalCount; j++)
                    {
                        if (second[i].IsAlive && second[i].Armor > 0 && first[j].IsAlive) second[i].Armor -= first[j].Damage;
                        else if (second[i].IsAlive && first[i].IsAlive) second[i].Health -= first[j].Damage;
                    }
                }
                for (int i = 0; i < first.TotalCount; i++)
                {
                    for (int j = 0; j < second.TotalCount; j++)
                    {
                        if (second[i].IsAlive && first[i].Armor > 0 && first[j].IsAlive) first[i].Armor -= second[j].Damage;
                        else if (second[i].IsAlive && first[i].IsAlive) first[i].Health -= second[j].Damage;
                    }
                }
                NextCheack(first, second);
            }
        }
        public void NextCheack(Tribe first, Tribe second)
        {
            if ((first.AliveCount <= 0 || second.AliveCount <= 0) && _Exit)
            {
                first.BattlesCount++;
                second.BattlesCount++;
                if (first.AliveCount > second.AliveCount)
                {
                    _winner = first;
                }
                else
                {
                    _next--;
                    _winner = second;
                }
                tribes[0] = first;
                if (_next < 0) tribes[_next] = second;
                _Exit = false;
                _isOver = (first.AliveCount > 0) ? false : true;
                Thread.Sleep(2000);
                Console.WriteLine("Winners in {0} battle tribe: {1}", _next, Winner().Name);
                Console.WriteLine("{0}\n{1}", first, first.ShowWarrior());
                NextRound();
            }
            else if (_Exit)
            {
                _round++;
            }
        }

        public void BattleCount(Tribe first, Tribe second)
        {
            for (int i = 0; i < first.TotalCount; i++) if (first[i].IsAlive) first[i].BattleCount++;
            for (int i = 0; i < second.TotalCount; i++) if (second[i].IsAlive) second[i].BattleCount++;
        }
        public Tribe Winner() { return _winner; }
        public int RoundCount { get { return _round; } }
    }
 enum Names
    {
        David,
        James,
        Alex,
        Stiven,
        Jeffrey,
        Jeremy,
        Alexander,
        Scot,
        Julian,
        Quentin,
        Alan,
        Paul
    }
 class Accensi : Warrior
    {
        public Accensi(Names name, WarriorTypes type, int battlecount = 0)
            : base(name, type, battlecount)
        {
            switch (Type)
            {
                case WarriorTypes.Critical:
                    {
                        MaxHealth = 205;
                        Armor = Armor;
                        Health = MaxHealth;
                        Damage = 9;
                        break;
                    }
                case WarriorTypes.Dodge:
                    {
                        MaxHealth = 155;
                        Armor = Armor;
                        Health = MaxHealth;
                        Damage = 7;
                        break;
                    }
                case WarriorTypes.Tank:
                    {
                        MaxHealth = 240;
                        Armor = Armor;
                        Health = MaxHealth;
                        Damage = 2;
                        break;
                    }
            }
        }
        public override int Damage { get { return _damage; } set { _damage = value; } }
        public override int Armor
        {
            get { return _armor; }
            set
            {
                _armor = (value > MaxHealth * 2) ? MaxHealth * 2 : (value > 0) ? value : 0;
            }
        }
        public override int Health
        {
            get { return _health; }
            set
            {
                _health = (value > MaxHealth) ? MaxHealth : (value > 0) ? value : 0;
            }
        }
        public override int MaxHealth
        {
            get { return _maxhealth; }
            set
            {
                if (value > 0) _maxhealth = value; else _maxhealth = 0;
            }
        }
    }
class TribeCreator
    {
        static Random random = new Random();
        public TribeCreator()
        {
        }
        static public Tribe CreateInstance(int size, TribeTypes type)
        {
            Tribe tribe = new Tribe();
            var nameTribe = Enum.GetValues(typeof(TribeNames));
            tribe.Name = (TribeNames)nameTribe.GetValue(random.Next((random.Next(3) + random.Next(2)), nameTribe.Length));
            tribe.Warrior(size, type);
            return tribe;
        }
    }
abstract class Warrior
    {
        private Names _name;
        private WarriorTypes _type;
        protected int _health;
        protected int _maxhealth;
        protected int _damage;
        protected bool _isAlive;
        private int _battelsCount;
        protected int _armor;
        public Warrior(Names names, WarriorTypes warriorType, int battleCount)
        {
            _name = names;
            _type = warriorType;
            _battelsCount = battleCount;
        }
        public string Name { get { return _name.ToString(); } }
        public WarriorTypes Type { get { return _type; } }
        public abstract int MaxHealth { get; set; }
        public abstract int Health { get; set; }
        public abstract int Damage { get; set; }
        public abstract int Armor { get; set; }
        public int BattleCount { get { return _battelsCount; } set { _battelsCount = value; } }
        public bool IsAlive { get { return _isAlive = (Health > 0) ? true : false; } }
        public override bool Equals(object obj) { return this.ToString().Equals(obj.ToString()); }
        public override int GetHashCode() { return this.ToString().GetHashCode(); }
        public override string ToString()
        {
            return "Name: " + Name + "|Type:  " + Type + "|Health: " + Health + "|Damage: " + Damage + "|Armor: " + Armor + "|IsAlive: " + IsAlive + "|CountOfBattle " + BattleCount;
        }
    }
    enum WarriorTypes
    {
        Tank,
        Dodge,
        Critical
    }

Правда сюди можна дуже багато чого добавити і це ще фінальна версі, але основний функціонал працює)

Подякували: FakiNyan, koala2

9

Re: Допоможіть дописати іграшку

Хочу, щоб після кожної перемоги, моє військо отримувало бонуси і я їх міг розкинути між воїнами(збільшити здоров'я чи броню і т.д.)

10

Re: Допоможіть дописати іграшку

Пораджу: якщо бачите три однакових фрагменти коду - об'єднайте їх. Наприклад, Health, Armor та MaxHealth поводяться однаково у всіх нащадків Warrior - значить, винесіть їх у Warrior і перевизначайте тільки там, де вони змінюються. Конструктори різних нащадків відрізняються лише константами? Винесіть ці константи десь окремо, а конструктор зробіть єдиним. Цей код можна спокійно скоротити вдвічі, і від цього тільки легше стане.

Подякували: taburyak1