From 91356be7a5f615850f489794a4466f1ba60dc58f Mon Sep 17 00:00:00 2001 From: Sasha1602 Date: Sat, 17 Sep 2022 14:15:18 +0300 Subject: [PATCH 01/11] =?UTF-8?q?=D0=A8=D0=BA=D0=B0=D1=80=D0=BF=D0=B8?= =?UTF-8?q?=D1=86=D0=BA=D0=B8=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0?= =?UTF-8?q?=D0=BD=D0=B4=D1=80=202/42?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CourseApp/Character.cs | 47 ++++++++++++++++++++++++++++++++++++++++++ CourseApp/Program.cs | 11 +++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 CourseApp/Character.cs diff --git a/CourseApp/Character.cs b/CourseApp/Character.cs new file mode 100644 index 0000000..5324707 --- /dev/null +++ b/CourseApp/Character.cs @@ -0,0 +1,47 @@ +namespace CourseApp; + +using System; + +public class Character +{ + private int level; + + private string clas; + public int Lvl { + get + { + return level; + } + set + { + if (level < value) + { + level = value; + } + } + } + private string TypeOfWeapon; + + public Character(string TypeOfWeapon) : this("guardian", TypeOfWeapon, 60) + {} + public Character(string clas, string TypeOfWeapon, int Lvl) + { + this.clas = clas; + this.TypeOfWeapon = TypeOfWeapon; + this.Lvl = Lvl; + } + public void Print() + { + Console.WriteLine($"Ваши характеристи на данный момент \n {clas} {Lvl} {TypeOfWeapon}"); + } + + public void MaxLevel() + { + Console.WriteLine($"Ваш уровень {Lvl} /99"); + } + + public void Damag() + { + Console.WriteLine($"Вам выпало легендарный оружие {TypeOfWeapon}"); + } +} diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index d6d2c87..819dff3 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -6,7 +6,16 @@ public class Program { public static void Main(string[] args) { - Console.WriteLine("Hello World"); + Character gur = new("zweihender"); + Character mag = new("Magian", "crystal staf", 58); + Console.WriteLine($"lev= {mag.Lvl}"); + + mag.MaxLevel(); + mag.Damag(); + mag.Print(); + + gur.Damag(); + gur.Print(); } } } From 980402ba11a1d9c207f6b1cb9b31ed590eeff5c2 Mon Sep 17 00:00:00 2001 From: Sasha1602 Date: Sat, 17 Sep 2022 14:55:20 +0300 Subject: [PATCH 02/11] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BD=D0=BE=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CourseApp/Character.cs | 28 ++++++++++++++++++---------- CourseApp/Program.cs | 6 +++--- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/CourseApp/Character.cs b/CourseApp/Character.cs index 5324707..5e31cb1 100644 --- a/CourseApp/Character.cs +++ b/CourseApp/Character.cs @@ -7,11 +7,26 @@ public class Character private int level; private string clas; - public int Lvl { + + public Character(string typeOfWeapon) + : this("guardian", typeOfWeapon, 60) + { + } + + public Character(string clas, string typeOfWeapon, int lvl) + { + this.clas = clas; + this.TypeOfWeapon = typeOfWeapon; + this.Lvl = lvl; + } + + public int Lvl + { get { return level; } + set { if (level < value) @@ -20,16 +35,9 @@ public int Lvl { } } } - private string TypeOfWeapon; - public Character(string TypeOfWeapon) : this("guardian", TypeOfWeapon, 60) - {} - public Character(string clas, string TypeOfWeapon, int Lvl) - { - this.clas = clas; - this.TypeOfWeapon = TypeOfWeapon; - this.Lvl = Lvl; - } + public string TypeOfWeapon { get; set; } + public void Print() { Console.WriteLine($"Ваши характеристи на данный момент \n {clas} {Lvl} {TypeOfWeapon}"); diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 819dff3..abbb2af 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -6,14 +6,14 @@ public class Program { public static void Main(string[] args) { - Character gur = new("zweihender"); - Character mag = new("Magian", "crystal staf", 58); + Character gur = new ("zweihender"); + Character mag = new ("Magian", "crystal staf", 58); Console.WriteLine($"lev= {mag.Lvl}"); mag.MaxLevel(); mag.Damag(); mag.Print(); - + gur.Damag(); gur.Print(); } From 63acd9c9a05071512016d53112264bd57be87904 Mon Sep 17 00:00:00 2001 From: Sasha1602 Date: Tue, 20 Sep 2022 14:42:57 +0300 Subject: [PATCH 03/11] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D0=BD=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=20=D1=81=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0?= =?UTF-8?q?=D0=BC=D0=B8=20=D0=A8=D0=BA=D0=B0=D1=80=D0=BF=D0=B8=D1=86=D0=BA?= =?UTF-8?q?=D0=B8=D0=B9=202/42?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CourseApp/Character.cs | 14 ++++++++------ CourseApp/CourseApp.csproj | 1 + CourseApp/Program.cs | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CourseApp/Character.cs b/CourseApp/Character.cs index 5e31cb1..09d8837 100644 --- a/CourseApp/Character.cs +++ b/CourseApp/Character.cs @@ -6,16 +6,16 @@ public class Character { private int level; - private string clas; - - public Character(string typeOfWeapon) - : this("guardian", typeOfWeapon, 60) + public Character(string typeOfWeapon, int lvl) { + Clas = "Guardian"; + this.TypeOfWeapon = typeOfWeapon; + this.level = lvl; } public Character(string clas, string typeOfWeapon, int lvl) { - this.clas = clas; + this.Clas = clas; this.TypeOfWeapon = typeOfWeapon; this.Lvl = lvl; } @@ -38,9 +38,11 @@ public int Lvl public string TypeOfWeapon { get; set; } + public string Clas { get; set; } + public void Print() { - Console.WriteLine($"Ваши характеристи на данный момент \n {clas} {Lvl} {TypeOfWeapon}"); + Console.WriteLine($"Ваши характеристи на данный момент \n {Clas} {Lvl} {TypeOfWeapon}"); } public void MaxLevel() diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index eb22147..82ed6ac 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -1,3 +1,4 @@ + diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index abbb2af..493ea0c 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -6,7 +6,7 @@ public class Program { public static void Main(string[] args) { - Character gur = new ("zweihender"); + Character gur = new ("zweihender", 60); Character mag = new ("Magian", "crystal staf", 58); Console.WriteLine($"lev= {mag.Lvl}"); From c9af1dfec15ffe8b6f5f9ac15099bef700141597 Mon Sep 17 00:00:00 2001 From: Sasha1602 Date: Tue, 20 Sep 2022 14:43:23 +0300 Subject: [PATCH 04/11] =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=A8?= =?UTF-8?q?=D0=BA=D0=B0=D1=80=D0=BF=D0=B8=D1=86=D0=BA=D0=B8=D0=B9=202/42?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CourseApp.Tests/CharacterTest.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 CourseApp.Tests/CharacterTest.cs diff --git a/CourseApp.Tests/CharacterTest.cs b/CourseApp.Tests/CharacterTest.cs new file mode 100644 index 0000000..feb70f5 --- /dev/null +++ b/CourseApp.Tests/CharacterTest.cs @@ -0,0 +1,26 @@ +namespace CourseApp.Tests +{ + using Xunit; + + public class CharacterTest + { + [Fact] + + public void TestGur() + { + var gur = new Character("zweihender", 60); + Assert.Equal("zweihender", gur.TypeOfWeapon); + Assert.Equal(60, gur.Lvl); + } + + [Fact] + + public void TestMag() + { + var mag = new Character("Magian", "crystal staf", 58); + Assert.Equal("Magian", mag.Clas); + Assert.Equal("crystal staf", mag.TypeOfWeapon); + Assert.Equal(58, mag.Lvl); + } + } +} From 2d08eaf98fde00b52f35243842f1b569d701d51c Mon Sep 17 00:00:00 2001 From: Sasha1602 Date: Sat, 8 Oct 2022 14:29:13 +0300 Subject: [PATCH 05/11] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CourseApp.Tests/DemoTest.cs | 13 ------------- CourseApp/Archer.cs | 37 +++++++++++++++++++++++++++++++++++++ CourseApp/Character.cs | 2 +- CourseApp/CourseApp.csproj | 2 +- CourseApp/Guardian.cs | 23 +++++++++++++++++++++++ CourseApp/Program.cs | 6 ++++++ 6 files changed, 68 insertions(+), 15 deletions(-) delete mode 100644 CourseApp.Tests/DemoTest.cs create mode 100644 CourseApp/Archer.cs create mode 100644 CourseApp/Guardian.cs 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/Archer.cs b/CourseApp/Archer.cs new file mode 100644 index 0000000..dcef223 --- /dev/null +++ b/CourseApp/Archer.cs @@ -0,0 +1,37 @@ +namespace CourseApp; + +using System; + +public class Archer : Character +{ + public Archer(string clas, string typeOfWeapon, int lvl) + : base(clas, typeOfWeapon, lvl) + { + } + + private string bw = "Bow of the erd tree"; + + public void Bow(string bow) + { + if (bow == bw) + { + Ability(100); + } + else + { + Ability(80); + } + } + + public void Ability(int arrows) + { + if (arrows < 90) + { + Console.WriteLine("Тебе разрешено защищать только стены города"); + } + else + { + Console.WriteLine("Тебе разрешено защищать саму принцессу"); + } + } +} \ No newline at end of file diff --git a/CourseApp/Character.cs b/CourseApp/Character.cs index 09d8837..0cb26a2 100644 --- a/CourseApp/Character.cs +++ b/CourseApp/Character.cs @@ -10,7 +10,7 @@ public Character(string typeOfWeapon, int lvl) { Clas = "Guardian"; this.TypeOfWeapon = typeOfWeapon; - this.level = lvl; + this.Lvl = lvl; } public Character(string clas, string typeOfWeapon, int lvl) diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index 82ed6ac..f5c84ea 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -4,7 +4,7 @@ Exe net6.0 - True + False diff --git a/CourseApp/Guardian.cs b/CourseApp/Guardian.cs new file mode 100644 index 0000000..f7b338b --- /dev/null +++ b/CourseApp/Guardian.cs @@ -0,0 +1,23 @@ +namespace CourseApp; + +using System; + +public class Guardian : Character +{ + public Guardian(string typeOfWeapon, int lvl) + : base(typeOfWeapon, lvl) + { + } + + public void Protect(bool protect) + { + if (protect != true) + { + Console.WriteLine("Я не защищаю принцессу"); + } + else + { + Console.WriteLine("Я защищаю принцессу"); + } + } +} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 493ea0c..50e8055 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -9,6 +9,8 @@ public static void Main(string[] args) Character gur = new ("zweihender", 60); Character mag = new ("Magian", "crystal staf", 58); Console.WriteLine($"lev= {mag.Lvl}"); + Guardian guardian = new Guardian("zweihender", 90); + Archer archer = new Archer("Archer", "Black Onion", 79); mag.MaxLevel(); mag.Damag(); @@ -16,6 +18,10 @@ public static void Main(string[] args) gur.Damag(); gur.Print(); + guardian.Print(); + guardian.Protect(true); + + archer.Bow("Bow of the erd tree"); } } } From fd243f7d2e4d2c52142cb2310b72b5380b27f4a0 Mon Sep 17 00:00:00 2001 From: Sasha1602 Date: Sat, 8 Oct 2022 14:31:31 +0300 Subject: [PATCH 06/11] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=20=D0=BF=D0=B5=D1=80=D0=B2?= =?UTF-8?q?=D0=BE=D0=BC=D1=83=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CourseApp.Tests/CharacterTest.cs | 57 ++++++++++++++++++++++++++++---- CourseApp/Archer.cs | 31 +++++++++++++---- CourseApp/Character.cs | 31 +++++++++-------- CourseApp/Guardian.cs | 16 +++++++-- CourseApp/Phone.cs | 38 +++++++++++++++++++++ CourseApp/Program.cs | 32 +++++++++--------- CourseApp/TheMagian.cs | 37 +++++++++++++++++++++ 7 files changed, 197 insertions(+), 45 deletions(-) create mode 100644 CourseApp/Phone.cs create mode 100644 CourseApp/TheMagian.cs diff --git a/CourseApp.Tests/CharacterTest.cs b/CourseApp.Tests/CharacterTest.cs index feb70f5..9d790ec 100644 --- a/CourseApp.Tests/CharacterTest.cs +++ b/CourseApp.Tests/CharacterTest.cs @@ -8,19 +8,62 @@ public class CharacterTest public void TestGur() { - var gur = new Character("zweihender", 60); - Assert.Equal("zweihender", gur.TypeOfWeapon); - Assert.Equal(60, gur.Lvl); + var guard = new Guardian("Leo", "zweihender", 95); + Assert.Equal("zweihender", guard.TypeOfWeapon); + Assert.Equal(95, guard.Lvl); } [Fact] public void TestMag() { - var mag = new Character("Magian", "crystal staf", 58); - Assert.Equal("Magian", mag.Clas); - Assert.Equal("crystal staf", mag.TypeOfWeapon); - Assert.Equal(58, mag.Lvl); + 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()); } } } diff --git a/CourseApp/Archer.cs b/CourseApp/Archer.cs index dcef223..2ba2ca1 100644 --- a/CourseApp/Archer.cs +++ b/CourseApp/Archer.cs @@ -4,14 +4,14 @@ namespace CourseApp; public class Archer : Character { - public Archer(string clas, string typeOfWeapon, int lvl) - : base(clas, typeOfWeapon, lvl) + public Archer(string name, string typeOfWeapon, int lvl) + : base(name, typeOfWeapon, lvl) { } - private string bw = "Bow of the erd tree"; + private static string bw = "Bow of the erd tree"; - public void Bow(string bow) + public static void Bow(string bow) { if (bow == bw) { @@ -23,15 +23,32 @@ public void Bow(string bow) } } - public void Ability(int arrows) + public static void Ability(int arrows) { if (arrows < 90) { - Console.WriteLine("Тебе разрешено защищать только стены города"); + Console.WriteLine("Azir тебе разрешено защищать только стены города"); + Console.WriteLine(); } else { - Console.WriteLine("Тебе разрешено защищать саму принцессу"); + Console.WriteLine("Azir тебе разрешено защищать саму принцессу"); + Console.WriteLine(); } } + + public override string Guild() + { + return "я состою в гильдии Милость Дриады"; + } + + public override string GetInfo() + { + return $"Я заступил на службу в 12:00 "; + } + + /*public new void Print() + { + Console.WriteLine($"{Name} {TypeOfWeapon}"); + }*/ } \ No newline at end of file diff --git a/CourseApp/Character.cs b/CourseApp/Character.cs index 0cb26a2..cf0aecf 100644 --- a/CourseApp/Character.cs +++ b/CourseApp/Character.cs @@ -2,20 +2,13 @@ using System; -public class Character +public abstract class Character { private int level; - - public Character(string typeOfWeapon, int lvl) - { - Clas = "Guardian"; - this.TypeOfWeapon = typeOfWeapon; - this.Lvl = lvl; - } - - public Character(string clas, string typeOfWeapon, int lvl) + + public Character(string name, string typeOfWeapon, int lvl) { - this.Clas = clas; + this.Name = name; this.TypeOfWeapon = typeOfWeapon; this.Lvl = lvl; } @@ -38,14 +31,19 @@ public int Lvl public string TypeOfWeapon { get; set; } - public string Clas { get; set; } + public string Name { get; set; } public void Print() { - Console.WriteLine($"Ваши характеристи на данный момент \n {Clas} {Lvl} {TypeOfWeapon}"); + Console.Write($"{Name} {Lvl} {TypeOfWeapon}"); } - public void MaxLevel() + public virtual string Guild() + { + return ""; + } + + /*public void MaxLevel() { Console.WriteLine($"Ваш уровень {Lvl} /99"); } @@ -53,5 +51,10 @@ public void MaxLevel() public void Damag() { Console.WriteLine($"Вам выпало легендарный оружие {TypeOfWeapon}"); + }*/ + + public virtual string GetInfo() + { + return ""; } } diff --git a/CourseApp/Guardian.cs b/CourseApp/Guardian.cs index f7b338b..0f111c3 100644 --- a/CourseApp/Guardian.cs +++ b/CourseApp/Guardian.cs @@ -4,8 +4,8 @@ namespace CourseApp; public class Guardian : Character { - public Guardian(string typeOfWeapon, int lvl) - : base(typeOfWeapon, lvl) + public Guardian(string name, string typeOfWeapon, int lvl) + : base(name, typeOfWeapon, lvl) { } @@ -14,10 +14,22 @@ 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 "; + } } \ No newline at end of file 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 50e8055..d83af7e 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,27 +1,29 @@ namespace CourseApp { using System; + using System.Collections.Generic; public class Program { public static void Main(string[] args) { - Character gur = new ("zweihender", 60); - Character mag = new ("Magian", "crystal staf", 58); - Console.WriteLine($"lev= {mag.Lvl}"); - Guardian guardian = new Guardian("zweihender", 90); - Archer archer = new Archer("Archer", "Black Onion", 79); - - mag.MaxLevel(); - mag.Damag(); - mag.Print(); - - gur.Damag(); - gur.Print(); - guardian.Print(); - guardian.Protect(true); + Archer archer = new ("Azir", "Black Onion", 79); + TheMagian magian = new ("Rise", "CristalStaff", 85); + Guardian guard = new ("Leo", "zweihender", 95); - archer.Bow("Bow of the erd tree"); + var characterList = new List + { + archer, + magian, + guard, + }; + + foreach (var Character in characterList) + { + Character.Print(); + Console.WriteLine(Character.Guild()); + Console.WriteLine(Character.GetInfo()); + } } } } diff --git a/CourseApp/TheMagian.cs b/CourseApp/TheMagian.cs new file mode 100644 index 0000000..b8b7cad --- /dev/null +++ b/CourseApp/TheMagian.cs @@ -0,0 +1,37 @@ +namespace CourseApp; + +using System; + +public class TheMagian : Character +{ + private int GrupOfOpponent; + + 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 $"Я служу для защиты нашего прекрасного замка "; + } +} \ No newline at end of file From 0309e0f4aaf2696a77a3e4edff0d04012a1ebd80 Mon Sep 17 00:00:00 2001 From: Sasha1602 Date: Fri, 14 Oct 2022 10:43:39 +0300 Subject: [PATCH 07/11] =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=B9=D0=BB=D0=BA?= =?UTF-8?q?=D0=BE=D0=BF=20True?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CourseApp/Archer.cs | 4 ++-- CourseApp/Character.cs | 6 +++--- CourseApp/CourseApp.csproj | 2 +- CourseApp/Program.cs | 10 +++++----- CourseApp/TheMagian.cs | 6 ++---- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/CourseApp/Archer.cs b/CourseApp/Archer.cs index 2ba2ca1..83cbd59 100644 --- a/CourseApp/Archer.cs +++ b/CourseApp/Archer.cs @@ -4,13 +4,13 @@ namespace CourseApp; 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) { } - private static string bw = "Bow of the erd tree"; - public static void Bow(string bow) { if (bow == bw) diff --git a/CourseApp/Character.cs b/CourseApp/Character.cs index cf0aecf..abed458 100644 --- a/CourseApp/Character.cs +++ b/CourseApp/Character.cs @@ -5,7 +5,7 @@ public abstract class Character { private int level; - + public Character(string name, string typeOfWeapon, int lvl) { this.Name = name; @@ -40,7 +40,7 @@ public void Print() public virtual string Guild() { - return ""; + return "1535"; } /*public void MaxLevel() @@ -55,6 +55,6 @@ public void Damag() public virtual string GetInfo() { - return ""; + return "54891"; } } diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index f5c84ea..82ed6ac 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -4,7 +4,7 @@ Exe net6.0 - False + True diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index d83af7e..cf48728 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -10,7 +10,7 @@ public static void Main(string[] args) Archer archer = new ("Azir", "Black Onion", 79); TheMagian magian = new ("Rise", "CristalStaff", 85); Guardian guard = new ("Leo", "zweihender", 95); - + var characterList = new List { archer, @@ -18,11 +18,11 @@ public static void Main(string[] args) guard, }; - foreach (var Character in characterList) + foreach (var character in characterList) { - Character.Print(); - Console.WriteLine(Character.Guild()); - Console.WriteLine(Character.GetInfo()); + character.Print(); + Console.WriteLine(character.Guild()); + Console.WriteLine(character.GetInfo()); } } } diff --git a/CourseApp/TheMagian.cs b/CourseApp/TheMagian.cs index b8b7cad..c45ebeb 100644 --- a/CourseApp/TheMagian.cs +++ b/CourseApp/TheMagian.cs @@ -4,16 +4,14 @@ namespace CourseApp; public class TheMagian : Character { - private int GrupOfOpponent; - public TheMagian(string name, string typeOfWeapon, int lvl) : base(name, typeOfWeapon, lvl) { } - public void Opponent(int GrupOfOpponent) + public void Opponent(int grupOfOpponent) { - if (GrupOfOpponent < 40) + if (grupOfOpponent < 40) { Console.WriteLine($"Им не нужна моя помощь"); Console.WriteLine(); From 88718f818b96c03488e53dbdcdd41216ab0751c6 Mon Sep 17 00:00:00 2001 From: Sasha1602 Date: Fri, 14 Oct 2022 10:48:10 +0300 Subject: [PATCH 08/11] / --- CourseApp/Archer.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CourseApp/Archer.cs b/CourseApp/Archer.cs index 83cbd59..e8eba98 100644 --- a/CourseApp/Archer.cs +++ b/CourseApp/Archer.cs @@ -46,9 +46,4 @@ public override string GetInfo() { return $"Я заступил на службу в 12:00 "; } - - /*public new void Print() - { - Console.WriteLine($"{Name} {TypeOfWeapon}"); - }*/ } \ No newline at end of file From c651f9a9ac0c3a8ac1c14d3e364b692aac50e674 Mon Sep 17 00:00:00 2001 From: Sasha1602 Date: Sat, 22 Oct 2022 15:09:41 +0300 Subject: [PATCH 09/11] . MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Дополнения для тестов и начало RPGSaga --- CourseApp.Tests/CharacterTest.cs | 65 ++++++++++++++++++++++++++ CourseApp/{ => Character}/Archer.cs | 7 ++- CourseApp/{ => Character}/Character.cs | 2 +- CourseApp/{ => Character}/Guardian.cs | 7 ++- CourseApp/{ => Character}/TheMagian.cs | 7 ++- CourseApp/CourseApp.csproj | 4 ++ CourseApp/Program.cs | 2 + 7 files changed, 90 insertions(+), 4 deletions(-) rename CourseApp/{ => Character}/Archer.cs (89%) rename CourseApp/{ => Character}/Character.cs (97%) rename CourseApp/{ => Character}/Guardian.cs (83%) rename CourseApp/{ => Character}/TheMagian.cs (85%) diff --git a/CourseApp.Tests/CharacterTest.cs b/CourseApp.Tests/CharacterTest.cs index 9d790ec..9c201d6 100644 --- a/CourseApp.Tests/CharacterTest.cs +++ b/CourseApp.Tests/CharacterTest.cs @@ -1,5 +1,6 @@ namespace CourseApp.Tests { + using Character; using Xunit; public class CharacterTest @@ -65,5 +66,69 @@ public void TestTheMagianGetInfo() 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/Archer.cs b/CourseApp/Character/Archer.cs similarity index 89% rename from CourseApp/Archer.cs rename to CourseApp/Character/Archer.cs index e8eba98..46c5cdb 100644 --- a/CourseApp/Archer.cs +++ b/CourseApp/Character/Archer.cs @@ -1,4 +1,4 @@ -namespace CourseApp; +namespace Character; using System; @@ -46,4 +46,9 @@ public override string GetInfo() { return $"Я заступил на службу в 12:00 "; } + + public override string ToString() + { + return "Ура у меня всё хорошо!"; + } } \ No newline at end of file diff --git a/CourseApp/Character.cs b/CourseApp/Character/Character.cs similarity index 97% rename from CourseApp/Character.cs rename to CourseApp/Character/Character.cs index abed458..7bb3f89 100644 --- a/CourseApp/Character.cs +++ b/CourseApp/Character/Character.cs @@ -1,4 +1,4 @@ -namespace CourseApp; +namespace Character; using System; diff --git a/CourseApp/Guardian.cs b/CourseApp/Character/Guardian.cs similarity index 83% rename from CourseApp/Guardian.cs rename to CourseApp/Character/Guardian.cs index 0f111c3..55521ff 100644 --- a/CourseApp/Guardian.cs +++ b/CourseApp/Character/Guardian.cs @@ -1,4 +1,4 @@ -namespace CourseApp; +namespace Character; using System; @@ -32,4 +32,9 @@ public override string GetInfo() { return $"Я работаю в элитных войсках короля Людовика 2 "; } + + public override string ToString() + { + return "Как хорошо, что меня ещё не уволили)"; + } } \ No newline at end of file diff --git a/CourseApp/TheMagian.cs b/CourseApp/Character/TheMagian.cs similarity index 85% rename from CourseApp/TheMagian.cs rename to CourseApp/Character/TheMagian.cs index c45ebeb..4200078 100644 --- a/CourseApp/TheMagian.cs +++ b/CourseApp/Character/TheMagian.cs @@ -1,4 +1,4 @@ -namespace CourseApp; +namespace Character; using System; @@ -32,4 +32,9 @@ 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 82ed6ac..463ae7c 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index cf48728..be0df7d 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -2,6 +2,7 @@ { using System; using System.Collections.Generic; + using Character; public class Program { @@ -23,6 +24,7 @@ public static void Main(string[] args) character.Print(); Console.WriteLine(character.Guild()); Console.WriteLine(character.GetInfo()); + Console.WriteLine(character.ToString()); } } } From 73befb674f6fb2d6002acb2eaa58553209e50d2f Mon Sep 17 00:00:00 2001 From: Sasha1602 Date: Sat, 22 Oct 2022 15:09:41 +0300 Subject: [PATCH 10/11] . MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Дополнения для тестов и начало RPGSaga --- CourseApp.Tests/CharacterTest.cs | 65 ++++++++++++++++++++++++++ CourseApp/{ => Character}/Archer.cs | 7 ++- CourseApp/{ => Character}/Character.cs | 2 +- CourseApp/{ => Character}/Guardian.cs | 7 ++- CourseApp/{ => Character}/TheMagian.cs | 7 ++- CourseApp/CourseApp.csproj | 4 ++ CourseApp/Program.cs | 2 + 7 files changed, 90 insertions(+), 4 deletions(-) rename CourseApp/{ => Character}/Archer.cs (89%) rename CourseApp/{ => Character}/Character.cs (97%) rename CourseApp/{ => Character}/Guardian.cs (83%) rename CourseApp/{ => Character}/TheMagian.cs (85%) diff --git a/CourseApp.Tests/CharacterTest.cs b/CourseApp.Tests/CharacterTest.cs index 9d790ec..9c201d6 100644 --- a/CourseApp.Tests/CharacterTest.cs +++ b/CourseApp.Tests/CharacterTest.cs @@ -1,5 +1,6 @@ namespace CourseApp.Tests { + using Character; using Xunit; public class CharacterTest @@ -65,5 +66,69 @@ public void TestTheMagianGetInfo() 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/Archer.cs b/CourseApp/Character/Archer.cs similarity index 89% rename from CourseApp/Archer.cs rename to CourseApp/Character/Archer.cs index e8eba98..46c5cdb 100644 --- a/CourseApp/Archer.cs +++ b/CourseApp/Character/Archer.cs @@ -1,4 +1,4 @@ -namespace CourseApp; +namespace Character; using System; @@ -46,4 +46,9 @@ public override string GetInfo() { return $"Я заступил на службу в 12:00 "; } + + public override string ToString() + { + return "Ура у меня всё хорошо!"; + } } \ No newline at end of file diff --git a/CourseApp/Character.cs b/CourseApp/Character/Character.cs similarity index 97% rename from CourseApp/Character.cs rename to CourseApp/Character/Character.cs index abed458..7bb3f89 100644 --- a/CourseApp/Character.cs +++ b/CourseApp/Character/Character.cs @@ -1,4 +1,4 @@ -namespace CourseApp; +namespace Character; using System; diff --git a/CourseApp/Guardian.cs b/CourseApp/Character/Guardian.cs similarity index 83% rename from CourseApp/Guardian.cs rename to CourseApp/Character/Guardian.cs index 0f111c3..55521ff 100644 --- a/CourseApp/Guardian.cs +++ b/CourseApp/Character/Guardian.cs @@ -1,4 +1,4 @@ -namespace CourseApp; +namespace Character; using System; @@ -32,4 +32,9 @@ public override string GetInfo() { return $"Я работаю в элитных войсках короля Людовика 2 "; } + + public override string ToString() + { + return "Как хорошо, что меня ещё не уволили)"; + } } \ No newline at end of file diff --git a/CourseApp/TheMagian.cs b/CourseApp/Character/TheMagian.cs similarity index 85% rename from CourseApp/TheMagian.cs rename to CourseApp/Character/TheMagian.cs index c45ebeb..4200078 100644 --- a/CourseApp/TheMagian.cs +++ b/CourseApp/Character/TheMagian.cs @@ -1,4 +1,4 @@ -namespace CourseApp; +namespace Character; using System; @@ -32,4 +32,9 @@ 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 82ed6ac..463ae7c 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index cf48728..be0df7d 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -2,6 +2,7 @@ { using System; using System.Collections.Generic; + using Character; public class Program { @@ -23,6 +24,7 @@ public static void Main(string[] args) character.Print(); Console.WriteLine(character.Guild()); Console.WriteLine(character.GetInfo()); + Console.WriteLine(character.ToString()); } } } From ed46441b77b24609ed152bd8e79e953c2aff581c Mon Sep 17 00:00:00 2001 From: Sasha Date: Thu, 12 Jan 2023 21:25:08 +0300 Subject: [PATCH 11/11] RPG Saga --- CourseApp/CourseApp.csproj | 5 +- CourseApp/Program.cs | 22 +++- CourseApp/RPGSaga/Game.cs | 152 ++++++++++++++++++++++++ CourseApp/RPGSaga/GameClasses/Archer.cs | 30 +++++ CourseApp/RPGSaga/GameClasses/Knight.cs | 30 +++++ CourseApp/RPGSaga/GameClasses/Mage.cs | 30 +++++ CourseApp/RPGSaga/Logger.cs | 61 ++++++++++ CourseApp/RPGSaga/Player.cs | 83 +++++++++++++ global.json | 7 ++ 9 files changed, 413 insertions(+), 7 deletions(-) create mode 100644 CourseApp/RPGSaga/Game.cs create mode 100644 CourseApp/RPGSaga/GameClasses/Archer.cs create mode 100644 CourseApp/RPGSaga/GameClasses/Knight.cs create mode 100644 CourseApp/RPGSaga/GameClasses/Mage.cs create mode 100644 CourseApp/RPGSaga/Logger.cs create mode 100644 CourseApp/RPGSaga/Player.cs create mode 100644 global.json diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index 463ae7c..1a102aa 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -5,6 +5,7 @@ Exe net6.0 True + preview @@ -20,8 +21,4 @@ - - - - diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index be0df7d..f9af896 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,14 +1,19 @@ -namespace CourseApp +/* +namespace CourseApp { using System; using System.Collections.Generic; using Character; + using CourseApp.RPGSaga; public class Program { public static void Main(string[] args) { - Archer archer = new ("Azir", "Black Onion", 79); + 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); @@ -25,7 +30,18 @@ public static void Main(string[] args) 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