View difference between Paste ID: bJGC5b8A and C26sWULh
SHOW: | | - or go back to the newest paste.
1
using System;
2
using System.Collections.Generic;
3-
namespace C_sharp_Light
3+
4
namespace CLight
5
{
6
    class Program
7-
        static void Main(string[] args)
7+
8
        public static void Main()
9-
            
9+
10
            new FightRoom().Work();
11
        }
12
    }
13
    public static class RandomStatic
14
    {
15
        static private Random _rand = new Random();
16
        static public int GetNext(int min, int max)
17
        {
18
            return _rand.Next(min, max);
19
        }
20
    }
21
    public static class Messager
22
    {
23
        static public void ShowMessageWithColor(string message, ConsoleColor color, bool delay)
24
        {
25
            ConsoleColor defaultColor = Console.ForegroundColor;
26
            Console.ForegroundColor = color;
27
            Console.WriteLine(message);
28
            Console.ForegroundColor = defaultColor;
29
            if (delay)
30
                Console.ReadKey();
31
        }
32
    }
33
    
34
    class FightRoom
35
    {
36
        private List<Warrion> warrions = new List<Warrion>() { new Mag(), new Barbar(), new Sworder(), new Gunner(), new Priest() };
37
        public void Work()
38
        {
39
            Warrion warrion1;
40
            Warrion warrion2;
41
42
            for (int i = 0; i < warrions.Count; i++)
43
            {
44
                Console.Write($"{i}: ");
45
                warrions[i].ShowInfo();
46
            } 
47
48
49
            Console.Write("Веберите индекс первого бойца: ");
50
            warrion1 = warrions[Convert.ToInt32(Console.ReadLine())];
51
            Console.Write("Веберите индекс второго бойца бойца: ");
52
            warrion2 = warrions[Convert.ToInt32(Console.ReadLine())];
53
54
            while(warrion1.Hp>0 && warrion2.Hp > 0)
55
            {
56
                warrion1.Attack(warrion2);
57
                if (!(warrion1.Hp > 0 && warrion2.Hp > 0))
58
                    break;
59
                warrion2.Attack(warrion1);
60
                Console.WriteLine();
61
            }
62
            if (warrion1.Hp <= 0)
63
                Console.WriteLine("Первый воин пал");
64
            else
65
                Console.WriteLine("Второй воин пал");
66
            Console.ReadKey();
67
        }
68
    }
69
    abstract class Warrion
70
    {
71
        public int Hp { get; protected set; }
72
        public int BaseDamage { get; private set; }
73
        protected int ReadyDamage { get; set; }
74
        public Warrion(int hp,int damage)
75
        {
76
            Hp = hp;
77
            BaseDamage = damage;
78
        }
79
        abstract public void ShowInfo();
80
        private void GetDamage(int damage)
81
        {
82
            Hp -= damage;
83
        }
84
        public virtual void Attack(Warrion enemy)
85
        {
86
            enemy.GetDamage(ReadyDamage);
87
        }
88
    }
89
    class Mag : Warrion
90
    {
91
        public Mag() : base(RandomStatic.GetNext(100, 200), RandomStatic.GetNext(10, 150)) { }
92
        public override void Attack(Warrion enemy)
93
        {
94
            string[] typeSpell = new string[] {"огненному", "лесному" };
95
            int indexSpeel = RandomStatic.GetNext(0, 2);
96
            if (indexSpeel == 0)
97
                ReadyDamage = BaseDamage*2;
98
            else
99
                ReadyDamage = BaseDamage / 2;
100
            base.Attack(enemy);
101
            Messager.ShowMessageWithColor($"Маг - Dam:{BaseDamage}; Hp:{Hp} - Нанес урон противнику в {ReadyDamage} единиц благодоря {typeSpell[indexSpeel]} заклинанию", ConsoleColor.Green, false);
102
        }
103
        override public void ShowInfo()
104
        {
105
            Messager.ShowMessageWithColor($"Маг - Dam:{BaseDamage}; Hp:{Hp}", ConsoleColor.White, false);
106
        }
107
    }
