diff --git a/CourseApp.Tests/CharacterTest.cs b/CourseApp.Tests/CharacterTest.cs new file mode 100644 index 0000000..9c201d6 --- /dev/null +++ b/CourseApp.Tests/CharacterTest.cs @@ -0,0 +1,134 @@ +namespace CourseApp.Tests +{ + using Character; + using Xunit; + + public class CharacterTest + { + [Fact] + + public void TestGur() + { + var guard = new Guardian("Leo", "zweihender", 95); + Assert.Equal("zweihender", guard.TypeOfWeapon); + Assert.Equal(95, guard.Lvl); + } + + [Fact] + + public void TestMag() + { + var magian = new TheMagian("Rise", "CristalStaff", 85); + Assert.Equal("Rise", magian.Name); + Assert.Equal("CristalStaff", magian.TypeOfWeapon); + Assert.Equal(85, magian.Lvl); + } + + [Fact] + + public void TestArcher() + { + var archer = new Archer("Azir", "Black Onion", 79); + Assert.Equal("Azir", archer.Name); + Assert.Equal("Black Onion", archer.TypeOfWeapon); + Assert.Equal(79, archer.Lvl); + } + + [Fact] + + public void TestArcherGetInfo() + { + var arch = new Archer("Azir", "Black Onion", 79); + var res = arch.GetInfo(); + Assert.Equal("Я заступил на службу в 12:00 ", res); + Character archer = arch; // ссылка типа базового класса на дочерний + Assert.Equal(res, archer.GetInfo()); + } + + [Fact] + + public void TestGuardianGetInfo() + { + var guar = new Guardian("Leo", "zweihender", 95); + var rs = guar.GetInfo(); + Assert.Equal("Я работаю в элитных войсках короля Людовика 2 ", rs); + Character guard = guar; + Assert.Equal(rs, guard.GetInfo()); + } + + [Fact] + + public void TestTheMagianGetInfo() + { + var mag = new TheMagian("Rise", "CristalStaff", 85); + var result = mag.GetInfo(); + Assert.Equal("Я служу для защиты нашего прекрасного замка ", result); + Character magian = mag; + Assert.Equal(result, magian.GetInfo()); + } + + [Fact] + public void TestTheMagianToString() + { + var mag = new TheMagian("Rise", "CristalStaff", 85); + var result = mag.ToString(); + Assert.Equal("Какой же красивый замок", result); + Character magian = mag; + Assert.Equal(result, magian.ToString()); + } + + [Fact] + + public void TestArcherToString() + { + var ar = new Archer("Azir", "Black Onion", 79); + var resul = ar.ToString(); + Assert.Equal("Ура у меня всё хорошо!", resul); + Character arc = ar; + Assert.Equal(resul, arc.ToString()); + } + + [Fact] + + public void TestGuardianToString() + { + var gurd = new Guardian("Leo", "zweihender", 95); + var resul = gurd.ToString(); + Assert.Equal("Как хорошо, что меня ещё не уволили)", resul); + Character gur = gurd; + Assert.Equal(resul, gur.ToString()); + } + + [Fact] + + public void TestGuardianGuild() + { + var guard = new Guardian("Leo", "zweihender", 95); + var result = guard.Guild(); + Assert.Equal("я состою в гильдии Пылающий Вепрь", result); + Character gur = guard; + Assert.Equal(result, gur.Guild()); + } + + [Fact] + + public void TestArcherGuild() + { + var archer = new Archer("Azir", "Black Onion", 79); + var resul = archer.Guild(); + Assert.Equal("я состою в гильдии Милость Дриады", resul); + Character arc = archer; + Assert.Equal(resul, arc.Guild()); + } + + [Fact] + public void TestTheMagianGuild() + { + var mag = new TheMagian("Rise", "CristalStaff", 85); + var result = mag.Guild(); + Assert.Equal("я состою в гильдии Банши", result); + Character magian = mag; + Assert.Equal(result, magian.Guild()); + } + } +} diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs deleted file mode 100644 index cf7cbb1..0000000 --- a/CourseApp.Tests/DemoTest.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace CourseApp.Tests -{ - using Xunit; - - public class DemoTest - { - [Fact] - public void Test1() - { - Assert.True(true); - } - } -} diff --git a/CourseApp/Character/Archer.cs b/CourseApp/Character/Archer.cs new file mode 100644 index 0000000..46c5cdb --- /dev/null +++ b/CourseApp/Character/Archer.cs @@ -0,0 +1,54 @@ +namespace Character; + +using System; + +public class Archer : Character +{ + private static string bw = "Bow of the erd tree"; + + public Archer(string name, string typeOfWeapon, int lvl) + : base(name, typeOfWeapon, lvl) + { + } + + public static void Bow(string bow) + { + if (bow == bw) + { + Ability(100); + } + else + { + Ability(80); + } + } + + public static void Ability(int arrows) + { + if (arrows < 90) + { + Console.WriteLine("Azir тебе разрешено защищать только стены города"); + Console.WriteLine(); + } + else + { + Console.WriteLine("Azir тебе разрешено защищать саму принцессу"); + Console.WriteLine(); + } + } + + public override string Guild() + { + return "я состою в гильдии Милость Дриады"; + } + + public override string GetInfo() + { + return $"Я заступил на службу в 12:00 "; + } + + public override string ToString() + { + return "Ура у меня всё хорошо!"; + } +} \ No newline at end of file diff --git a/CourseApp/Character/Character.cs b/CourseApp/Character/Character.cs new file mode 100644 index 0000000..7bb3f89 --- /dev/null +++ b/CourseApp/Character/Character.cs @@ -0,0 +1,60 @@ +namespace Character; + +using System; + +public abstract class Character +{ + private int level; + + public Character(string name, string typeOfWeapon, int lvl) + { + this.Name = name; + this.TypeOfWeapon = typeOfWeapon; + this.Lvl = lvl; + } + + public int Lvl + { + get + { + return level; + } + + set + { + if (level < value) + { + level = value; + } + } + } + + public string TypeOfWeapon { get; set; } + + public string Name { get; set; } + + public void Print() + { + Console.Write($"{Name} {Lvl} {TypeOfWeapon}"); + } + + public virtual string Guild() + { + return "1535"; + } + + /*public void MaxLevel() + { + Console.WriteLine($"Ваш уровень {Lvl} /99"); + } + + public void Damag() + { + Console.WriteLine($"Вам выпало легендарный оружие {TypeOfWeapon}"); + }*/ + + public virtual string GetInfo() + { + return "54891"; + } +} diff --git a/CourseApp/Character/Guardian.cs b/CourseApp/Character/Guardian.cs new file mode 100644 index 0000000..55521ff --- /dev/null +++ b/CourseApp/Character/Guardian.cs @@ -0,0 +1,40 @@ +namespace Character; + +using System; + +public class Guardian : Character +{ + public Guardian(string name, string typeOfWeapon, int lvl) + : base(name, typeOfWeapon, lvl) + { + } + + public void Protect(bool protect) + { + if (protect != true) + { + Console.WriteLine("Я не защищаю принцессу"); + Console.WriteLine(); + } + else + { + Console.WriteLine("Я защищаю принцессу"); + Console.WriteLine(); + } + } + + public override string Guild() + { + return "я состою в гильдии Пылающий Вепрь"; + } + + public override string GetInfo() + { + return $"Я работаю в элитных войсках короля Людовика 2 "; + } + + public override string ToString() + { + return "Как хорошо, что меня ещё не уволили)"; + } +} \ No newline at end of file diff --git a/CourseApp/Character/TheMagian.cs b/CourseApp/Character/TheMagian.cs new file mode 100644 index 0000000..4200078 --- /dev/null +++ b/CourseApp/Character/TheMagian.cs @@ -0,0 +1,40 @@ +namespace Character; + +using System; + +public class TheMagian : Character +{ + public TheMagian(string name, string typeOfWeapon, int lvl) + : base(name, typeOfWeapon, lvl) + { + } + + public void Opponent(int grupOfOpponent) + { + if (grupOfOpponent < 40) + { + Console.WriteLine($"Им не нужна моя помощь"); + Console.WriteLine(); + } + else + { + Console.WriteLine($"Им нужна моя помощь"); + Console.WriteLine(); + } + } + + public override string Guild() + { + return "я состою в гильдии Банши"; + } + + public override string GetInfo() + { + return $"Я служу для защиты нашего прекрасного замка "; + } + + public override string ToString() + { + return "Какой же красивый замок"; + } +} \ No newline at end of file diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index eb22147..1a102aa 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -1,9 +1,11 @@ + Exe net6.0 True + preview diff --git a/CourseApp/Phone.cs b/CourseApp/Phone.cs new file mode 100644 index 0000000..6415a98 --- /dev/null +++ b/CourseApp/Phone.cs @@ -0,0 +1,38 @@ +/*namespace CourseApp +{ + using System; + + public class Phone + { + private float diaonal; + + public Phone(string name, float diagonal) + { + Name = name; + Diagonal = diagonal; + } + + public string Name { get; set; } + + public float Diagonal + { + get + { + return diaonal; + } + + set + { + if (value > 0 && value < 20) + { + this.diaonal = value; + } + } + } + + public void Show() + { + Console.WriteLine($"{Name} with diagonal {diaonal}"); + } + } +}*/ \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index d6d2c87..f9af896 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,12 +1,47 @@ -namespace CourseApp +/* +namespace CourseApp { using System; + using System.Collections.Generic; + using Character; + using CourseApp.RPGSaga; public class Program { public static void Main(string[] args) { - Console.WriteLine("Hello World"); + Knight knight = new ("Nasus", 300, 5); + knight.Print(); + knight.Ability(); + /*Archer archer = new ("Azir", "Black Onion", 79); + TheMagian magian = new ("Rise", "CristalStaff", 85); + Guardian guard = new ("Leo", "zweihender", 95); + + var characterList = new List + { + archer, + magian, + guard, + }; + + foreach (var character in characterList) + { + character.Print(); + Console.WriteLine(character.Guild()); + Console.WriteLine(character.GetInfo()); + Console.WriteLine(character.ToString()); + }#1# } } } +*/ +namespace CourseApp +{ + public class Program + { + public static void Main(string[] args) + { + Game.Start(); + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Game.cs b/CourseApp/RPGSaga/Game.cs new file mode 100644 index 0000000..08be550 --- /dev/null +++ b/CourseApp/RPGSaga/Game.cs @@ -0,0 +1,152 @@ +namespace CourseApp +{ + using System; + using System.Collections.Generic; + using System.Linq; + + public class Game + { + public static void Start() + { + int p_number = AskNumber(); + List playerList = PlayerListGenerator(p_number); + RandomizeList(playerList); + PlayGame(playerList); + } + + private static void PlayGame(List playerList) + { + for (int i = 1; playerList.Count != 1; i++) + { + Logger.WriteRound(i); + PlayRound(playerList); + } + + Logger.WriteWinner(playerList[0]); + } + + private static void PlayRound(List playerList) + { + for (int i = 0; i < playerList.Count / 2; i++) + { + Player[] fightMembers = { playerList[i * 2], playerList[(i * 2) + 1] }; + Logger.WriteFight(fightMembers); + playerList[i * 2] = PlayFight(fightMembers); + } + + for (int i = 1; i < playerList.Count; i++) + { + playerList.RemoveAt(i); + } + } + + private static Player PlayFight(Player[] fightMembers) + { + for (int i = 0; true; i++) + { + var playerStatus = fightMembers[i % 2].CheckStatus(); + Logger.WriteAction(fightMembers[i % 2], playerStatus); + bool checkDeath = fightMembers[i % 2].GetDamage(playerStatus.Item2); + if (checkDeath) + { + Logger.WriteDeath(fightMembers[i % 2]); + fightMembers[(i + 1) % 2].Update(); + return fightMembers[(i + 1) % 2]; + } + + if (playerStatus.Item1 == "Заворожение") + { + continue; + } + + Tuple playerAction = PlayerDoAction(fightMembers[i % 2]); + Logger.WriteAction(fightMembers[i % 2], fightMembers[(i + 1) % 2], playerAction); + checkDeath = fightMembers[(i + 1) % 2].GetDamage(playerAction.Item2); + Logger.WriteDeath(fightMembers[(i + 1) % 2]); + if (checkDeath) + { + fightMembers[i % 2].Update(); + return fightMembers[i % 2]; + } + } + } + + private static Tuple PlayerDoAction(Player inputP) + { + Random rnd = new Random(); + int chosen = rnd.Next(0, 5); + switch (chosen) + { + case 0: + return inputP.Ability(); + default: + return inputP.Attack(); + } + } + + private static int AskNumber() + { + while (true) + { + Console.WriteLine("Введите четное количество игроков:"); + int p_number = Convert.ToInt32(Console.ReadLine()); + if (p_number <= 0) + { + Console.WriteLine("Число игроков должно быть больше 0!"); + } + else if (p_number % 2 != 0) + { + Console.WriteLine("Число игроков должно быть четным!"); + } + else + { + return p_number; + } + } + } + + private static void RandomizeList(List input) + { + Random rnd = new Random(); + var buffer = input.ToArray(); + for (int i = 0; i < input.Count; i++) + { + int chosen = rnd.Next(i, buffer.Length); + (buffer[i], buffer[chosen]) = (buffer[chosen], buffer[i]); + } + + input = buffer.ToList(); + } + + private static List PlayerListGenerator(int count) + { + List playerList = new List(); + for (int i = 0; i < count; i++) + { + playerList.Add(PlayerGenerator()); + } + + return playerList; + } + + private static Player PlayerGenerator() + { + string[] names = { "Ворибун", "Траструл", "Гетеамит", "Брернулуг", "Лиокандер", "Отауф", "Накама", "Берта", "Сордиан", "Скраврол", "Силеоес", "Ида", "Давид" }; + Random rnd = new Random(); + int health = (int)rnd.NextInt64(1, 100); + int strength = (int)rnd.NextInt64(1, 50); + int chouse = (int)rnd.NextInt64(0, 3); + switch (chouse) + { + case 0: + return new Knight(health, strength, names[rnd.Next(names.Length)]); + case 1: + return new Mage(health, strength, names[rnd.Next(names.Length)]); + case 2: + return new Archer(health, strength, names[rnd.Next(names.Length)]); + default: + return new Knight(health, strength, names[rnd.Next(names.Length)]); + } + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/GameClasses/Archer.cs b/CourseApp/RPGSaga/GameClasses/Archer.cs new file mode 100644 index 0000000..3769ad7 --- /dev/null +++ b/CourseApp/RPGSaga/GameClasses/Archer.cs @@ -0,0 +1,30 @@ +namespace CourseApp +{ + using System; + + public class Archer : Player + { + public Archer(int health, int strength, string name) + : base(health, strength, name, "Огненные стрелы", 1) + { + } + + public override string ToString() + { + return "(Лучник) " + Name; + } + + public override Tuple Ability() + { + if (AbilityLeft > 0) + { + AbilityLeft--; + return Tuple.Create(AbilityName, 0.0f); + } + else + { + return Attack(); + } + } + } +} diff --git a/CourseApp/RPGSaga/GameClasses/Knight.cs b/CourseApp/RPGSaga/GameClasses/Knight.cs new file mode 100644 index 0000000..426c5d7 --- /dev/null +++ b/CourseApp/RPGSaga/GameClasses/Knight.cs @@ -0,0 +1,30 @@ +namespace CourseApp +{ + using System; + + public class Knight : Player + { + public Knight(int health, int strength, string name) + : base(health, strength, name, "Удар возмездия", 1) + { + } + + public override string ToString() + { + return "(Рыцарь) " + Name; + } + + public override Tuple Ability() + { + if (AbilityLeft > 0) + { + AbilityLeft--; + return Tuple.Create(AbilityName, Strength * 1.3f); + } + else + { + return Attack(); + } + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/GameClasses/Mage.cs b/CourseApp/RPGSaga/GameClasses/Mage.cs new file mode 100644 index 0000000..3a949a9 --- /dev/null +++ b/CourseApp/RPGSaga/GameClasses/Mage.cs @@ -0,0 +1,30 @@ +namespace CourseApp +{ + using System; + + public class Mage : Player + { + public Mage(int health, int strength, string name) + : base(health, strength, name, "Заворожение", 1) + { + } + + public override string ToString() + { + return "(Маг) " + Name; + } + + public override Tuple Ability() + { + if (AbilityLeft > 0) + { + AbilityLeft--; + return Tuple.Create(AbilityName, 0.0f); + } + else + { + return Attack(); + } + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Logger.cs b/CourseApp/RPGSaga/Logger.cs new file mode 100644 index 0000000..276e4da --- /dev/null +++ b/CourseApp/RPGSaga/Logger.cs @@ -0,0 +1,61 @@ +namespace CourseApp +{ + using System; + using System.Collections.Generic; + + public static class Logger + { + public static void WriteWinner(Player winner) + { + Console.WriteLine($"{winner.ToString()} ПОБЕДИЛ!"); + } + + public static void WriteRound(int round) + { + Console.WriteLine($"Раунд {round}."); + } + + public static void WriteFight(Player[] fightMembers) + { + Console.WriteLine($"{fightMembers[0].ToString()} VS {fightMembers[1].ToString()}"); + } + + public static void WriteAction(Player firstP, Player secondP, Tuple playerAction) + { + switch (playerAction.Item1) + { + case "наносит урон": + Console.WriteLine($"{firstP.ToString()} наносит урон {playerAction.Item2} противнику {secondP.ToString()}"); + break; + case "Удар возмездия": + Console.WriteLine($"{firstP.ToString()} применяет ({playerAction.Item1}) и наносит урон {playerAction.Item2} противнику {secondP.ToString()}"); + break; + case "Огненная стрела": + Console.WriteLine($"{firstP.ToString()} применяет ({playerAction.Item1}) по противнику {secondP.ToString()}"); + break; + case "Заворожение": + Console.WriteLine($"{firstP.ToString()} применяет ({playerAction.Item1}) по противнику {secondP.ToString()}"); + break; + } + } + + public static void WriteAction(Player inputP, Tuple playerStatus) + { + switch (playerStatus.Item1) + { + case "Огненная стрела": + Console.WriteLine($"{inputP.ToString()} получает периодический урон {playerStatus.Item2} от ({playerStatus.Item1})"); + break; + case "Заворожение": + Console.WriteLine($"{inputP.ToString()} пропускает ход из-за ({playerStatus.Item1})"); + break; + } + } + + public static void WriteDeath(Player inputP) + { + Console.WriteLine($"{inputP.ToString()} погибает"); + Console.WriteLine(); + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Player.cs b/CourseApp/RPGSaga/Player.cs new file mode 100644 index 0000000..a05447e --- /dev/null +++ b/CourseApp/RPGSaga/Player.cs @@ -0,0 +1,83 @@ +namespace CourseApp +{ + using System; + using System.Collections.Generic; + + public abstract class Player + { + private string debaffs; + + public Player(int maxHealth, int strength, string name, string abilityName, int maxAbilityUsages) + { + this.MaxHealth = maxHealth; + this.CurrentHealth = maxHealth; + this.Strength = strength; + this.Name = name; + this.AbilityName = abilityName; + this.MaxAbilityUsages = maxAbilityUsages; + } + + public float MaxHealth { get; protected set; } + + public float CurrentHealth { get; protected set; } + + public float Strength { get; protected set; } + + public string Name { get; protected set; } + + public int MaxAbilityUsages { get; protected set; } + + public int AbilityLeft { get; protected set; } + + public string AbilityName { get; protected set; } + + public abstract Tuple Ability(); + + public Tuple Attack() + { + return Tuple.Create("наносит урон", Strength); + } + + public bool GetDamage(float damage) + { + CurrentHealth -= damage; + return CheckDeath(); + } + + public void SetDebaff(string debuffName) + { + debaffs = debuffName; + } + + public Tuple CheckStatus() + { + switch (debaffs) + { + case "Огненная стрела": + return Tuple.Create("Огненная стрела", 2.0f); + case "Заворожение": + debaffs = string.Empty; + return Tuple.Create("Заворожение", .0f); + default: + return Tuple.Create(" ", .0f); + } + } + + public bool CheckDeath() + { + if (CurrentHealth <= 0) + { + return true; + } + + return false; + } + + public void Update() + { + AbilityLeft = MaxAbilityUsages; + CurrentHealth = MaxHealth; + debaffs = string.Empty; + } + } +} \ No newline at end of file diff --git a/global.json b/global.json new file mode 100644 index 0000000..7cd6a1f --- /dev/null +++ b/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "7.0.0", + "rollForward": "latestMajor", + "allowPrerelease": true + } +} \ No newline at end of file