diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..e69de29 diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs deleted file mode 100644 index 14357d6..0000000 --- a/CourseApp.Tests/DemoTest.cs +++ /dev/null @@ -1,95 +0,0 @@ -using System; -using Xunit; - -namespace CourseApp.Tests -{ - public class DemoTest - { - [Theory] - [InlineData(0, 0, 0, double.NaN)] - - public void TestCalcAllZero(double a, double b, double x, double exp) - { - var actualResult = Program.Calc(a, b, x); - Assert.Equal(exp, actualResult); - } - - [Fact] - public void Test1() - { - Assert.True(true); - } - - [Fact] - public void NumenatorEqualZero() - { - var actualResult = Program.Calc(1, 2, 2); - Assert.Equal(double.NaN, actualResult); - } - - [Fact] - public void DenominatorEqualZero() - { - var actualResult = Program.Calc(1, 1, 0); - Assert.Equal(double.NaN, actualResult); - } - - [Fact] - public void LogEqualZero() - { - var actualResult = Program.Calc(1, 0, 0); - Assert.Equal(double.NaN, actualResult); - } - - [Fact] - public void ArrayLenght() - { - var actualResult = Program.TaskA(2, 1.1, 0.08, 1.08, 0.2); - Assert.Equal(6, actualResult.Length); - } - - [Fact] - public void Array() - { - var actualResult = Program.TaskA(2, 1.1, 1, 6, 1); - Assert.Equal(6, actualResult.Length); - double[] expX = { 1, 2, 3, 4, 5, 6 }; - for (int i = 0; i <= 5; i++) - { - var (x, y) = actualResult[i]; - Assert.Equal(expX[i], x, 1); - } - } - - [Fact] - public void ArrayOfThreeElements() - { - double[] xTest = { 1, 2, 3 }; - var actualResult = Program.TaskB(2, 1.1, xTest); - Assert.Equal(3, actualResult.Length); - } - - [Fact] - public void ArrayOfZeroElements() - { - double[] xTest = { }; - var actualResult = Program.TaskB(2, 1, xTest); - var a = actualResult.Length; - Assert.Equal(0, a); - } - - [Fact] - public void RootOfFive() - { - var actualResult = Program.CubeRoot(-32); - Assert.Equal(-2, actualResult); - } - - [Fact] - public void RootOfFive2() - { - var actualResult = Program.CubeRoot(32); - Assert.Equal(2, actualResult); - } - } -} \ No newline at end of file diff --git a/CourseApp.Tests/TestClass1.cs b/CourseApp.Tests/TestClass1.cs deleted file mode 100644 index de138d0..0000000 --- a/CourseApp.Tests/TestClass1.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using Xunit; - -namespace CourseApp.Tests -{ - public class TestClass1 - { - [Fact] - public void ZeroOfPopulation() - { - Country country2 = new Country(0, 40, 185); - var actualResult = country2.Population; - Assert.Equal(0, actualResult); - } - - [Fact] - public void ZeroOfArea() - { - Country country2 = new Country(13860, 0, 185); - var actualResult = country2.Area; - Assert.Equal(0, actualResult); - } - - [Fact] - public void ZeroOfDensity() - { - Country country2 = new Country(13860, 40, 0); - var actualResult = country2.Density; - Assert.Equal(0, actualResult); - } - } -} \ No newline at end of file diff --git a/CourseApp/Archer.cs b/CourseApp/Archer.cs new file mode 100644 index 0000000..657ab67 --- /dev/null +++ b/CourseApp/Archer.cs @@ -0,0 +1,23 @@ +using System; + +namespace CourseApp +{ + public class Archer : Player + { + public Archer(string name) + : base(name) + { + } + + public override int DealDamage(bool useUlt) + { + if (useUlt) + { + Console.WriteLine($"{Name} ультанул, огненные стрелы"); + return 0; + } + + return Power; + } + } +} \ No newline at end of file diff --git a/CourseApp/Country.cs b/CourseApp/Country.cs index 4629373..fbe6a57 100644 --- a/CourseApp/Country.cs +++ b/CourseApp/Country.cs @@ -10,7 +10,7 @@ public class Country public Country() { - Console.WriteLine($"Население, площадь и плоность не заданы"); + Console.WriteLine($"Население, площадь и плотность не заданы"); } public Country(int population, int area, double density) diff --git a/CourseApp/Knight.cs b/CourseApp/Knight.cs new file mode 100644 index 0000000..b80d245 --- /dev/null +++ b/CourseApp/Knight.cs @@ -0,0 +1,23 @@ +using System; + +namespace CourseApp +{ + public class Knight : Player + { + public Knight(string name) + : base(name) + { + } + + public override int DealDamage(bool useUlt) + { + if (useUlt) + { + Console.WriteLine($"{Name} ультанул, +30% к урону"); + return Convert.ToInt32(Math.Floor(Power * 1.3)); + } + + return Power; + } + } +} \ No newline at end of file diff --git a/CourseApp/Magician.cs b/CourseApp/Magician.cs new file mode 100644 index 0000000..2e75ef9 --- /dev/null +++ b/CourseApp/Magician.cs @@ -0,0 +1,23 @@ +using System; + +namespace CourseApp +{ + public class Magician : Player + { + public Magician(string name) + : base(name) + { + } + + public override int DealDamage(bool useUlt) + { + if (useUlt) + { + Console.WriteLine($"{Name} ультанул, пропуск хода"); + return 0; + } + + return Power; + } + } +} \ No newline at end of file diff --git a/CourseApp/Player.cs b/CourseApp/Player.cs new file mode 100644 index 0000000..ece1960 --- /dev/null +++ b/CourseApp/Player.cs @@ -0,0 +1,167 @@ +using System; + +namespace CourseApp +{ + public class Player + { + private int health; + private int power; + private string name; + private bool isOnFire = false; + private bool frozen; + private int defaultHealth; + private int defaultPower; + + public Player(string name) + { + this.Name = name; + Random random = new Random(); + this.defaultHealth = random.Next(40, 70); + this.Health = this.defaultHealth; + this.defaultPower = random.Next(10, 20); + this.Power = this.defaultPower; + } + + public int Health + { + get + { + return health; + } + + set + { + if (value < 0) + { + throw new InvalidOperationException("Не верное значение"); + } + else + { + health = value; + } + } + } + + public int Power + { + get + { + return power; + } + + set + { + if (value < 0) + { + throw new InvalidOperationException("Не верное значение"); + } + else + { + power = value; + } + } + } + + public string Name + { + get + { + return name; + } + + set + { + if (value == " ") + { + Console.WriteLine("Нет значения"); + } + else + { + name = value; + } + } + } + + public virtual bool Frozen + { + get + { + return frozen; + } + + set + { + value = false; + } + } + + public virtual int DealDamage(bool useUlt) + { + return Power; + } + + public virtual int GetDamage(int damage, string type) + { + if (Health - damage < 0) + { + Health = 0; + this.isOnFire = false; + } + else + { + Health -= damage; + } + + if (this.isOnFire && type == "Archer") + { + return Health - 2; + } + + if (damage == 0 && type == "Archer") + { + this.isOnFire = true; + } + + if (this.frozen = true && type == "Magician") + { + this.frozen = false; + } + + if (damage == 0 && type == "Magician") + { + this.frozen = true; + } + + return Health; + } + + public virtual bool UseUlt() + { + Random a = new Random(); + int powerA = a.Next(1, 4); + return powerA == 2; + } + + public int GetHealth() + { + return Health; + } + + public int GetPower() + { + return Power; + } + + public string GetName() + { + return Name; + } + + public void RestoreStats() + { + this.Health = this.defaultHealth; + this.Power = this.defaultPower; + this.isOnFire = false; + } + } +} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index be6f5e4..d60caea 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,93 +1,125 @@ using System; +using System.Threading; +using System.Collections.Generic; namespace CourseApp { public class Program { - public static double Calc(double a, double b, double x) - { - var numerator = Math.Log(Math.Abs(Math.Pow(b, 2) - Math.Pow(x, 2)), a); - var denominator = Math.Abs(Math.Pow(x, 2) - Math.Pow(a, 2)); - CubeRoot(denominator); - var y = numerator / denominator; - return y; - } - - public static (double x, double y)[] TaskA(double a, double b, double xn, double xk, double dx) + public static void Main(string[] args) { - var res = new(double, double)[(int)Math.Ceiling((xk - xn) / dx) + 1]; - int i = 0; - for (var x = xn; x <= xk; x += dx) + Console.Write("Введите кол-во героев: "); + int number = Convert.ToInt16(Console.ReadLine()); + Console.WriteLine(); + List type = new List(); + List excess = new List(); + List hero = new List(number); + string[] nameArray = new string[20] { "Player_1", "Player_2", "Player_3", "Player_4", "Player_5", "Player_6", "Player_7", "Player_8", "Player_9", "Player_10", "Player_11", "Player_12", "Player_13", "Player_14", "Player_15", "Player_16", "Player_17", "Player_18", "Player_19", "Player_20" }; + if (number % 2.0 != 0) { - var y = Calc(a, b, x); - res[i] = (x, y); - i++; + throw new InvalidOperationException("Число героев нечетное"); } - return res; - } - - public static (double x, double y)[] TaskB(double a, double b, double[] xItems) - { - var res = new(double, double)[xItems.Length]; - int i = 0; - foreach (var x in xItems) + for (int i = 0; i < number; i++) { - var y = Calc(a, b, x); - res[i] = (x, y); - i++; + Random random = new Random(); + string name = nameArray[random.Next(0, 19)]; + type.Add(GetHeroType()); + switch (type[i]) + { + case "Knight": + hero.Add(new Knight(name)); + break; + case "Archer": + hero.Add(new Archer(name)); + break; + case "Magician": + hero.Add(new Magician(name)); + break; + } } - return res; - } - - public static void Main(string[] args) - { - const double a = 2.0; - const double b = 1.1; - Console.WriteLine($"--------- TASK A --------------"); - var taskA = TaskA(a, b, 0.08, 1.08, 0.2); - foreach (var item in taskA) + while (number > 1) { - var(x, y) = item; - Console.WriteLine($"x={x}, y={y}"); - } + bool isExcessHero = false; + if (hero.Count % 2.0 != 0) + { + excess.Add(hero[hero.Count - 1]); + hero.RemoveAt(hero.Count - 1); + isExcessHero = true; + } - Console.WriteLine($"--------- TASK B --------------"); - double[] xItems = { 0.1, 0.3, 0.4, 0.45, 0.65 }; - var taskB = TaskB(a, b, xItems); - foreach (var item in taskB) - { - var(x, y) = item; - Console.WriteLine($"x={x}, y={y}"); - } + for (int i = 0; i < hero.Count; i = i + 2) + { + Console.WriteLine($"Игрок: {hero[i].GetName()} класса {type[i]} cила = {hero[i].GetPower()}, ХР = {hero[i].GetHealth()} против Игрока: {hero[i + 1].GetName()} класса {type[i + 1]}, сила = {hero[i + 1].GetPower()} , ХР = {hero[i + 1].GetHealth()}"); + Console.ReadKey(); + int step = 0; + while (hero[i].GetHealth() > 0 && hero[i + 1].GetHealth() > 0) + { + Console.WriteLine($"{hero[i + step].GetName()} наносит урон игроку {hero[i + 1 - step].GetName()}"); + if (!hero[i + step].Frozen) + { + hero[i + 1 - step].GetDamage(hero[i + step].DealDamage(hero[i + step].UseUlt()), type[i + step]); + Thread.Sleep(100); + } - Console.WriteLine("Hello World!"); + Console.WriteLine($"Игрок {hero[i + 1 - step].GetName()}, XP = {hero[i + 1 - step].GetHealth()} "); + step = (step + 1) % 2; + Thread.Sleep(100); + } - var country1 = new Country(); - country1.AllInfo(); - var country2 = new Country(7420, 40, 185.5); - country2.AllInfo(); - country2.Population = 0; - var country3 = new Country(13450, 100, 134.5); - country3.PopulationInfo(); - country3.AreaInfo(); - country3.DensityInfo(); - var union1 = new Union(5); - union1.UnionInfo(); + if (hero[i].GetHealth() <= 0) + { + Console.WriteLine($"Игрок {hero[i + 1].GetName()} победил"); + Console.WriteLine(); + Console.ReadKey(); + } - Console.ReadKey(); - } + if (hero[i + 1].GetHealth() <= 0) + { + Console.WriteLine($"Игрок {hero[i].GetName()} победил"); + Console.WriteLine(); + Console.ReadKey(); + } + } - public static double CubeRoot(double x) - { - if (x < 0) + if (isExcessHero) { - return -Math.Pow(-x, 1d / 5d); + hero.Add(excess[0]); + excess.RemoveAt(0); + isExcessHero = false; } - else + + int j = 0; + while (j < hero.Count) + { + if (hero[j].GetHealth() <= 0) + { + hero.RemoveAt(j); + } + else + { + hero[j].RestoreStats(); + j++; + } + } + + number = Convert.ToInt16(number / 2.0); + } + } + + private static string GetHeroType() + { + Random type = new Random(); + int typeHero = type.Next(1, 3); + switch (typeHero) { - return Math.Pow(x, 1d / 5d); + case 1: + return "Knight"; + case 2: + return "Archer"; + default: + return "Magician"; } } } diff --git a/README.md b/README.md index b389250..b9d8f94 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # Tprogramming_42_2020 -## Boleslav_Piguta \ No newline at end of file +## Boleslav_Piguta +>https://github.com/MrColteR/sitee \ No newline at end of file