108
    class Barbar : Warrion
109
    {
110
        public Barbar() : base(RandomStatic.GetNext(250, 500), RandomStatic.GetNext(75, 125)) { }
111
        public override void Attack(Warrion enemy)
112
        {
113
            bool isAmuck = Convert.ToBoolean(RandomStatic.GetNext(0, 2));
114
            if (isAmuck)
115
                ReadyDamage = (int)(BaseDamage * 1.5f);
116
            else
117
                ReadyDamage = BaseDamage;
118
            base.Attack(enemy);
119
            Messager.ShowMessageWithColor($"Варвар - Dam:{BaseDamage}; Hp:{Hp} - Нанес урон противнику в {ReadyDamage} единиц. Состояние ярости {isAmuck.ToString()}", ConsoleColor.Blue, false);
120
        }
121
        override public void ShowInfo()
122
        {
123
            Messager.ShowMessageWithColor($"Варвар - Dam:{BaseDamage}; Hp:{Hp}", ConsoleColor.White, false);
124
        }
125
    }
126
    class Sworder : Warrion
127
    {
128
        public Sworder() : base(RandomStatic.GetNext(200, 600), RandomStatic.GetNext(100, 200)) { }
129
        public override void Attack(Warrion enemy)
130
        {
131
            int remorse =RandomStatic.GetNext(0, 5)+1;
132
            ReadyDamage = BaseDamage / remorse;
133
            base.Attack(enemy);
134
            Messager.ShowMessageWithColor($"Мечник - Dam:{BaseDamage}; Hp:{Hp} - Нанес урон противнику в {ReadyDamage} единиц. Угрызение совести в {remorse} единицы, уменшила его атаку на {BaseDamage-ReadyDamage}", ConsoleColor.Cyan, false);
135
        }
136
        override public void ShowInfo()
137
        {
138
            Messager.ShowMessageWithColor($"Мечник - Dam:{BaseDamage}; Hp:{Hp}", ConsoleColor.White, false);
139
        }
140
    }
141
    class Gunner : Warrion
142
    {
143
        public Gunner() : base(RandomStatic.GetNext(100, 400), RandomStatic.GetNext(50, 100)) { }
144
        public override void Attack(Warrion enemy)
145
        {
146
            bool criticalShot = RandomStatic.GetNext(0, 101) < 20;
147
            if (criticalShot)
148
                ReadyDamage = BaseDamage * 10;
149
            else
150
                ReadyDamage = BaseDamage / 3;
151
            base.Attack(enemy);
152
            Messager.ShowMessageWithColor($"Стрелок - Dam:{BaseDamage}; Hp:{Hp} - Нанес урон противнику в {ReadyDamage} единиц. Критический выстер - {criticalShot}", ConsoleColor.Magenta, false);
153
        }
154
        override public void ShowInfo()
155
        {
156
            Messager.ShowMessageWithColor($"Стрелок - Dam:{BaseDamage}; Hp:{Hp}", ConsoleColor.White, false);
157
        }
158
    }
159
    class Priest : Warrion
160
    {
161
        public Priest() : base(RandomStatic.GetNext(250, 300), RandomStatic.GetNext(10, 70)) { }
162
        public override void Attack(Warrion enemy)
163
        {
164
            int powerPrayer = RandomStatic.GetNext(0, 11);
165
            ReadyDamage = BaseDamage * powerPrayer;
166
            base.Attack(enemy);
167
            Messager.ShowMessageWithColor($"Священик - Dam:{BaseDamage}; Hp:{Hp} - Нанес урон противнику в {ReadyDamage} единиц. Молитва в {powerPrayer}, увеличила атаку на {ReadyDamage-BaseDamage}", ConsoleColor.White, false);
168
        }
169
        override public void ShowInfo()
170
        {
171
            Messager.ShowMessageWithColor($"Священик - Dam:{BaseDamage}; Hp:{Hp}", ConsoleColor.White, false);
172
        }
173
    }
174
}