From b742c4d31b1e7c40c3da07aa49d6e5b9a066ae16 Mon Sep 17 00:00:00 2001 From: SunM1sty Date: Mon, 27 Dec 2021 19:08:23 +0300 Subject: [PATCH 01/11] Class Person with Unit Tests --- .github/workflows/dotnetcore.yml | 4 +- CourseApp.Tests/CourseApp.Tests.csproj | 1 + .../{Tests.cs => TestsForFunction.cs} | 4 +- CourseApp.Tests/TestsForPersons.cs | 40 ++++++++ CourseApp/CourseApp.csproj | 1 + CourseApp/FunctionStarter.cs | 33 +++++++ CourseApp/Person/Employee.cs | 49 ++++++++++ CourseApp/Person/IPerson.cs | 12 +++ CourseApp/Person/Person.cs | 94 +++++++++++++++++++ CourseApp/Person/Student.cs | 48 ++++++++++ CourseApp/Program.cs | 29 ++---- 11 files changed, 291 insertions(+), 24 deletions(-) rename CourseApp.Tests/{Tests.cs => TestsForFunction.cs} (88%) create mode 100644 CourseApp.Tests/TestsForPersons.cs create mode 100644 CourseApp/FunctionStarter.cs create mode 100644 CourseApp/Person/Employee.cs create mode 100644 CourseApp/Person/IPerson.cs create mode 100644 CourseApp/Person/Person.cs create mode 100644 CourseApp/Person/Student.cs diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 95b27949..6f9f1260 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -8,10 +8,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - dotnet: [ '2.1', '3.1.x', '5.0.x' ] + dotnet: [ '2.1', '5.0.x', '6.0.x' ] steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 158d6300..34066014 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -4,6 +4,7 @@ netcoreapp5 True false + latest diff --git a/CourseApp.Tests/Tests.cs b/CourseApp.Tests/TestsForFunction.cs similarity index 88% rename from CourseApp.Tests/Tests.cs rename to CourseApp.Tests/TestsForFunction.cs index f5624e38..0eba5fe0 100644 --- a/CourseApp.Tests/Tests.cs +++ b/CourseApp.Tests/TestsForFunction.cs @@ -2,11 +2,11 @@ namespace CourseApp.Tests { using Xunit; - public class Tests + public class TestsForFunction { private readonly Function _function; - public Tests() + public TestsForFunction() { _function = new Function(); } diff --git a/CourseApp.Tests/TestsForPersons.cs b/CourseApp.Tests/TestsForPersons.cs new file mode 100644 index 00000000..e565450b --- /dev/null +++ b/CourseApp.Tests/TestsForPersons.cs @@ -0,0 +1,40 @@ +namespace CourseApp.Tests +{ + using CourseApp.Person; + using Xunit; + + public class TestsForPersons + { + [Fact] + public void GetNameOfStudent() + { + var student = new Student("Anatoliy Rumyantsev", 18, "Clown", 192); + var expected = "Anatoliy Rumyantsev"; + Assert.Equal(expected, student.Name); + } + + [Fact] + public void GetAgeOfStudent() + { + var student = new Student("Sergey Vasiliev", 25, "c400", 165); + var expected = 25; + Assert.Equal(expected, student.Age); + } + + [Fact] + public void GetGenderOfEmployee() + { + var employee = new Employee("Stas Tereshenko", 45, "T34", 180); + var expected = "T34"; + Assert.Equal(expected, employee.Gender); + } + + [Fact] + public void GetHeightOfEmployee() + { + var employee = new Employee("Anastasiya Kruchevskaya", 33, 174); + var expected = 174; + Assert.Equal(expected, employee.Height); + } + } +} \ No newline at end of file diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index ee97040a..40d13afe 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -4,6 +4,7 @@ Exe netcoreapp5 True + latest diff --git a/CourseApp/FunctionStarter.cs b/CourseApp/FunctionStarter.cs new file mode 100644 index 00000000..c4f473b0 --- /dev/null +++ b/CourseApp/FunctionStarter.cs @@ -0,0 +1,33 @@ +namespace CourseApp +{ + using System; + using System.Collections.Generic; + using Kantaiko.ConsoleFormatting; + + public class FunctionStarter + { + public static void Start(string[] args) + { + var runner = new TaskRunner(); + var a = 1.6; + var xn = 1.2; + var xk = 3.7; + var dx = 0.5; + Console.WriteLine(Colors.FgCyan("-----TASK A-----").BgBlack()); + var listA = runner.Calculation(a, xn, xk, dx); + ConsoleOutput(listA); + Console.WriteLine(Colors.FgCyan("-----TASK B-----").BgBlack()); + var xs = new List() { 1.28, 1.36, 2.47, 3.68, 4.56 }; + var listB = runner.Calculation(a, xs); + ConsoleOutput(listB); + } + + private static void ConsoleOutput(List ys) + { + foreach (var y in ys) + { + Console.WriteLine(Colors.FgCyan($"y = {y}").BgBlack()); + } + } + } +} \ No newline at end of file diff --git a/CourseApp/Person/Employee.cs b/CourseApp/Person/Employee.cs new file mode 100644 index 00000000..456f4491 --- /dev/null +++ b/CourseApp/Person/Employee.cs @@ -0,0 +1,49 @@ +namespace CourseApp.Person; +using System; +public class Employee : Person +{ + public Employee() + : base() + { + } + + public Employee(string name, int age, string gender, int height) + : base(name, age, gender, height) + { + } + + public Employee(string name, int age, string gender) + : base(name, age, gender) + { + } + + public Employee(string name, int age, int height) + : base(name, age, height) + { + } + + public Employee(string name) + : base(name) + { + } + + public Employee(string name, int age) + : base(name, age) + { + } + + public override string Walk() + { + return "Whoooooooooooo, I`m walking"; + } + + public override string Greeting() + { + return $"Hi! What`s your name? My my name is {Name} and I`m {Age} old."; + } + + public void Work() + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/CourseApp/Person/IPerson.cs b/CourseApp/Person/IPerson.cs new file mode 100644 index 00000000..4802af51 --- /dev/null +++ b/CourseApp/Person/IPerson.cs @@ -0,0 +1,12 @@ +namespace CourseApp.Person; + +public interface IPerson +{ + string Name { get; set; } + + int Age { get; set; } + + string Gender { get; set; } + + int Height { get; set; } +} \ No newline at end of file diff --git a/CourseApp/Person/Person.cs b/CourseApp/Person/Person.cs new file mode 100644 index 00000000..c060eb37 --- /dev/null +++ b/CourseApp/Person/Person.cs @@ -0,0 +1,94 @@ +namespace CourseApp.Person; + +public abstract class Person : IPerson +{ + private int age; + + private int height; + + public Person(string name, int age, string gender, int height) + { + Name = name; + Age = age; + Gender = gender; + Height = height; + } + + public Person() + : this("Someone", 0, "Ukrainian drone", 0) + { + } + + public Person(string name, int age, string gender) + : this(name, age, gender, 0) + { + } + + public Person(string name, int age, int height) + : this(name, age, "Ukrainian drone", height) + { + } + + public Person(string name, int age) + : this(name, age, "Ukrainian drone", 0) + { + } + + public Person(string name) + : this(name, 0, "Ukrainian drone", 0) + { + } + + public string Name { get; set; } + + public int Age + { + get + { + return age; + } + + set + { + if (value >= 0 && value < 100) + { + age = value; + } + else + { + age = 0; + } + } + } + + public string Gender { get; set; } + + public int Height + { + get + { + return height; + } + + set + { + if (value > 100 && value < 250) + { + height = value; + } + else + { + height = 100; + } + } + } + + public abstract string Walk(); + + public abstract string Greeting(); + + public override string ToString() + { + return $"Person {Name} is living"; + } +} \ No newline at end of file diff --git a/CourseApp/Person/Student.cs b/CourseApp/Person/Student.cs new file mode 100644 index 00000000..84754f5f --- /dev/null +++ b/CourseApp/Person/Student.cs @@ -0,0 +1,48 @@ +namespace CourseApp.Person; +using System; +public class Student : Person +{ + public Student() + { + } + + public Student(string name, int age, string gender) + : base(name, age, gender) + { + } + + public Student(string name, int age, string gender, int height) + : base(name, age, gender, height) + { + } + + public Student(string name, int age, int height) + : base(name, age, height) + { + } + + public Student(string name) + : base(name) + { + } + + public Student(string name, int age) + : base(name, age) + { + } + + public override string Walk() + { + return "I`m walking"; + } + + public override string Greeting() + { + return $"Hello, my name is {Name} and I`m {Age} old."; + } + + public void Study() + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index dd0aea7b..1a7223e8 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -2,32 +2,21 @@ { using System; using System.Collections.Generic; + using CourseApp.Person; using Kantaiko.ConsoleFormatting; public class Program { public static void Main(string[] args) { - var runner = new TaskRunner(); - var a = 1.6; - var xn = 1.2; - var xk = 3.7; - var dx = 0.5; - Console.WriteLine(Colors.FgCyan("-----TASK A-----").BgBlack()); - var listA = runner.Calculation(a, xn, xk, dx); - ConsoleOutput(listA); - Console.WriteLine(Colors.FgCyan("-----TASK B-----").BgBlack()); - var xs = new List() { 1.28, 1.36, 2.47, 3.68, 4.56 }; - var listB = runner.Calculation(a, xs); - ConsoleOutput(listB); - } - - private static void ConsoleOutput(List ys) - { - foreach (var y in ys) - { - Console.WriteLine(Colors.FgCyan($"y = {y}").BgBlack()); - } + var studentValera = new Student("Valera Sukharev", 18, 185); + var studentAlesha = new Student("Aleksei Polekhin", 19, "Подвальный", 182); + var employeeVladimir = new Employee("Vladimir Kozhukhar", 18, 185); + var employeeUnknown = new Employee(); + Console.WriteLine(studentAlesha.Walk()); + Console.WriteLine(studentValera.Greeting()); + Console.WriteLine(employeeVladimir.ToString()); + Console.WriteLine(employeeUnknown.ToString()); } } } From c20568cb988da5967e2ab4161698476954a8ce6a Mon Sep 17 00:00:00 2001 From: Vladimir Kozhukhar <71171622+SunM1sty@users.noreply.github.com> Date: Mon, 27 Dec 2021 19:16:02 +0300 Subject: [PATCH 02/11] add .net 6 build --- .github/workflows/dotnetcore.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 6f9f1260..dffe441c 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -16,6 +16,7 @@ jobs: uses: actions/setup-dotnet@v1 with: dotnet-version: ${{ matrix.dotnet-version }} + include-prerelease: true - name: Build with dotnet run: | cd CourseApp From 610bdd889d9ff5a1c5160a8dd154400ae1ee22fd Mon Sep 17 00:00:00 2001 From: SunM1sty Date: Mon, 27 Dec 2021 19:22:25 +0300 Subject: [PATCH 03/11] Fixed troubles with blanks --- CourseApp/Person/Employee.cs | 99 ++++++++++++++------------- CourseApp/Person/IPerson.cs | 17 ++--- CourseApp/Person/Person.cs | 129 ++++++++++++++++++----------------- CourseApp/Person/Student.cs | 93 +++++++++++++------------ 4 files changed, 173 insertions(+), 165 deletions(-) diff --git a/CourseApp/Person/Employee.cs b/CourseApp/Person/Employee.cs index 456f4491..cb5688d5 100644 --- a/CourseApp/Person/Employee.cs +++ b/CourseApp/Person/Employee.cs @@ -1,49 +1,52 @@ -namespace CourseApp.Person; -using System; -public class Employee : Person +namespace CourseApp.Person { - public Employee() - : base() - { - } - - public Employee(string name, int age, string gender, int height) - : base(name, age, gender, height) - { - } - - public Employee(string name, int age, string gender) - : base(name, age, gender) - { - } - - public Employee(string name, int age, int height) - : base(name, age, height) - { - } - - public Employee(string name) - : base(name) - { - } - - public Employee(string name, int age) - : base(name, age) - { - } - - public override string Walk() - { - return "Whoooooooooooo, I`m walking"; - } - - public override string Greeting() - { - return $"Hi! What`s your name? My my name is {Name} and I`m {Age} old."; - } - - public void Work() - { - throw new NotImplementedException(); - } -} \ No newline at end of file + using System; + + public class Employee : Person + { + public Employee() + : base() + { + } + + public Employee(string name, int age, string gender, int height) + : base(name, age, gender, height) + { + } + + public Employee(string name, int age, string gender) + : base(name, age, gender) + { + } + + public Employee(string name, int age, int height) + : base(name, age, height) + { + } + + public Employee(string name) + : base(name) + { + } + + public Employee(string name, int age) + : base(name, age) + { + } + + public override string Walk() + { + return "Whoooooooooooo, I`m walking"; + } + + public override string Greeting() + { + return $"Hi! What`s your name? My my name is {Name} and I`m {Age} old."; + } + + public void Work() + { + throw new NotImplementedException(); + } + } +} diff --git a/CourseApp/Person/IPerson.cs b/CourseApp/Person/IPerson.cs index 4802af51..8a2f7d1e 100644 --- a/CourseApp/Person/IPerson.cs +++ b/CourseApp/Person/IPerson.cs @@ -1,12 +1,13 @@ -namespace CourseApp.Person; - -public interface IPerson +namespace CourseApp.Person { - string Name { get; set; } + public interface IPerson + { + string Name { get; set; } - int Age { get; set; } + int Age { get; set; } - string Gender { get; set; } + string Gender { get; set; } - int Height { get; set; } -} \ No newline at end of file + int Height { get; set; } + } +} diff --git a/CourseApp/Person/Person.cs b/CourseApp/Person/Person.cs index c060eb37..70e9d17c 100644 --- a/CourseApp/Person/Person.cs +++ b/CourseApp/Person/Person.cs @@ -1,94 +1,95 @@ -namespace CourseApp.Person; - -public abstract class Person : IPerson +namespace CourseApp.Person { - private int age; - - private int height; - - public Person(string name, int age, string gender, int height) + public abstract class Person : IPerson { - Name = name; - Age = age; - Gender = gender; - Height = height; - } + private int age; - public Person() - : this("Someone", 0, "Ukrainian drone", 0) - { - } + private int height; - public Person(string name, int age, string gender) - : this(name, age, gender, 0) - { - } + public Person(string name, int age, string gender, int height) + { + Name = name; + Age = age; + Gender = gender; + Height = height; + } - public Person(string name, int age, int height) - : this(name, age, "Ukrainian drone", height) - { - } + public Person() + : this("Someone", 0, "Ukrainian drone", 0) + { + } - public Person(string name, int age) - : this(name, age, "Ukrainian drone", 0) - { - } + public Person(string name, int age, string gender) + : this(name, age, gender, 0) + { + } - public Person(string name) - : this(name, 0, "Ukrainian drone", 0) - { - } + public Person(string name, int age, int height) + : this(name, age, "Ukrainian drone", height) + { + } - public string Name { get; set; } + public Person(string name, int age) + : this(name, age, "Ukrainian drone", 0) + { + } - public int Age - { - get + public Person(string name) + : this(name, 0, "Ukrainian drone", 0) { - return age; } - set + public string Name { get; set; } + + public int Age { - if (value >= 0 && value < 100) + get { - age = value; + return age; } - else + + set { - age = 0; + if (value >= 0 && value < 100) + { + age = value; + } + else + { + age = 0; + } } } - } - public string Gender { get; set; } + public string Gender { get; set; } - public int Height - { - get + public int Height { - return height; - } - - set - { - if (value > 100 && value < 250) + get { - height = value; + return height; } - else + + set { - height = 100; + if (value > 100 && value < 250) + { + height = value; + } + else + { + height = 100; + } } } - } - public abstract string Walk(); + public abstract string Walk(); - public abstract string Greeting(); + public abstract string Greeting(); - public override string ToString() - { - return $"Person {Name} is living"; + public override string ToString() + { + return $"Person {Name} is living"; + } } -} \ No newline at end of file +} diff --git a/CourseApp/Person/Student.cs b/CourseApp/Person/Student.cs index 84754f5f..f8486c3a 100644 --- a/CourseApp/Person/Student.cs +++ b/CourseApp/Person/Student.cs @@ -1,48 +1,51 @@ -namespace CourseApp.Person; -using System; -public class Student : Person +namespace CourseApp.Person { - public Student() - { - } - - public Student(string name, int age, string gender) - : base(name, age, gender) - { - } - - public Student(string name, int age, string gender, int height) - : base(name, age, gender, height) - { - } - - public Student(string name, int age, int height) - : base(name, age, height) - { - } - - public Student(string name) - : base(name) - { - } - - public Student(string name, int age) - : base(name, age) - { - } - - public override string Walk() - { - return "I`m walking"; - } - - public override string Greeting() - { - return $"Hello, my name is {Name} and I`m {Age} old."; - } - - public void Study() - { - throw new NotImplementedException(); + using System; + + public class Student : Person + { + public Student() + { + } + + public Student(string name, int age, string gender) + : base(name, age, gender) + { + } + + public Student(string name, int age, string gender, int height) + : base(name, age, gender, height) + { + } + + public Student(string name, int age, int height) + : base(name, age, height) + { + } + + public Student(string name) + : base(name) + { + } + + public Student(string name, int age) + : base(name, age) + { + } + + public override string Walk() + { + return "I`m walking"; + } + + public override string Greeting() + { + return $"Hello, my name is {Name} and I`m {Age} old."; + } + + public void Study() + { + throw new NotImplementedException(); + } } } \ No newline at end of file From fdc5d26b7338359e61578e0cd74aa284c2819239 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 5 Feb 2022 13:35:54 +0300 Subject: [PATCH 04/11] RPGSaga: Heroes Classes --- CourseApp/Function.cs | 12 ---- CourseApp/FunctionStarter.cs | 33 --------- CourseApp/Person/Employee.cs | 52 -------------- CourseApp/Person/IPerson.cs | 13 ---- CourseApp/Person/Person.cs | 95 ------------------------- CourseApp/Person/Student.cs | 51 ------------- CourseApp/Program.cs | 9 --- CourseApp/RPGSaga/Heroes/Archer.cs | 10 +++ CourseApp/RPGSaga/Heroes/Knight.cs | 10 +++ CourseApp/RPGSaga/Heroes/Player.cs | 57 +++++++++++++++ CourseApp/RPGSaga/Heroes/Wizard.cs | 10 +++ CourseApp/RPGSaga/Interfaces/IPlayer.cs | 11 +++ CourseApp/TaskRunner.cs | 38 ---------- 13 files changed, 98 insertions(+), 303 deletions(-) delete mode 100644 CourseApp/Function.cs delete mode 100644 CourseApp/FunctionStarter.cs delete mode 100644 CourseApp/Person/Employee.cs delete mode 100644 CourseApp/Person/IPerson.cs delete mode 100644 CourseApp/Person/Person.cs delete mode 100644 CourseApp/Person/Student.cs create mode 100644 CourseApp/RPGSaga/Heroes/Archer.cs create mode 100644 CourseApp/RPGSaga/Heroes/Knight.cs create mode 100644 CourseApp/RPGSaga/Heroes/Player.cs create mode 100644 CourseApp/RPGSaga/Heroes/Wizard.cs create mode 100644 CourseApp/RPGSaga/Interfaces/IPlayer.cs delete mode 100644 CourseApp/TaskRunner.cs diff --git a/CourseApp/Function.cs b/CourseApp/Function.cs deleted file mode 100644 index 2391b6b3..00000000 --- a/CourseApp/Function.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace CourseApp -{ - using static System.Math; - - public class Function - { - public double CalculateFunction(double a, double x) - { - return Pow(a, Pow(x, 2.0) - 1.0) - Log10(Pow(x, 2.0) - 1.0) - Pow(Pow(x, 2.0) - 1.0, 1.0 / 3.0); - } - } -} \ No newline at end of file diff --git a/CourseApp/FunctionStarter.cs b/CourseApp/FunctionStarter.cs deleted file mode 100644 index c4f473b0..00000000 --- a/CourseApp/FunctionStarter.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace CourseApp -{ - using System; - using System.Collections.Generic; - using Kantaiko.ConsoleFormatting; - - public class FunctionStarter - { - public static void Start(string[] args) - { - var runner = new TaskRunner(); - var a = 1.6; - var xn = 1.2; - var xk = 3.7; - var dx = 0.5; - Console.WriteLine(Colors.FgCyan("-----TASK A-----").BgBlack()); - var listA = runner.Calculation(a, xn, xk, dx); - ConsoleOutput(listA); - Console.WriteLine(Colors.FgCyan("-----TASK B-----").BgBlack()); - var xs = new List() { 1.28, 1.36, 2.47, 3.68, 4.56 }; - var listB = runner.Calculation(a, xs); - ConsoleOutput(listB); - } - - private static void ConsoleOutput(List ys) - { - foreach (var y in ys) - { - Console.WriteLine(Colors.FgCyan($"y = {y}").BgBlack()); - } - } - } -} \ No newline at end of file diff --git a/CourseApp/Person/Employee.cs b/CourseApp/Person/Employee.cs deleted file mode 100644 index cb5688d5..00000000 --- a/CourseApp/Person/Employee.cs +++ /dev/null @@ -1,52 +0,0 @@ -namespace CourseApp.Person -{ - using System; - - public class Employee : Person - { - public Employee() - : base() - { - } - - public Employee(string name, int age, string gender, int height) - : base(name, age, gender, height) - { - } - - public Employee(string name, int age, string gender) - : base(name, age, gender) - { - } - - public Employee(string name, int age, int height) - : base(name, age, height) - { - } - - public Employee(string name) - : base(name) - { - } - - public Employee(string name, int age) - : base(name, age) - { - } - - public override string Walk() - { - return "Whoooooooooooo, I`m walking"; - } - - public override string Greeting() - { - return $"Hi! What`s your name? My my name is {Name} and I`m {Age} old."; - } - - public void Work() - { - throw new NotImplementedException(); - } - } -} diff --git a/CourseApp/Person/IPerson.cs b/CourseApp/Person/IPerson.cs deleted file mode 100644 index 8a2f7d1e..00000000 --- a/CourseApp/Person/IPerson.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace CourseApp.Person -{ - public interface IPerson - { - string Name { get; set; } - - int Age { get; set; } - - string Gender { get; set; } - - int Height { get; set; } - } -} diff --git a/CourseApp/Person/Person.cs b/CourseApp/Person/Person.cs deleted file mode 100644 index 70e9d17c..00000000 --- a/CourseApp/Person/Person.cs +++ /dev/null @@ -1,95 +0,0 @@ -namespace CourseApp.Person -{ - public abstract class Person : IPerson - { - private int age; - - private int height; - - public Person(string name, int age, string gender, int height) - { - Name = name; - Age = age; - Gender = gender; - Height = height; - } - - public Person() - : this("Someone", 0, "Ukrainian drone", 0) - { - } - - public Person(string name, int age, string gender) - : this(name, age, gender, 0) - { - } - - public Person(string name, int age, int height) - : this(name, age, "Ukrainian drone", height) - { - } - - public Person(string name, int age) - : this(name, age, "Ukrainian drone", 0) - { - } - - public Person(string name) - : this(name, 0, "Ukrainian drone", 0) - { - } - - public string Name { get; set; } - - public int Age - { - get - { - return age; - } - - set - { - if (value >= 0 && value < 100) - { - age = value; - } - else - { - age = 0; - } - } - } - - public string Gender { get; set; } - - public int Height - { - get - { - return height; - } - - set - { - if (value > 100 && value < 250) - { - height = value; - } - else - { - height = 100; - } - } - } - - public abstract string Walk(); - - public abstract string Greeting(); - - public override string ToString() - { - return $"Person {Name} is living"; - } - } -} diff --git a/CourseApp/Person/Student.cs b/CourseApp/Person/Student.cs deleted file mode 100644 index f8486c3a..00000000 --- a/CourseApp/Person/Student.cs +++ /dev/null @@ -1,51 +0,0 @@ -namespace CourseApp.Person -{ - using System; - - public class Student : Person - { - public Student() - { - } - - public Student(string name, int age, string gender) - : base(name, age, gender) - { - } - - public Student(string name, int age, string gender, int height) - : base(name, age, gender, height) - { - } - - public Student(string name, int age, int height) - : base(name, age, height) - { - } - - public Student(string name) - : base(name) - { - } - - public Student(string name, int age) - : base(name, age) - { - } - - public override string Walk() - { - return "I`m walking"; - } - - public override string Greeting() - { - return $"Hello, my name is {Name} and I`m {Age} old."; - } - - public void Study() - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 1a7223e8..84f7e748 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -2,21 +2,12 @@ { using System; using System.Collections.Generic; - using CourseApp.Person; using Kantaiko.ConsoleFormatting; public class Program { public static void Main(string[] args) { - var studentValera = new Student("Valera Sukharev", 18, 185); - var studentAlesha = new Student("Aleksei Polekhin", 19, "Подвальный", 182); - var employeeVladimir = new Employee("Vladimir Kozhukhar", 18, 185); - var employeeUnknown = new Employee(); - Console.WriteLine(studentAlesha.Walk()); - Console.WriteLine(studentValera.Greeting()); - Console.WriteLine(employeeVladimir.ToString()); - Console.WriteLine(employeeUnknown.ToString()); } } } diff --git a/CourseApp/RPGSaga/Heroes/Archer.cs b/CourseApp/RPGSaga/Heroes/Archer.cs new file mode 100644 index 00000000..21f0238e --- /dev/null +++ b/CourseApp/RPGSaga/Heroes/Archer.cs @@ -0,0 +1,10 @@ +namespace CourseApp.RPGSaga.Heroes +{ + public class Archer : Player + { + public Archer(string name, int hp, int strength) + : base(name, hp, strength) + { + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Heroes/Knight.cs b/CourseApp/RPGSaga/Heroes/Knight.cs new file mode 100644 index 00000000..3b496c4a --- /dev/null +++ b/CourseApp/RPGSaga/Heroes/Knight.cs @@ -0,0 +1,10 @@ +namespace CourseApp.RPGSaga.Heroes +{ + public class Knight : Player + { + public Knight(string name, int hp, int strength) + : base(name, hp, strength) + { + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Heroes/Player.cs b/CourseApp/RPGSaga/Heroes/Player.cs new file mode 100644 index 00000000..9195803e --- /dev/null +++ b/CourseApp/RPGSaga/Heroes/Player.cs @@ -0,0 +1,57 @@ +namespace CourseApp.RPGSaga.Heroes +{ + public abstract class Player : IPlayer + { + private int _hp; + private int _strength; + + public Player(string name, int hp, int strength) + { + Name = name; + HP = hp; + Strength = strength; + } + + public string Name { get; set; } + + public int HP + { + get + { + return _hp; + } + + set + { + if (value > 0) + { + _hp = value; + } + else + { + _hp = 10; + } + } + } + + public int Strength + { + get + { + return _strength; + } + + set + { + if (value > 0) + { + _strength = value; + } + else + { + _strength = 10; + } + } + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Heroes/Wizard.cs b/CourseApp/RPGSaga/Heroes/Wizard.cs new file mode 100644 index 00000000..81ea58ff --- /dev/null +++ b/CourseApp/RPGSaga/Heroes/Wizard.cs @@ -0,0 +1,10 @@ +namespace CourseApp.RPGSaga.Heroes +{ + public class Wizard : Player + { + public Wizard(string name, int hp, int strength) + : base(name, hp, strength) + { + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Interfaces/IPlayer.cs b/CourseApp/RPGSaga/Interfaces/IPlayer.cs new file mode 100644 index 00000000..6035103c --- /dev/null +++ b/CourseApp/RPGSaga/Interfaces/IPlayer.cs @@ -0,0 +1,11 @@ +namespace CourseApp.RPGSaga +{ + public interface IPlayer + { + string Name { get; set; } + + int HP { get; set; } + + int Strength { get; set; } + } +} \ No newline at end of file diff --git a/CourseApp/TaskRunner.cs b/CourseApp/TaskRunner.cs deleted file mode 100644 index 1aabf2ab..00000000 --- a/CourseApp/TaskRunner.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace CourseApp -{ - using System; - using System.Collections.Generic; - using Kantaiko.ConsoleFormatting; - - public class TaskRunner - { - private readonly Function _function; - - public TaskRunner() - { - _function = new Function(); - } - - public List Calculation(double a, double xn, double xk, double dx) - { - var listA = new List(); - for (var x = xn; x <= xk; x += dx) - { - listA.Add(_function.CalculateFunction(a, x)); - } - - return listA; - } - - public List Calculation(double a, List xs) - { - var listB = new List(); - foreach (var x in xs) - { - listB.Add(_function.CalculateFunction(a, x)); - } - - return listB; - } - } -} \ No newline at end of file From 23da9133d7824c4ea9246f3ddcf9c5ad22341e92 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 5 Feb 2022 13:42:21 +0300 Subject: [PATCH 05/11] Deleted unnecessary files --- CourseApp.Tests/Tests.cs | 8 ++++++ CourseApp.Tests/TestsForFunction.cs | 26 ------------------- CourseApp.Tests/TestsForPersons.cs | 40 ----------------------------- 3 files changed, 8 insertions(+), 66 deletions(-) create mode 100644 CourseApp.Tests/Tests.cs delete mode 100644 CourseApp.Tests/TestsForFunction.cs delete mode 100644 CourseApp.Tests/TestsForPersons.cs diff --git a/CourseApp.Tests/Tests.cs b/CourseApp.Tests/Tests.cs new file mode 100644 index 00000000..a8bb930f --- /dev/null +++ b/CourseApp.Tests/Tests.cs @@ -0,0 +1,8 @@ +namespace CourseApp.Tests +{ + using Xunit; + + public class Tests + { + } +} \ No newline at end of file diff --git a/CourseApp.Tests/TestsForFunction.cs b/CourseApp.Tests/TestsForFunction.cs deleted file mode 100644 index 0eba5fe0..00000000 --- a/CourseApp.Tests/TestsForFunction.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace CourseApp.Tests -{ - using Xunit; - - public class TestsForFunction - { - private readonly Function _function; - - public TestsForFunction() - { - _function = new Function(); - } - - [Theory] - [InlineData(1.2, 0.8256)] - [InlineData(1.7, 0.9182)] - [InlineData(2.2, 3.9286)] - [InlineData(3.7, 385.8624)] - public void RunTest(double x, double expected) - { - var a = 1.6; - var actual = _function.CalculateFunction(a, x); - Assert.Equal(expected, actual, 3); - } - } -} \ No newline at end of file diff --git a/CourseApp.Tests/TestsForPersons.cs b/CourseApp.Tests/TestsForPersons.cs deleted file mode 100644 index e565450b..00000000 --- a/CourseApp.Tests/TestsForPersons.cs +++ /dev/null @@ -1,40 +0,0 @@ -namespace CourseApp.Tests -{ - using CourseApp.Person; - using Xunit; - - public class TestsForPersons - { - [Fact] - public void GetNameOfStudent() - { - var student = new Student("Anatoliy Rumyantsev", 18, "Clown", 192); - var expected = "Anatoliy Rumyantsev"; - Assert.Equal(expected, student.Name); - } - - [Fact] - public void GetAgeOfStudent() - { - var student = new Student("Sergey Vasiliev", 25, "c400", 165); - var expected = 25; - Assert.Equal(expected, student.Age); - } - - [Fact] - public void GetGenderOfEmployee() - { - var employee = new Employee("Stas Tereshenko", 45, "T34", 180); - var expected = "T34"; - Assert.Equal(expected, employee.Gender); - } - - [Fact] - public void GetHeightOfEmployee() - { - var employee = new Employee("Anastasiya Kruchevskaya", 33, 174); - var expected = 174; - Assert.Equal(expected, employee.Height); - } - } -} \ No newline at end of file From c15e7fe3667aed3d4bd2ed78e97846816944af09 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 6 Feb 2022 15:11:23 +0300 Subject: [PATCH 06/11] RPGSaga: added abilities --- CourseApp/RPGSaga/Abilities/Attack.cs | 26 +++++++++++++++ CourseApp/RPGSaga/Abilities/FireArrows.cs | 29 +++++++++++++++++ CourseApp/RPGSaga/Abilities/Spellbinding.cs | 29 +++++++++++++++++ .../RPGSaga/Abilities/VengeanceStrike.cs | 32 +++++++++++++++++++ CourseApp/RPGSaga/Heroes/Archer.cs | 32 +++++++++++++++++++ CourseApp/RPGSaga/Heroes/Knight.cs | 31 ++++++++++++++++++ CourseApp/RPGSaga/Heroes/Player.cs | 9 ++++++ CourseApp/RPGSaga/Heroes/Wizard.cs | 31 ++++++++++++++++++ CourseApp/RPGSaga/Interfaces/IAbility.cs | 15 +++++++++ CourseApp/RPGSaga/Interfaces/IPlayer.cs | 10 +++++- 10 files changed, 243 insertions(+), 1 deletion(-) create mode 100644 CourseApp/RPGSaga/Abilities/Attack.cs create mode 100644 CourseApp/RPGSaga/Abilities/FireArrows.cs create mode 100644 CourseApp/RPGSaga/Abilities/Spellbinding.cs create mode 100644 CourseApp/RPGSaga/Abilities/VengeanceStrike.cs create mode 100644 CourseApp/RPGSaga/Interfaces/IAbility.cs diff --git a/CourseApp/RPGSaga/Abilities/Attack.cs b/CourseApp/RPGSaga/Abilities/Attack.cs new file mode 100644 index 00000000..f3a74176 --- /dev/null +++ b/CourseApp/RPGSaga/Abilities/Attack.cs @@ -0,0 +1,26 @@ +namespace CourseApp.RPGSaga.Abilities +{ + using CourseApp.RPGSaga.Interfaces; + + public class Attack : IAbility + { + public Attack() + { + Name = "Attack"; + IsPositive = false; + IsSkipRound = false; + ActionDuration = 1; + NumOfUses = 100000000; + } + + public string Name { get; } + + public bool IsPositive { get; } + + public bool IsSkipRound { get; } + + public int ActionDuration { get; } + + public int NumOfUses { get; } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Abilities/FireArrows.cs b/CourseApp/RPGSaga/Abilities/FireArrows.cs new file mode 100644 index 00000000..929fd225 --- /dev/null +++ b/CourseApp/RPGSaga/Abilities/FireArrows.cs @@ -0,0 +1,29 @@ +namespace CourseApp.RPGSaga.Abilities +{ + using CourseApp.RPGSaga.Interfaces; + + public class FireArrows : IAbility + { + private bool _isFire; + + public FireArrows() + { + Name = "Fire arrows"; + IsPositive = false; + IsSkipRound = false; + ActionDuration = 100000; + NumOfUses = 1; + _isFire = true; + } + + public string Name { get; } + + public bool IsPositive { get; } + + public bool IsSkipRound { get; } + + public int ActionDuration { get; } + + public int NumOfUses { get; } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Abilities/Spellbinding.cs b/CourseApp/RPGSaga/Abilities/Spellbinding.cs new file mode 100644 index 00000000..7613d170 --- /dev/null +++ b/CourseApp/RPGSaga/Abilities/Spellbinding.cs @@ -0,0 +1,29 @@ +namespace CourseApp.RPGSaga.Abilities +{ + using CourseApp.RPGSaga.Interfaces; + + public class Spellbinding : IAbility + { + public Spellbinding() + { + Name = "Spellbinding"; + IsPositive = false; + IsSkipRound = true; + ActionDuration = 1; + NumOfUses = 1; + Multiplier = 0; + } + + public string Name { get; } + + public bool IsPositive { get; } + + public bool IsSkipRound { get; } + + public int ActionDuration { get; } + + public int NumOfUses { get; } + + public double Multiplier { get; } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Abilities/VengeanceStrike.cs b/CourseApp/RPGSaga/Abilities/VengeanceStrike.cs new file mode 100644 index 00000000..a977490a --- /dev/null +++ b/CourseApp/RPGSaga/Abilities/VengeanceStrike.cs @@ -0,0 +1,32 @@ +namespace CourseApp.RPGSaga.Abilities +{ + using CourseApp.RPGSaga.Interfaces; + + public class VengeanceStrike : IAbility + { + public VengeanceStrike() + { + Multiplier = 1.3; + Name = "Vengeance Strike"; + IsPositive = false; + IsSkipRound = false; + ActionDuration = 1; + NumsPerRound = 1; + NumOfUses = 1; + } + + public string Name { get; } + + public bool IsPositive { get; } + + public bool IsSkipRound { get; } + + public int ActionDuration { get; } + + public int NumsPerRound { get; } + + public int NumOfUses { get; } + + public double Multiplier { get; } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Heroes/Archer.cs b/CourseApp/RPGSaga/Heroes/Archer.cs index 21f0238e..43711cae 100644 --- a/CourseApp/RPGSaga/Heroes/Archer.cs +++ b/CourseApp/RPGSaga/Heroes/Archer.cs @@ -1,10 +1,42 @@ namespace CourseApp.RPGSaga.Heroes { + using System.Collections.Generic; + using CourseApp.RPGSaga.Abilities; + using CourseApp.RPGSaga.Interfaces; + public class Archer : Player { + private List _abilities; + private List _effects; + public Archer(string name, int hp, int strength) : base(name, hp, strength) { + _abilities = new List(); + _effects = new List(); + } + + public override string ToString() + { + return $"Archer: {Name} HP: {HP} Strength: {Strength}"; + } + + public override void ApplyDamage(int damage) + { + throw new System.NotImplementedException(); + } + + public override List Abilities() + { + _abilities.Add(new Attack()); + _abilities.Add(new FireArrows()); + return _abilities; + } + + public override List Effects(IAbility effect) + { + _effects.Add(effect); + return _effects; } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Heroes/Knight.cs b/CourseApp/RPGSaga/Heroes/Knight.cs index 3b496c4a..e6c88451 100644 --- a/CourseApp/RPGSaga/Heroes/Knight.cs +++ b/CourseApp/RPGSaga/Heroes/Knight.cs @@ -1,10 +1,41 @@ namespace CourseApp.RPGSaga.Heroes { + using System.Collections.Generic; + using CourseApp.RPGSaga.Abilities; + using CourseApp.RPGSaga.Interfaces; + public class Knight : Player { + private List _abilities; + private List _effects; + public Knight(string name, int hp, int strength) : base(name, hp, strength) { + _abilities = new List(); + _effects = new List(); + } + + public override void ApplyDamage(int damage) + { + } + + public override List Abilities() + { + _abilities.Add(new Attack()); + _abilities.Add(new VengeanceStrike()); + return _abilities; + } + + public override List Effects(IAbility effect) + { + _effects.Add(effect); + return _effects; + } + + public override string ToString() + { + return $"Knight: {Name} HP: {HP} Strength: {Strength}"; } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Heroes/Player.cs b/CourseApp/RPGSaga/Heroes/Player.cs index 9195803e..7ad42d40 100644 --- a/CourseApp/RPGSaga/Heroes/Player.cs +++ b/CourseApp/RPGSaga/Heroes/Player.cs @@ -1,5 +1,8 @@ namespace CourseApp.RPGSaga.Heroes { + using System.Collections.Generic; + using CourseApp.RPGSaga.Interfaces; + public abstract class Player : IPlayer { private int _hp; @@ -53,5 +56,11 @@ public int Strength } } } + + public abstract void ApplyDamage(int damage); + + public abstract List Abilities(); + + public abstract List Effects(IAbility effect); } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Heroes/Wizard.cs b/CourseApp/RPGSaga/Heroes/Wizard.cs index 81ea58ff..9d348e98 100644 --- a/CourseApp/RPGSaga/Heroes/Wizard.cs +++ b/CourseApp/RPGSaga/Heroes/Wizard.cs @@ -1,10 +1,41 @@ namespace CourseApp.RPGSaga.Heroes { + using System.Collections.Generic; + using CourseApp.RPGSaga.Abilities; + using CourseApp.RPGSaga.Interfaces; + public class Wizard : Player { + private List _abilities; + private List _effects; + public Wizard(string name, int hp, int strength) : base(name, hp, strength) { + _abilities = new List(); + _effects = new List(); + } + + public override void ApplyDamage(int damage) + { + } + + public override List Abilities() + { + _abilities.Add(new Attack()); + _abilities.Add(new Spellbinding()); + return _abilities; + } + + public override List Effects(IAbility effect) + { + _effects.Add(effect); + return _effects; + } + + public override string ToString() + { + return $"Wizard: {Name} HP: {HP} Strength: {Strength}"; } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Interfaces/IAbility.cs b/CourseApp/RPGSaga/Interfaces/IAbility.cs new file mode 100644 index 00000000..90633cba --- /dev/null +++ b/CourseApp/RPGSaga/Interfaces/IAbility.cs @@ -0,0 +1,15 @@ +namespace CourseApp.RPGSaga.Interfaces +{ + public interface IAbility + { + string Name { get; } + + bool IsPositive { get; } + + bool IsSkipRound { get; } + + int ActionDuration { get; } + + int NumOfUses { get; } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Interfaces/IPlayer.cs b/CourseApp/RPGSaga/Interfaces/IPlayer.cs index 6035103c..1cab44b0 100644 --- a/CourseApp/RPGSaga/Interfaces/IPlayer.cs +++ b/CourseApp/RPGSaga/Interfaces/IPlayer.cs @@ -1,5 +1,7 @@ -namespace CourseApp.RPGSaga +namespace CourseApp.RPGSaga.Interfaces { + using System.Collections.Generic; + public interface IPlayer { string Name { get; set; } @@ -7,5 +9,11 @@ public interface IPlayer int HP { get; set; } int Strength { get; set; } + + void ApplyDamage(int damage); + + List Abilities(); + + List Effects(IAbility effect); } } \ No newline at end of file From e2ded5998e0f7e4a5884f49d95e0c6a85a1ebdc4 Mon Sep 17 00:00:00 2001 From: SunM1sty Date: Sat, 12 Feb 2022 23:09:12 +0300 Subject: [PATCH 07/11] RPGSaga many changes --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp/CourseApp.csproj | 2 +- CourseApp/Program.cs | 2 + CourseApp/RPGSaga/Abilities/Attack.cs | 20 ++++-- CourseApp/RPGSaga/Abilities/FireArrows.cs | 21 +++--- CourseApp/RPGSaga/Abilities/Spellbinding.cs | 18 +++-- .../RPGSaga/Abilities/VengeanceStrike.cs | 21 +++--- CourseApp/RPGSaga/GameBuilder/FightBuilder.cs | 45 +++++++++++++ CourseApp/RPGSaga/GameBuilder/GameBuilder.cs | 36 ++++++++++ CourseApp/RPGSaga/GameBuilder/Logger.cs | 12 ++++ CourseApp/RPGSaga/Generators/Fabric.cs | 9 +++ CourseApp/RPGSaga/Generators/PlayerFabric.cs | 58 ++++++++++++++++ .../Generators/TournamentListGenerator.cs | 51 ++++++++++++++ CourseApp/RPGSaga/Heroes/Archer.cs | 66 ++++++++++++++++--- CourseApp/RPGSaga/Heroes/Knight.cs | 56 +++++++++++++--- CourseApp/RPGSaga/Heroes/Player.cs | 19 ++++-- CourseApp/RPGSaga/Heroes/Wizard.cs | 56 +++++++++++++--- CourseApp/RPGSaga/Interfaces/IAbility.cs | 10 +-- CourseApp/RPGSaga/Interfaces/IFabric.cs | 7 ++ CourseApp/RPGSaga/Interfaces/IPlayer.cs | 14 ++-- CourseApp/RPGSaga/Interfaces/ISetTarget.cs | 7 ++ .../Interfaces/ITournamentListGenerator.cs | 12 ++++ Dockerfile | 4 +- 23 files changed, 475 insertions(+), 73 deletions(-) create mode 100644 CourseApp/RPGSaga/GameBuilder/FightBuilder.cs create mode 100644 CourseApp/RPGSaga/GameBuilder/GameBuilder.cs create mode 100644 CourseApp/RPGSaga/GameBuilder/Logger.cs create mode 100644 CourseApp/RPGSaga/Generators/Fabric.cs create mode 100644 CourseApp/RPGSaga/Generators/PlayerFabric.cs create mode 100644 CourseApp/RPGSaga/Generators/TournamentListGenerator.cs create mode 100644 CourseApp/RPGSaga/Interfaces/IFabric.cs create mode 100644 CourseApp/RPGSaga/Interfaces/ISetTarget.cs create mode 100644 CourseApp/RPGSaga/Interfaces/ITournamentListGenerator.cs diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 34066014..16f02d9d 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp5 + netcoreapp6 True false latest diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index 40d13afe..55bb3a1d 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp5 + netcoreapp6 True latest diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 84f7e748..49885b28 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -2,12 +2,14 @@ { using System; using System.Collections.Generic; + using CourseApp.RPGSaga.Heroes; using Kantaiko.ConsoleFormatting; public class Program { public static void Main(string[] args) { + var archer = new Archer("Volodya", 100, 50); } } } diff --git a/CourseApp/RPGSaga/Abilities/Attack.cs b/CourseApp/RPGSaga/Abilities/Attack.cs index f3a74176..18781b79 100644 --- a/CourseApp/RPGSaga/Abilities/Attack.cs +++ b/CourseApp/RPGSaga/Abilities/Attack.cs @@ -4,23 +4,31 @@ public class Attack : IAbility { - public Attack() + public Attack(int damage) { Name = "Attack"; - IsPositive = false; + Damage = damage; IsSkipRound = false; ActionDuration = 1; NumOfUses = 100000000; + IsFire = false; } - public string Name { get; } + public int Damage { get; set; } - public bool IsPositive { get; } + public string Name { get; } public bool IsSkipRound { get; } - public int ActionDuration { get; } + public int ActionDuration { get; set; } + + public int NumOfUses { get; set; } - public int NumOfUses { get; } + public bool IsFire { get; } + + public override string ToString() + { + return $"base attack"; + } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Abilities/FireArrows.cs b/CourseApp/RPGSaga/Abilities/FireArrows.cs index 929fd225..69b8ee9b 100644 --- a/CourseApp/RPGSaga/Abilities/FireArrows.cs +++ b/CourseApp/RPGSaga/Abilities/FireArrows.cs @@ -4,26 +4,31 @@ public class FireArrows : IAbility { - private bool _isFire; - public FireArrows() { + Damage = 0; Name = "Fire arrows"; - IsPositive = false; IsSkipRound = false; ActionDuration = 100000; NumOfUses = 1; - _isFire = true; + IsFire = true; } - public string Name { get; } + public int Damage { get; set; } - public bool IsPositive { get; } + public string Name { get; } public bool IsSkipRound { get; } - public int ActionDuration { get; } + public int ActionDuration { get; set; } + + public int NumOfUses { get; set; } - public int NumOfUses { get; } + public bool IsFire { get; } + + public override string ToString() + { + return $"fire arrows"; + } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Abilities/Spellbinding.cs b/CourseApp/RPGSaga/Abilities/Spellbinding.cs index 7613d170..a46c1a19 100644 --- a/CourseApp/RPGSaga/Abilities/Spellbinding.cs +++ b/CourseApp/RPGSaga/Abilities/Spellbinding.cs @@ -6,24 +6,32 @@ public class Spellbinding : IAbility { public Spellbinding() { + Damage = 0; Name = "Spellbinding"; - IsPositive = false; IsSkipRound = true; ActionDuration = 1; NumOfUses = 1; Multiplier = 0; + IsFire = false; } - public string Name { get; } + public int Damage { get; set; } - public bool IsPositive { get; } + public string Name { get; } public bool IsSkipRound { get; } - public int ActionDuration { get; } + public int ActionDuration { get; set; } + + public int NumOfUses { get; set; } - public int NumOfUses { get; } + public bool IsFire { get; } public double Multiplier { get; } + + public override string ToString() + { + return $"spellbinding"; + } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Abilities/VengeanceStrike.cs b/CourseApp/RPGSaga/Abilities/VengeanceStrike.cs index a977490a..3d1891f0 100644 --- a/CourseApp/RPGSaga/Abilities/VengeanceStrike.cs +++ b/CourseApp/RPGSaga/Abilities/VengeanceStrike.cs @@ -4,29 +4,34 @@ public class VengeanceStrike : IAbility { - public VengeanceStrike() + public VengeanceStrike(int damage) { Multiplier = 1.3; + Damage = (int)(Multiplier * damage); Name = "Vengeance Strike"; - IsPositive = false; IsSkipRound = false; ActionDuration = 1; - NumsPerRound = 1; NumOfUses = 1; + IsFire = false; } - public string Name { get; } + public int Damage { get; set; } - public bool IsPositive { get; } + public string Name { get; } public bool IsSkipRound { get; } - public int ActionDuration { get; } + public int ActionDuration { get; set; } - public int NumsPerRound { get; } + public int NumOfUses { get; set; } - public int NumOfUses { get; } + public bool IsFire { get; } public double Multiplier { get; } + + public override string ToString() + { + return $"vengeance strike"; + } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/GameBuilder/FightBuilder.cs b/CourseApp/RPGSaga/GameBuilder/FightBuilder.cs new file mode 100644 index 00000000..cba57557 --- /dev/null +++ b/CourseApp/RPGSaga/GameBuilder/FightBuilder.cs @@ -0,0 +1,45 @@ +namespace CourseApp.RPGSaga.GameBuilder +{ + using CourseApp.RPGSaga.Heroes; + + public class FightBuilder + { + private Player _p1; + private Player _p2; + private Player _winner; + private Player _looser; + + public FightBuilder(Player p1, Player p2) + { + _p1 = p1; + _p2 = p2; + } + + public Player StartFight() + { + Logger.WriteLog($"Fight: {_p1} ({_p1.GetType()}) against {_p2} ({_p2.GetType()})"); + while (!_p1.IsDead && !_p2.IsDead) + { + _p1.SetTarget(_p2); + _p1.MakeAMove(); + _p2.SetTarget(_p1); + _p2.MakeAMove(); + } + + if (_p1.IsDead) + { + _looser = _p1; + _winner = _p2; + } + else + { + _looser = _p2; + _winner = _p1; + } + + Logger.WriteLog($"Winner of this match is {_winner.ToString()}"); + Logger.WriteLog($"Such a good victory against {_looser.ToString()}"); + return _winner; + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/GameBuilder/GameBuilder.cs b/CourseApp/RPGSaga/GameBuilder/GameBuilder.cs new file mode 100644 index 00000000..ccf6ce42 --- /dev/null +++ b/CourseApp/RPGSaga/GameBuilder/GameBuilder.cs @@ -0,0 +1,36 @@ +namespace CourseApp.RPGSaga.GameBuilder +{ + using System.Collections.Generic; + using CourseApp.RPGSaga.Generators; + using CourseApp.RPGSaga.Heroes; + + public class GameBuilder + { + private int _listSize = 4; + private TournamentListGenerator _tournamentListGenerator; + private List _tournamentList; + private List _winners; + private FightBuilder _fight; + + public GameBuilder() + { + _tournamentListGenerator = new TournamentListGenerator(_listSize); + _tournamentList = new List(); + _winners = new List(); + } + + public void StartTournament() + { + _tournamentList = _tournamentListGenerator.GenerateTournamentList(); + RunRound(_tournamentList); + } + + public List RunRound(List players) + { + for (int i = 1; i < players.Count; i += 2) + { + _fight = new FightBuilder(players[i - 1], players[i]); + } + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/GameBuilder/Logger.cs b/CourseApp/RPGSaga/GameBuilder/Logger.cs new file mode 100644 index 00000000..88e481e4 --- /dev/null +++ b/CourseApp/RPGSaga/GameBuilder/Logger.cs @@ -0,0 +1,12 @@ +namespace CourseApp.RPGSaga.GameBuilder +{ + using System; + + public class Logger + { + public static void WriteLog(string massage) + { + Console.WriteLine(massage); + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Generators/Fabric.cs b/CourseApp/RPGSaga/Generators/Fabric.cs new file mode 100644 index 00000000..5260684a --- /dev/null +++ b/CourseApp/RPGSaga/Generators/Fabric.cs @@ -0,0 +1,9 @@ +namespace CourseApp.RPGSaga.Generators +{ + using CourseApp.RPGSaga.Interfaces; + + public abstract class Fabric : IFabric + { + public abstract IPlayer FactoryMethod(); + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Generators/PlayerFabric.cs b/CourseApp/RPGSaga/Generators/PlayerFabric.cs new file mode 100644 index 00000000..52d60aba --- /dev/null +++ b/CourseApp/RPGSaga/Generators/PlayerFabric.cs @@ -0,0 +1,58 @@ +namespace CourseApp.RPGSaga.Generators +{ + using System; + using System.Collections.Generic; + using CourseApp.RPGSaga.Heroes; + + public class PlayerFabric : Fabric + { + private List _name = new List() + { + "Артемий", "Ева", "Кира", "Платон", "Максим", "Владимир", "Алиса", "Василий", "София", "Ника", "Марьям", + "Тимофей", "Ангелина", "Мирон", "Антон", "Ярослав", "Иван", "Аделина", "Валерия", "Диана", "Дмитрий", + "Амина", "Алексей", "Кирилл", "Александр", "Даниил", "Агата", "Виктория", "Михаил", "Злата", "Илья", + "Дарья", "Ксения", + }; + + private List _heroesTypes = new List() { "Archer", "Knight", "Wizard" }; + + public override Player FactoryMethod() + { + return CreatePlayer(); + } + + private string SetName() + { + return _name[Random.Shared.Next(0, _name.Count)]; + } + + private int SetHP() + { + return Random.Shared.Next(70, 100); + } + + private int SetStrength() + { + return Random.Shared.Next(10, 15); + } + + private Player CreatePlayer() + { + Player hero = null; + switch (_heroesTypes[Random.Shared.Next(0, _heroesTypes.Count)]) + { + case "Archer": + hero = new Archer(SetName(), SetHP(), SetStrength()); + break; + case "Knight": + hero = new Knight(SetName(), SetHP(), SetStrength()); + break; + case "Wizard": + hero = new Wizard(SetName(), SetHP(), SetStrength()); + break; + } + + return hero; + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Generators/TournamentListGenerator.cs b/CourseApp/RPGSaga/Generators/TournamentListGenerator.cs new file mode 100644 index 00000000..8f941ec8 --- /dev/null +++ b/CourseApp/RPGSaga/Generators/TournamentListGenerator.cs @@ -0,0 +1,51 @@ +namespace CourseApp.RPGSaga.Generators +{ + using System; + using System.Collections.Generic; + using CourseApp.RPGSaga.Heroes; + using CourseApp.RPGSaga.Interfaces; + + public class TournamentListGenerator : ITournamentListGenerator + { + private int _listSize; + private PlayerFabric _playerFabric; + private List _tournamentList; + + public TournamentListGenerator(int listSize) + { + ListSize = listSize; + _playerFabric = new PlayerFabric(); + _tournamentList = new List(); + } + + public int ListSize + { + get + { + return _listSize; + } + + set + { + if (value >= 2 && value % 2 == 0) + { + _listSize = value; + } + else + { + Console.WriteLine("incorrect value"); + } + } + } + + public List GenerateTournamentList() + { + for (int i = 0; i < _listSize; i++) + { + _tournamentList.Add(_playerFabric.FactoryMethod()); + } + + return _tournamentList; + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Heroes/Archer.cs b/CourseApp/RPGSaga/Heroes/Archer.cs index 43711cae..b490e764 100644 --- a/CourseApp/RPGSaga/Heroes/Archer.cs +++ b/CourseApp/RPGSaga/Heroes/Archer.cs @@ -1,42 +1,88 @@ namespace CourseApp.RPGSaga.Heroes { + using System; using System.Collections.Generic; using CourseApp.RPGSaga.Abilities; using CourseApp.RPGSaga.Interfaces; public class Archer : Player { + private bool _isSkip; + private IPlayer _enemy; private List _abilities; private List _effects; public Archer(string name, int hp, int strength) : base(name, hp, strength) { - _abilities = new List(); + _abilities = new List() { new Attack(Strength), new FireArrows() }; _effects = new List(); } public override string ToString() { - return $"Archer: {Name} HP: {HP} Strength: {Strength}"; + return $"Archer: {Name} HP: {Hp} Strength: {Strength}"; } - public override void ApplyDamage(int damage) + public override void MakeAMove() { - throw new System.NotImplementedException(); + _isSkip = false; + foreach (var effect in _effects) + { + if (effect.IsSkipRound) + { + _isSkip = true; + } + + if (effect.IsFire) + { + IsFire = true; + } + + if (IsFire) + { + Hp -= 2; + } + + Hp -= effect.Damage; + if (Hp <= 0) + { + IsDead = true; + return; + } + + effect.ActionDuration -= 1; + if (effect.ActionDuration == 0) + { + _effects.Remove(effect); + } + } + + if (!_isSkip) + { + SetDamage(); + } + } + + public override void SetTarget(IPlayer enemy) + { + _enemy = enemy; } - public override List Abilities() + public override void SetDamage() { - _abilities.Add(new Attack()); - _abilities.Add(new FireArrows()); - return _abilities; + var randomIndex = Random.Shared.Next(0, _abilities.Count); + _enemy.AddEffect(_abilities[randomIndex]); + _abilities[randomIndex].NumOfUses -= 1; + if (_abilities[randomIndex].NumOfUses == 0) + { + _abilities.RemoveAt(randomIndex); + } } - public override List Effects(IAbility effect) + public override void AddEffect(IAbility effect) { _effects.Add(effect); - return _effects; } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Heroes/Knight.cs b/CourseApp/RPGSaga/Heroes/Knight.cs index e6c88451..b96be1af 100644 --- a/CourseApp/RPGSaga/Heroes/Knight.cs +++ b/CourseApp/RPGSaga/Heroes/Knight.cs @@ -1,41 +1,79 @@ namespace CourseApp.RPGSaga.Heroes { + using System; using System.Collections.Generic; using CourseApp.RPGSaga.Abilities; using CourseApp.RPGSaga.Interfaces; public class Knight : Player { + private bool _isSkip; + private IPlayer _enemy; private List _abilities; private List _effects; public Knight(string name, int hp, int strength) : base(name, hp, strength) { - _abilities = new List(); + _abilities = new List() { new Attack(Strength), new VengeanceStrike(Strength) }; _effects = new List(); } - public override void ApplyDamage(int damage) + public override void MakeAMove() { + _isSkip = false; + foreach (var effect in _effects) + { + if (effect.IsSkipRound) + { + _isSkip = true; + } + + if (IsFire) + { + Hp -= 2; + } + + Hp -= effect.Damage; + if (Hp <= 0) + { + IsDead = true; + return; + } + + effect.ActionDuration -= 1; + } + + if (!_isSkip) + { + SetDamage(); + } + } + + public override void SetTarget(IPlayer enemy) + { + _enemy = enemy; } - public override List Abilities() + public override void SetDamage() { - _abilities.Add(new Attack()); - _abilities.Add(new VengeanceStrike()); - return _abilities; + var randomIndex = Random.Shared.Next(0, _abilities.Count); + _enemy.AddEffect(_abilities[randomIndex]); + _abilities[randomIndex].NumOfUses -= 1; + if (_abilities[randomIndex].NumOfUses == 0) + { + _abilities.RemoveAt(randomIndex); + } } - public override List Effects(IAbility effect) + public override void AddEffect(IAbility effect) { _effects.Add(effect); - return _effects; } public override string ToString() { - return $"Knight: {Name} HP: {HP} Strength: {Strength}"; + return $"Knight: {Name} HP: {Hp} Strength: {Strength}"; } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Heroes/Player.cs b/CourseApp/RPGSaga/Heroes/Player.cs index 7ad42d40..71a6c47a 100644 --- a/CourseApp/RPGSaga/Heroes/Player.cs +++ b/CourseApp/RPGSaga/Heroes/Player.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using CourseApp.RPGSaga.Interfaces; - public abstract class Player : IPlayer + public abstract class Player : IPlayer, ISetTarget { private int _hp; private int _strength; @@ -11,13 +11,14 @@ public abstract class Player : IPlayer public Player(string name, int hp, int strength) { Name = name; - HP = hp; + Hp = hp; Strength = strength; + IsDead = false; } public string Name { get; set; } - public int HP + public int Hp { get { @@ -57,10 +58,16 @@ public int Strength } } - public abstract void ApplyDamage(int damage); + public bool IsFire { get; set; } - public abstract List Abilities(); + public bool IsDead { get; set; } - public abstract List Effects(IAbility effect); + public abstract void MakeAMove(); + + public abstract void AddEffect(IAbility effect); + + public abstract void SetTarget(IPlayer enemy); + + public abstract void SetDamage(); } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Heroes/Wizard.cs b/CourseApp/RPGSaga/Heroes/Wizard.cs index 9d348e98..7ae2d7ff 100644 --- a/CourseApp/RPGSaga/Heroes/Wizard.cs +++ b/CourseApp/RPGSaga/Heroes/Wizard.cs @@ -1,41 +1,79 @@ namespace CourseApp.RPGSaga.Heroes { + using System; using System.Collections.Generic; using CourseApp.RPGSaga.Abilities; using CourseApp.RPGSaga.Interfaces; public class Wizard : Player { + private bool _isSkip; + private IPlayer _enemy; private List _abilities; private List _effects; public Wizard(string name, int hp, int strength) : base(name, hp, strength) { - _abilities = new List(); + _abilities = new List() { new Attack(Strength), new Spellbinding() }; _effects = new List(); } - public override void ApplyDamage(int damage) + public override void MakeAMove() { + _isSkip = false; + foreach (var effect in _effects) + { + if (effect.IsSkipRound) + { + _isSkip = true; + } + + if (IsFire) + { + Hp -= 2; + } + + Hp -= effect.Damage; + if (Hp <= 0) + { + IsDead = true; + return; + } + + effect.ActionDuration -= 1; + } + + if (!_isSkip) + { + SetDamage(); + } + } + + public override void SetTarget(IPlayer enemy) + { + _enemy = enemy; } - public override List Abilities() + public override void SetDamage() { - _abilities.Add(new Attack()); - _abilities.Add(new Spellbinding()); - return _abilities; + var randomIndex = Random.Shared.Next(0, _abilities.Count); + _enemy.AddEffect(_abilities[randomIndex]); + _abilities[randomIndex].NumOfUses -= 1; + if (_abilities[randomIndex].NumOfUses == 0) + { + _abilities.RemoveAt(randomIndex); + } } - public override List Effects(IAbility effect) + public override void AddEffect(IAbility effect) { _effects.Add(effect); - return _effects; } public override string ToString() { - return $"Wizard: {Name} HP: {HP} Strength: {Strength}"; + return $"Wizard: {Name} HP: {Hp} Strength: {Strength}"; } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Interfaces/IAbility.cs b/CourseApp/RPGSaga/Interfaces/IAbility.cs index 90633cba..91c41272 100644 --- a/CourseApp/RPGSaga/Interfaces/IAbility.cs +++ b/CourseApp/RPGSaga/Interfaces/IAbility.cs @@ -2,14 +2,16 @@ { public interface IAbility { - string Name { get; } + int Damage { get; set; } - bool IsPositive { get; } + string Name { get; } bool IsSkipRound { get; } - int ActionDuration { get; } + int ActionDuration { get; set; } + + int NumOfUses { get; set; } - int NumOfUses { get; } + bool IsFire { get; } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Interfaces/IFabric.cs b/CourseApp/RPGSaga/Interfaces/IFabric.cs new file mode 100644 index 00000000..a33db6dd --- /dev/null +++ b/CourseApp/RPGSaga/Interfaces/IFabric.cs @@ -0,0 +1,7 @@ +namespace CourseApp.RPGSaga.Interfaces +{ + public interface IFabric + { + IPlayer FactoryMethod(); + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Interfaces/IPlayer.cs b/CourseApp/RPGSaga/Interfaces/IPlayer.cs index 1cab44b0..e8d8d896 100644 --- a/CourseApp/RPGSaga/Interfaces/IPlayer.cs +++ b/CourseApp/RPGSaga/Interfaces/IPlayer.cs @@ -6,14 +6,20 @@ public interface IPlayer { string Name { get; set; } - int HP { get; set; } + int Hp { get; set; } int Strength { get; set; } - void ApplyDamage(int damage); + bool IsFire { get; set; } - List Abilities(); + bool IsDead { get; set; } - List Effects(IAbility effect); + void MakeAMove(); + + void SetTarget(IPlayer enemy); + + void SetDamage(); + + void AddEffect(IAbility effect); } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Interfaces/ISetTarget.cs b/CourseApp/RPGSaga/Interfaces/ISetTarget.cs new file mode 100644 index 00000000..39c09955 --- /dev/null +++ b/CourseApp/RPGSaga/Interfaces/ISetTarget.cs @@ -0,0 +1,7 @@ +namespace CourseApp.RPGSaga.Interfaces +{ + public interface ISetTarget + { + void SetTarget(IPlayer enemy); + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Interfaces/ITournamentListGenerator.cs b/CourseApp/RPGSaga/Interfaces/ITournamentListGenerator.cs new file mode 100644 index 00000000..6432fb66 --- /dev/null +++ b/CourseApp/RPGSaga/Interfaces/ITournamentListGenerator.cs @@ -0,0 +1,12 @@ +namespace CourseApp.RPGSaga.Interfaces +{ + using System.Collections.Generic; + using CourseApp.RPGSaga.Heroes; + + public interface ITournamentListGenerator + { + int ListSize { get; set; } + + List GenerateTournamentList(); + } +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 179909b7..f75dc413 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/core/sdk:5.0 AS build-env +FROM mcr.microsoft.com/dotnet/core/sdk:6.0 AS build-env WORKDIR /app # Copy csproj and restore as distinct layers @@ -11,7 +11,7 @@ COPY ./_stylecop/ /_stylecop/ RUN dotnet publish -c Release -o out # Build runtime image -FROM mcr.microsoft.com/dotnet/core/aspnet:5.0 +FROM mcr.microsoft.com/dotnet/core/aspnet:6.0 WORKDIR /app COPY --from=build-env /app/out . ENTRYPOINT ["dotnet", "CourseApp.dll"] From e4ae775ba69eabc70636c2d3e7b8e7b210ec6695 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 12 Feb 2022 23:44:59 +0300 Subject: [PATCH 08/11] Work is continuing --- CourseApp/Program.cs | 5 +++- CourseApp/RPGSaga/GameBuilder/FightBuilder.cs | 2 +- CourseApp/RPGSaga/GameBuilder/GameBuilder.cs | 9 +++++++ CourseApp/RPGSaga/Heroes/Archer.cs | 7 +++++ CourseApp/RPGSaga/Heroes/Knight.cs | 26 +++++++++++++++---- CourseApp/RPGSaga/Heroes/Wizard.cs | 16 ++++++++++++ 6 files changed, 58 insertions(+), 7 deletions(-) diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 49885b28..8d9b3bc1 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -2,6 +2,7 @@ { using System; using System.Collections.Generic; + using CourseApp.RPGSaga.GameBuilder; using CourseApp.RPGSaga.Heroes; using Kantaiko.ConsoleFormatting; @@ -9,7 +10,9 @@ public class Program { public static void Main(string[] args) { - var archer = new Archer("Volodya", 100, 50); + var tournam = new GameBuilder(); + tournam.StartTournament(); + tournam.GetWinner(); } } } diff --git a/CourseApp/RPGSaga/GameBuilder/FightBuilder.cs b/CourseApp/RPGSaga/GameBuilder/FightBuilder.cs index cba57557..2f5ed11c 100644 --- a/CourseApp/RPGSaga/GameBuilder/FightBuilder.cs +++ b/CourseApp/RPGSaga/GameBuilder/FightBuilder.cs @@ -17,7 +17,7 @@ public FightBuilder(Player p1, Player p2) public Player StartFight() { - Logger.WriteLog($"Fight: {_p1} ({_p1.GetType()}) against {_p2} ({_p2.GetType()})"); + Logger.WriteLog($"Fight: {_p1.ToString()} against {_p2.ToString()}"); while (!_p1.IsDead && !_p2.IsDead) { _p1.SetTarget(_p2); diff --git a/CourseApp/RPGSaga/GameBuilder/GameBuilder.cs b/CourseApp/RPGSaga/GameBuilder/GameBuilder.cs index ccf6ce42..6bea4f9e 100644 --- a/CourseApp/RPGSaga/GameBuilder/GameBuilder.cs +++ b/CourseApp/RPGSaga/GameBuilder/GameBuilder.cs @@ -27,10 +27,19 @@ public void StartTournament() public List RunRound(List players) { + _winners.Clear(); for (int i = 1; i < players.Count; i += 2) { _fight = new FightBuilder(players[i - 1], players[i]); + _winners.Add(_fight.StartFight()); } + + return RunRound(_winners); + } + + public void GetWinner() + { + Logger.WriteLog($"Winner is {_winners[0].Name} {_winners[0].GetType()}"); } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Heroes/Archer.cs b/CourseApp/RPGSaga/Heroes/Archer.cs index b490e764..23999434 100644 --- a/CourseApp/RPGSaga/Heroes/Archer.cs +++ b/CourseApp/RPGSaga/Heroes/Archer.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using CourseApp.RPGSaga.Abilities; + using CourseApp.RPGSaga.GameBuilder; using CourseApp.RPGSaga.Interfaces; public class Archer : Player @@ -32,11 +33,13 @@ public override void MakeAMove() if (effect.IsSkipRound) { _isSkip = true; + Logger.WriteLog($"{GetType()} {Name} is frozen right now, so he miss this step"); } if (effect.IsFire) { IsFire = true; + Logger.WriteLog($"{GetType()} {Name} is burning now"); } if (IsFire) @@ -45,6 +48,7 @@ public override void MakeAMove() } Hp -= effect.Damage; + Logger.WriteLog($"{GetType()} {Name} has {Hp} HP"); if (Hp <= 0) { IsDead = true; @@ -55,6 +59,7 @@ public override void MakeAMove() if (effect.ActionDuration == 0) { _effects.Remove(effect); + Logger.WriteLog($"Duration of {effect.Name} is ended"); } } @@ -73,10 +78,12 @@ public override void SetDamage() { var randomIndex = Random.Shared.Next(0, _abilities.Count); _enemy.AddEffect(_abilities[randomIndex]); + Logger.WriteLog($"{GetType()} {Name} used {_abilities[randomIndex].Name} against {GetType()} {_enemy.Name}"); _abilities[randomIndex].NumOfUses -= 1; if (_abilities[randomIndex].NumOfUses == 0) { _abilities.RemoveAt(randomIndex); + Logger.WriteLog($"{GetType()} {Name} used maximum times of {_abilities[randomIndex].Name}"); } } diff --git a/CourseApp/RPGSaga/Heroes/Knight.cs b/CourseApp/RPGSaga/Heroes/Knight.cs index b96be1af..20c8d30f 100644 --- a/CourseApp/RPGSaga/Heroes/Knight.cs +++ b/CourseApp/RPGSaga/Heroes/Knight.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using CourseApp.RPGSaga.Abilities; + using CourseApp.RPGSaga.GameBuilder; using CourseApp.RPGSaga.Interfaces; public class Knight : Player @@ -27,6 +28,13 @@ public override void MakeAMove() if (effect.IsSkipRound) { _isSkip = true; + Logger.WriteLog($"{GetType()} {Name} is frozen right now, so he miss this step"); + } + + if (effect.IsFire) + { + IsFire = true; + Logger.WriteLog($"{GetType()} {Name} is burning now"); } if (IsFire) @@ -35,6 +43,7 @@ public override void MakeAMove() } Hp -= effect.Damage; + Logger.WriteLog($"{GetType()} {Name} has {Hp} HP"); if (Hp <= 0) { IsDead = true; @@ -42,6 +51,11 @@ public override void MakeAMove() } effect.ActionDuration -= 1; + if (effect.ActionDuration == 0) + { + _effects.Remove(effect); + Logger.WriteLog($"Duration of {effect.Name} is ended"); + } } if (!_isSkip) @@ -50,6 +64,11 @@ public override void MakeAMove() } } + public override void AddEffect(IAbility effect) + { + _effects.Add(effect); + } + public override void SetTarget(IPlayer enemy) { _enemy = enemy; @@ -59,18 +78,15 @@ public override void SetDamage() { var randomIndex = Random.Shared.Next(0, _abilities.Count); _enemy.AddEffect(_abilities[randomIndex]); + Logger.WriteLog($"{GetType()} {Name} used {_abilities[randomIndex].Name} against {GetType()} {_enemy.Name}"); _abilities[randomIndex].NumOfUses -= 1; if (_abilities[randomIndex].NumOfUses == 0) { _abilities.RemoveAt(randomIndex); + Logger.WriteLog($"{GetType()} {Name} used maximum times of {_abilities[randomIndex].Name}"); } } - public override void AddEffect(IAbility effect) - { - _effects.Add(effect); - } - public override string ToString() { return $"Knight: {Name} HP: {Hp} Strength: {Strength}"; diff --git a/CourseApp/RPGSaga/Heroes/Wizard.cs b/CourseApp/RPGSaga/Heroes/Wizard.cs index 7ae2d7ff..b7bea690 100644 --- a/CourseApp/RPGSaga/Heroes/Wizard.cs +++ b/CourseApp/RPGSaga/Heroes/Wizard.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using CourseApp.RPGSaga.Abilities; + using CourseApp.RPGSaga.GameBuilder; using CourseApp.RPGSaga.Interfaces; public class Wizard : Player @@ -27,6 +28,13 @@ public override void MakeAMove() if (effect.IsSkipRound) { _isSkip = true; + Logger.WriteLog($"{GetType()} {Name} is frozen right now, so he miss this step"); + } + + if (effect.IsFire) + { + IsFire = true; + Logger.WriteLog($"{GetType()} {Name} is burning now"); } if (IsFire) @@ -35,6 +43,7 @@ public override void MakeAMove() } Hp -= effect.Damage; + Logger.WriteLog($"{GetType()} {Name} has {Hp} HP"); if (Hp <= 0) { IsDead = true; @@ -42,6 +51,11 @@ public override void MakeAMove() } effect.ActionDuration -= 1; + if (effect.ActionDuration == 0) + { + _effects.Remove(effect); + Logger.WriteLog($"Duration of {effect.Name} is ended"); + } } if (!_isSkip) @@ -59,10 +73,12 @@ public override void SetDamage() { var randomIndex = Random.Shared.Next(0, _abilities.Count); _enemy.AddEffect(_abilities[randomIndex]); + Logger.WriteLog($"{GetType()} {Name} used {_abilities[randomIndex].Name} against {GetType()} {_enemy.Name}"); _abilities[randomIndex].NumOfUses -= 1; if (_abilities[randomIndex].NumOfUses == 0) { _abilities.RemoveAt(randomIndex); + Logger.WriteLog($"{GetType()} {Name} used maximum times of {_abilities[randomIndex].Name}"); } } From f36c3feb2e218a723da8dd18077a6580ec0ee461 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 13 Feb 2022 10:12:33 +0300 Subject: [PATCH 09/11] Whouuuuuuaaa it works --- CourseApp/Program.cs | 10 +++-- CourseApp/RPGSaga/GameBuilder/FightBuilder.cs | 10 +++-- CourseApp/RPGSaga/Heroes/Archer.cs | 38 +++++++++++-------- CourseApp/RPGSaga/Heroes/Knight.cs | 26 ++++++++----- CourseApp/RPGSaga/Heroes/Player.cs | 21 +--------- CourseApp/RPGSaga/Heroes/Wizard.cs | 36 +++++++++++------- CourseApp/RPGSaga/Interfaces/IPlayer.cs | 2 +- README.md | 7 ++-- 8 files changed, 81 insertions(+), 69 deletions(-) diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 8d9b3bc1..0e11cd1c 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using CourseApp.RPGSaga.GameBuilder; + using CourseApp.RPGSaga.Generators; using CourseApp.RPGSaga.Heroes; using Kantaiko.ConsoleFormatting; @@ -10,9 +11,12 @@ public class Program { public static void Main(string[] args) { - var tournam = new GameBuilder(); - tournam.StartTournament(); - tournam.GetWinner(); + var pfabric = new PlayerFabric(); + var p1 = pfabric.FactoryMethod(); + var p2 = pfabric.FactoryMethod(); + var fight = new FightBuilder(p1, p2); + fight.SetTragets(); + fight.StartFight(); } } } diff --git a/CourseApp/RPGSaga/GameBuilder/FightBuilder.cs b/CourseApp/RPGSaga/GameBuilder/FightBuilder.cs index 2f5ed11c..3cc546ab 100644 --- a/CourseApp/RPGSaga/GameBuilder/FightBuilder.cs +++ b/CourseApp/RPGSaga/GameBuilder/FightBuilder.cs @@ -15,14 +15,18 @@ public FightBuilder(Player p1, Player p2) _p2 = p2; } + public void SetTragets() + { + _p1.SetTarget(_p2); + _p2.SetTarget(_p1); + } + public Player StartFight() { - Logger.WriteLog($"Fight: {_p1.ToString()} against {_p2.ToString()}"); + Logger.WriteLog($"Fight: [{_p1.ToString()} {_p1.Hp} HP {_p1.Strength} Strength] against [{_p2.ToString()} {_p2.Hp} HP {_p2.Strength} Strength]"); while (!_p1.IsDead && !_p2.IsDead) { - _p1.SetTarget(_p2); _p1.MakeAMove(); - _p2.SetTarget(_p1); _p2.MakeAMove(); } diff --git a/CourseApp/RPGSaga/Heroes/Archer.cs b/CourseApp/RPGSaga/Heroes/Archer.cs index 23999434..b2927dd3 100644 --- a/CourseApp/RPGSaga/Heroes/Archer.cs +++ b/CourseApp/RPGSaga/Heroes/Archer.cs @@ -2,6 +2,7 @@ { using System; using System.Collections.Generic; + using System.Linq; using CourseApp.RPGSaga.Abilities; using CourseApp.RPGSaga.GameBuilder; using CourseApp.RPGSaga.Interfaces; @@ -20,26 +21,22 @@ public Archer(string name, int hp, int strength) _effects = new List(); } - public override string ToString() - { - return $"Archer: {Name} HP: {Hp} Strength: {Strength}"; - } - public override void MakeAMove() { _isSkip = false; - foreach (var effect in _effects) + List effects = _effects; + foreach (var effect in effects) { if (effect.IsSkipRound) { _isSkip = true; - Logger.WriteLog($"{GetType()} {Name} is frozen right now, so he miss this step"); + Logger.WriteLog($"{ToString()} is skipping step"); } if (effect.IsFire) { IsFire = true; - Logger.WriteLog($"{GetType()} {Name} is burning now"); + Logger.WriteLog($"{ToString()} is burning"); } if (IsFire) @@ -48,7 +45,6 @@ public override void MakeAMove() } Hp -= effect.Damage; - Logger.WriteLog($"{GetType()} {Name} has {Hp} HP"); if (Hp <= 0) { IsDead = true; @@ -56,19 +52,31 @@ public override void MakeAMove() } effect.ActionDuration -= 1; - if (effect.ActionDuration == 0) + if (effect.ActionDuration <= 0) { _effects.Remove(effect); - Logger.WriteLog($"Duration of {effect.Name} is ended"); + } + + if (effects.Count <= 1) + { + break; } } + Logger.WriteLog($"{ToString()} has {Hp} HP"); + Logger.WriteLog("-------------------------------------------------------"); + if (!_isSkip) { SetDamage(); } } + public override void AddEffect(IAbility effect) + { + _effects.Add(effect); + } + public override void SetTarget(IPlayer enemy) { _enemy = enemy; @@ -78,18 +86,18 @@ public override void SetDamage() { var randomIndex = Random.Shared.Next(0, _abilities.Count); _enemy.AddEffect(_abilities[randomIndex]); - Logger.WriteLog($"{GetType()} {Name} used {_abilities[randomIndex].Name} against {GetType()} {_enemy.Name}"); + Logger.WriteLog($"{ToString()} used {_abilities[randomIndex].Name} against {_enemy.ToString()}"); _abilities[randomIndex].NumOfUses -= 1; if (_abilities[randomIndex].NumOfUses == 0) { + Logger.WriteLog($"{ToString()} used maximum times of {_abilities[randomIndex].Name}"); _abilities.RemoveAt(randomIndex); - Logger.WriteLog($"{GetType()} {Name} used maximum times of {_abilities[randomIndex].Name}"); } } - public override void AddEffect(IAbility effect) + public override string ToString() { - _effects.Add(effect); + return $"Archer: {Name}"; } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Heroes/Knight.cs b/CourseApp/RPGSaga/Heroes/Knight.cs index 20c8d30f..6c9733e6 100644 --- a/CourseApp/RPGSaga/Heroes/Knight.cs +++ b/CourseApp/RPGSaga/Heroes/Knight.cs @@ -2,6 +2,7 @@ { using System; using System.Collections.Generic; + using System.Linq; using CourseApp.RPGSaga.Abilities; using CourseApp.RPGSaga.GameBuilder; using CourseApp.RPGSaga.Interfaces; @@ -23,18 +24,19 @@ public Knight(string name, int hp, int strength) public override void MakeAMove() { _isSkip = false; - foreach (var effect in _effects) + List effects = _effects; + foreach (var effect in effects) { if (effect.IsSkipRound) { _isSkip = true; - Logger.WriteLog($"{GetType()} {Name} is frozen right now, so he miss this step"); + Logger.WriteLog($"{ToString()} is skipping step"); } if (effect.IsFire) { IsFire = true; - Logger.WriteLog($"{GetType()} {Name} is burning now"); + Logger.WriteLog($"{ToString()} is burning"); } if (IsFire) @@ -43,7 +45,6 @@ public override void MakeAMove() } Hp -= effect.Damage; - Logger.WriteLog($"{GetType()} {Name} has {Hp} HP"); if (Hp <= 0) { IsDead = true; @@ -51,13 +52,20 @@ public override void MakeAMove() } effect.ActionDuration -= 1; - if (effect.ActionDuration == 0) + if (effect.ActionDuration <= 0) { _effects.Remove(effect); - Logger.WriteLog($"Duration of {effect.Name} is ended"); + } + + if (_effects.Count <= 1) + { + break; } } + Logger.WriteLog($"{ToString()} has {Hp} HP"); + Logger.WriteLog("-------------------------------------------------------"); + if (!_isSkip) { SetDamage(); @@ -78,18 +86,18 @@ public override void SetDamage() { var randomIndex = Random.Shared.Next(0, _abilities.Count); _enemy.AddEffect(_abilities[randomIndex]); - Logger.WriteLog($"{GetType()} {Name} used {_abilities[randomIndex].Name} against {GetType()} {_enemy.Name}"); + Logger.WriteLog($"{ToString()} used {_abilities[randomIndex].Name} against {_enemy.ToString()}"); _abilities[randomIndex].NumOfUses -= 1; if (_abilities[randomIndex].NumOfUses == 0) { + Logger.WriteLog($"{ToString()} used maximum times of {_abilities[randomIndex].Name}"); _abilities.RemoveAt(randomIndex); - Logger.WriteLog($"{GetType()} {Name} used maximum times of {_abilities[randomIndex].Name}"); } } public override string ToString() { - return $"Knight: {Name} HP: {Hp} Strength: {Strength}"; + return $"Knight: {Name}"; } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Heroes/Player.cs b/CourseApp/RPGSaga/Heroes/Player.cs index 71a6c47a..5ac70b52 100644 --- a/CourseApp/RPGSaga/Heroes/Player.cs +++ b/CourseApp/RPGSaga/Heroes/Player.cs @@ -5,7 +5,6 @@ public abstract class Player : IPlayer, ISetTarget { - private int _hp; private int _strength; public Player(string name, int hp, int strength) @@ -18,25 +17,7 @@ public Player(string name, int hp, int strength) public string Name { get; set; } - public int Hp - { - get - { - return _hp; - } - - set - { - if (value > 0) - { - _hp = value; - } - else - { - _hp = 10; - } - } - } + public int Hp { get; protected set; } public int Strength { diff --git a/CourseApp/RPGSaga/Heroes/Wizard.cs b/CourseApp/RPGSaga/Heroes/Wizard.cs index b7bea690..35dac339 100644 --- a/CourseApp/RPGSaga/Heroes/Wizard.cs +++ b/CourseApp/RPGSaga/Heroes/Wizard.cs @@ -2,6 +2,7 @@ { using System; using System.Collections.Generic; + using System.Linq; using CourseApp.RPGSaga.Abilities; using CourseApp.RPGSaga.GameBuilder; using CourseApp.RPGSaga.Interfaces; @@ -23,18 +24,19 @@ public Wizard(string name, int hp, int strength) public override void MakeAMove() { _isSkip = false; - foreach (var effect in _effects) + List effects = _effects; + foreach (var effect in effects) { if (effect.IsSkipRound) { _isSkip = true; - Logger.WriteLog($"{GetType()} {Name} is frozen right now, so he miss this step"); + Logger.WriteLog($"{ToString()} is skipping step"); } if (effect.IsFire) { IsFire = true; - Logger.WriteLog($"{GetType()} {Name} is burning now"); + Logger.WriteLog($"{ToString()} is burning"); } if (IsFire) @@ -43,7 +45,6 @@ public override void MakeAMove() } Hp -= effect.Damage; - Logger.WriteLog($"{GetType()} {Name} has {Hp} HP"); if (Hp <= 0) { IsDead = true; @@ -51,19 +52,31 @@ public override void MakeAMove() } effect.ActionDuration -= 1; - if (effect.ActionDuration == 0) + if (effect.ActionDuration <= 0) { _effects.Remove(effect); - Logger.WriteLog($"Duration of {effect.Name} is ended"); + } + + if (_effects.Count <= 1) + { + break; } } + Logger.WriteLog($"{ToString()} has {Hp} HP"); + Logger.WriteLog("-------------------------------------------------------"); + if (!_isSkip) { SetDamage(); } } + public override void AddEffect(IAbility effect) + { + _effects.Add(effect); + } + public override void SetTarget(IPlayer enemy) { _enemy = enemy; @@ -73,23 +86,18 @@ public override void SetDamage() { var randomIndex = Random.Shared.Next(0, _abilities.Count); _enemy.AddEffect(_abilities[randomIndex]); - Logger.WriteLog($"{GetType()} {Name} used {_abilities[randomIndex].Name} against {GetType()} {_enemy.Name}"); + Logger.WriteLog($"{ToString()} used {_abilities[randomIndex].Name} against {_enemy.ToString()}"); _abilities[randomIndex].NumOfUses -= 1; if (_abilities[randomIndex].NumOfUses == 0) { + Logger.WriteLog($"{ToString()} used maximum times of {_abilities[randomIndex].Name}"); _abilities.RemoveAt(randomIndex); - Logger.WriteLog($"{GetType()} {Name} used maximum times of {_abilities[randomIndex].Name}"); } } - public override void AddEffect(IAbility effect) - { - _effects.Add(effect); - } - public override string ToString() { - return $"Wizard: {Name} HP: {Hp} Strength: {Strength}"; + return $"Wizard: {Name}"; } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Interfaces/IPlayer.cs b/CourseApp/RPGSaga/Interfaces/IPlayer.cs index e8d8d896..7618af73 100644 --- a/CourseApp/RPGSaga/Interfaces/IPlayer.cs +++ b/CourseApp/RPGSaga/Interfaces/IPlayer.cs @@ -6,7 +6,7 @@ public interface IPlayer { string Name { get; set; } - int Hp { get; set; } + int Hp { get; } int Strength { get; set; } diff --git a/README.md b/README.md index ee351e79..43e22d9b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # Tprogramming 2021 -Vladimir =) - -Pushed via SSH connection... -Everything is alright=) +``` +RPGSaga +``` \ No newline at end of file From 130c4b725d9f3f2c5a8a8be359b5735f97546c15 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 14 Feb 2022 08:21:22 +0300 Subject: [PATCH 10/11] last version of RPGSaga --- CourseApp/Program.cs | 14 +---- CourseApp/RPGSaga/Abilities/Attack.cs | 4 +- CourseApp/RPGSaga/Abilities/FireArrows.cs | 3 +- CourseApp/RPGSaga/Abilities/Spellbinding.cs | 5 +- .../RPGSaga/Abilities/VengeanceStrike.cs | 10 +++- CourseApp/RPGSaga/GameBuilder/FightBuilder.cs | 12 ++-- CourseApp/RPGSaga/GameBuilder/GameBuilder.cs | 55 +++++++++++++++---- CourseApp/RPGSaga/Generators/PlayerFabric.cs | 21 +------ .../Generators/TournamentListGenerator.cs | 17 ++---- CourseApp/RPGSaga/Heroes/Archer.cs | 17 +++++- CourseApp/RPGSaga/Heroes/Knight.cs | 20 ++++++- CourseApp/RPGSaga/Heroes/Player.cs | 24 +++----- CourseApp/RPGSaga/Heroes/Wizard.cs | 17 +++++- 13 files changed, 132 insertions(+), 87 deletions(-) diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 0e11cd1c..a94350eb 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,22 +1,14 @@ namespace CourseApp { - using System; - using System.Collections.Generic; using CourseApp.RPGSaga.GameBuilder; - using CourseApp.RPGSaga.Generators; - using CourseApp.RPGSaga.Heroes; - using Kantaiko.ConsoleFormatting; public class Program { public static void Main(string[] args) { - var pfabric = new PlayerFabric(); - var p1 = pfabric.FactoryMethod(); - var p2 = pfabric.FactoryMethod(); - var fight = new FightBuilder(p1, p2); - fight.SetTragets(); - fight.StartFight(); + var gameBuilder = new GameBuilder(4); + gameBuilder.StartTournament(); + gameBuilder.GetWinner(); } } } diff --git a/CourseApp/RPGSaga/Abilities/Attack.cs b/CourseApp/RPGSaga/Abilities/Attack.cs index 18781b79..b6dc8226 100644 --- a/CourseApp/RPGSaga/Abilities/Attack.cs +++ b/CourseApp/RPGSaga/Abilities/Attack.cs @@ -22,13 +22,15 @@ public Attack(int damage) public int ActionDuration { get; set; } + public double Multiplier { get; set; } + public int NumOfUses { get; set; } public bool IsFire { get; } public override string ToString() { - return $"base attack"; + return $"{Name}"; } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Abilities/FireArrows.cs b/CourseApp/RPGSaga/Abilities/FireArrows.cs index 69b8ee9b..095419a0 100644 --- a/CourseApp/RPGSaga/Abilities/FireArrows.cs +++ b/CourseApp/RPGSaga/Abilities/FireArrows.cs @@ -1,5 +1,6 @@ namespace CourseApp.RPGSaga.Abilities { + using System.ComponentModel; using CourseApp.RPGSaga.Interfaces; public class FireArrows : IAbility @@ -28,7 +29,7 @@ public FireArrows() public override string ToString() { - return $"fire arrows"; + return $"{Name}"; } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Abilities/Spellbinding.cs b/CourseApp/RPGSaga/Abilities/Spellbinding.cs index a46c1a19..ab84587a 100644 --- a/CourseApp/RPGSaga/Abilities/Spellbinding.cs +++ b/CourseApp/RPGSaga/Abilities/Spellbinding.cs @@ -11,7 +11,6 @@ public Spellbinding() IsSkipRound = true; ActionDuration = 1; NumOfUses = 1; - Multiplier = 0; IsFire = false; } @@ -27,11 +26,9 @@ public Spellbinding() public bool IsFire { get; } - public double Multiplier { get; } - public override string ToString() { - return $"spellbinding"; + return $"{Name}"; } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Abilities/VengeanceStrike.cs b/CourseApp/RPGSaga/Abilities/VengeanceStrike.cs index 3d1891f0..dcf6730b 100644 --- a/CourseApp/RPGSaga/Abilities/VengeanceStrike.cs +++ b/CourseApp/RPGSaga/Abilities/VengeanceStrike.cs @@ -27,11 +27,17 @@ public VengeanceStrike(int damage) public bool IsFire { get; } - public double Multiplier { get; } + private double Multiplier { get; } + + public void SetDefaultValue() + { + ActionDuration = 1; + NumOfUses = 1; + } public override string ToString() { - return $"vengeance strike"; + return $"{Name}"; } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/GameBuilder/FightBuilder.cs b/CourseApp/RPGSaga/GameBuilder/FightBuilder.cs index 3cc546ab..53dacb3b 100644 --- a/CourseApp/RPGSaga/GameBuilder/FightBuilder.cs +++ b/CourseApp/RPGSaga/GameBuilder/FightBuilder.cs @@ -4,8 +4,8 @@ namespace CourseApp.RPGSaga.GameBuilder public class FightBuilder { - private Player _p1; - private Player _p2; + private readonly Player _p1; + private readonly Player _p2; private Player _winner; private Player _looser; @@ -15,7 +15,7 @@ public FightBuilder(Player p1, Player p2) _p2 = p2; } - public void SetTragets() + public void SetTargets() { _p1.SetTarget(_p2); _p2.SetTarget(_p1); @@ -23,7 +23,7 @@ public void SetTragets() public Player StartFight() { - Logger.WriteLog($"Fight: [{_p1.ToString()} {_p1.Hp} HP {_p1.Strength} Strength] against [{_p2.ToString()} {_p2.Hp} HP {_p2.Strength} Strength]"); + Logger.WriteLog($"Fight: [{_p1} {_p1.Hp} HP {_p1.Strength} Strength] against [{_p2} {_p2.Hp} HP {_p2.Strength} Strength]"); while (!_p1.IsDead && !_p2.IsDead) { _p1.MakeAMove(); @@ -41,8 +41,8 @@ public Player StartFight() _winner = _p1; } - Logger.WriteLog($"Winner of this match is {_winner.ToString()}"); - Logger.WriteLog($"Such a good victory against {_looser.ToString()}"); + Logger.WriteLog($"Winner of this match is {_winner}"); + Logger.WriteLog($"Such a good victory against {_looser}"); return _winner; } } diff --git a/CourseApp/RPGSaga/GameBuilder/GameBuilder.cs b/CourseApp/RPGSaga/GameBuilder/GameBuilder.cs index 6bea4f9e..ac3ab117 100644 --- a/CourseApp/RPGSaga/GameBuilder/GameBuilder.cs +++ b/CourseApp/RPGSaga/GameBuilder/GameBuilder.cs @@ -1,45 +1,76 @@ namespace CourseApp.RPGSaga.GameBuilder { + using System; using System.Collections.Generic; using CourseApp.RPGSaga.Generators; using CourseApp.RPGSaga.Heroes; public class GameBuilder { - private int _listSize = 4; private TournamentListGenerator _tournamentListGenerator; private List _tournamentList; - private List _winners; private FightBuilder _fight; + private int _size; - public GameBuilder() + public GameBuilder(int size) { - _tournamentListGenerator = new TournamentListGenerator(_listSize); + Size = size; + _tournamentListGenerator = new TournamentListGenerator(size); _tournamentList = new List(); - _winners = new List(); + } + + public int Size + { + get => _size; + + set + { + if (value >= 1) + { + _size = value; + } + } } public void StartTournament() { _tournamentList = _tournamentListGenerator.GenerateTournamentList(); - RunRound(_tournamentList); + for (int i = 0; i < Size - 1; i++) + { + RunRound(_tournamentList); + } + + foreach (var player in _tournamentList) + { + Console.WriteLine(player); + } } public List RunRound(List players) { - _winners.Clear(); - for (int i = 1; i < players.Count; i += 2) + var playerList = players; + _tournamentList.Clear(); + foreach (var player in playerList) + { + player.SetDefaultValues(); + } + + for (int i = 0; i < playerList.Count; i += 2) { - _fight = new FightBuilder(players[i - 1], players[i]); - _winners.Add(_fight.StartFight()); + _fight = new FightBuilder(playerList[i], playerList[i + 1]); + _fight.SetTargets(); + _tournamentList.Add(_fight.StartFight()); } - return RunRound(_winners); + return _tournamentList; } public void GetWinner() { - Logger.WriteLog($"Winner is {_winners[0].Name} {_winners[0].GetType()}"); + Logger.WriteLog("======================================="); + Logger.WriteLog("Winner List"); + Logger.WriteLog("======================================="); + Console.WriteLine(_tournamentList); } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Generators/PlayerFabric.cs b/CourseApp/RPGSaga/Generators/PlayerFabric.cs index 52d60aba..3b29780b 100644 --- a/CourseApp/RPGSaga/Generators/PlayerFabric.cs +++ b/CourseApp/RPGSaga/Generators/PlayerFabric.cs @@ -21,34 +21,19 @@ public override Player FactoryMethod() return CreatePlayer(); } - private string SetName() - { - return _name[Random.Shared.Next(0, _name.Count)]; - } - - private int SetHP() - { - return Random.Shared.Next(70, 100); - } - - private int SetStrength() - { - return Random.Shared.Next(10, 15); - } - private Player CreatePlayer() { Player hero = null; switch (_heroesTypes[Random.Shared.Next(0, _heroesTypes.Count)]) { case "Archer": - hero = new Archer(SetName(), SetHP(), SetStrength()); + hero = new Archer(_name[Random.Shared.Next(0, _name.Count)], 95, 14); break; case "Knight": - hero = new Knight(SetName(), SetHP(), SetStrength()); + hero = new Knight(_name[Random.Shared.Next(0, _name.Count)], 90, 15); break; case "Wizard": - hero = new Wizard(SetName(), SetHP(), SetStrength()); + hero = new Wizard(_name[Random.Shared.Next(0, _name.Count)], 100, 13); break; } diff --git a/CourseApp/RPGSaga/Generators/TournamentListGenerator.cs b/CourseApp/RPGSaga/Generators/TournamentListGenerator.cs index 8f941ec8..44c68301 100644 --- a/CourseApp/RPGSaga/Generators/TournamentListGenerator.cs +++ b/CourseApp/RPGSaga/Generators/TournamentListGenerator.cs @@ -2,6 +2,7 @@ namespace CourseApp.RPGSaga.Generators { using System; using System.Collections.Generic; + using System.ComponentModel; using CourseApp.RPGSaga.Heroes; using CourseApp.RPGSaga.Interfaces; @@ -18,29 +19,23 @@ public TournamentListGenerator(int listSize) _tournamentList = new List(); } + [DefaultValue(2)] public int ListSize { - get - { - return _listSize; - } + get => _listSize; set { - if (value >= 2 && value % 2 == 0) - { - _listSize = value; - } - else + if (value >= 1) { - Console.WriteLine("incorrect value"); + _listSize = (int)Math.Pow(2.0, value); } } } public List GenerateTournamentList() { - for (int i = 0; i < _listSize; i++) + for (int i = 0; i < ListSize; i++) { _tournamentList.Add(_playerFabric.FactoryMethod()); } diff --git a/CourseApp/RPGSaga/Heroes/Archer.cs b/CourseApp/RPGSaga/Heroes/Archer.cs index b2927dd3..43fb72c7 100644 --- a/CourseApp/RPGSaga/Heroes/Archer.cs +++ b/CourseApp/RPGSaga/Heroes/Archer.cs @@ -86,7 +86,7 @@ public override void SetDamage() { var randomIndex = Random.Shared.Next(0, _abilities.Count); _enemy.AddEffect(_abilities[randomIndex]); - Logger.WriteLog($"{ToString()} used {_abilities[randomIndex].Name} against {_enemy.ToString()}"); + Logger.WriteLog($"{ToString()} used {_abilities[randomIndex].Name} against {_enemy}"); _abilities[randomIndex].NumOfUses -= 1; if (_abilities[randomIndex].NumOfUses == 0) { @@ -95,9 +95,24 @@ public override void SetDamage() } } + public override void SetDefaultValues() + { + Hp = 95; + IsDead = false; + IsFire = false; + AddAbilities(); + } + public override string ToString() { return $"Archer: {Name}"; } + + protected override void AddAbilities() + { + _abilities.Clear(); + _abilities.Add(new Attack(Strength)); + _abilities.Add(new FireArrows()); + } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Heroes/Knight.cs b/CourseApp/RPGSaga/Heroes/Knight.cs index 6c9733e6..b7493675 100644 --- a/CourseApp/RPGSaga/Heroes/Knight.cs +++ b/CourseApp/RPGSaga/Heroes/Knight.cs @@ -2,7 +2,6 @@ { using System; using System.Collections.Generic; - using System.Linq; using CourseApp.RPGSaga.Abilities; using CourseApp.RPGSaga.GameBuilder; using CourseApp.RPGSaga.Interfaces; @@ -17,7 +16,7 @@ public class Knight : Player public Knight(string name, int hp, int strength) : base(name, hp, strength) { - _abilities = new List() { new Attack(Strength), new VengeanceStrike(Strength) }; + _abilities = new List(); _effects = new List(); } @@ -86,7 +85,7 @@ public override void SetDamage() { var randomIndex = Random.Shared.Next(0, _abilities.Count); _enemy.AddEffect(_abilities[randomIndex]); - Logger.WriteLog($"{ToString()} used {_abilities[randomIndex].Name} against {_enemy.ToString()}"); + Logger.WriteLog($"{ToString()} used {_abilities[randomIndex].Name} against {_enemy}"); _abilities[randomIndex].NumOfUses -= 1; if (_abilities[randomIndex].NumOfUses == 0) { @@ -95,9 +94,24 @@ public override void SetDamage() } } + public override void SetDefaultValues() + { + Hp = 90; + IsDead = false; + IsFire = false; + AddAbilities(); + } + public override string ToString() { return $"Knight: {Name}"; } + + protected override void AddAbilities() + { + _abilities.Clear(); + _abilities.Add(new Attack(Strength)); + _abilities.Add(new VengeanceStrike(Strength)); + } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Heroes/Player.cs b/CourseApp/RPGSaga/Heroes/Player.cs index 5ac70b52..7e96fea8 100644 --- a/CourseApp/RPGSaga/Heroes/Player.cs +++ b/CourseApp/RPGSaga/Heroes/Player.cs @@ -13,6 +13,7 @@ public Player(string name, int hp, int strength) Hp = hp; Strength = strength; IsDead = false; + IsFire = false; } public string Name { get; set; } @@ -21,22 +22,9 @@ public Player(string name, int hp, int strength) public int Strength { - get - { - return _strength; - } - - set - { - if (value > 0) - { - _strength = value; - } - else - { - _strength = 10; - } - } + get => _strength; + + set => _strength = value > 0 ? value : 50; } public bool IsFire { get; set; } @@ -50,5 +38,9 @@ public int Strength public abstract void SetTarget(IPlayer enemy); public abstract void SetDamage(); + + public abstract void SetDefaultValues(); + + protected abstract void AddAbilities(); } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Heroes/Wizard.cs b/CourseApp/RPGSaga/Heroes/Wizard.cs index 35dac339..99aa232f 100644 --- a/CourseApp/RPGSaga/Heroes/Wizard.cs +++ b/CourseApp/RPGSaga/Heroes/Wizard.cs @@ -86,7 +86,7 @@ public override void SetDamage() { var randomIndex = Random.Shared.Next(0, _abilities.Count); _enemy.AddEffect(_abilities[randomIndex]); - Logger.WriteLog($"{ToString()} used {_abilities[randomIndex].Name} against {_enemy.ToString()}"); + Logger.WriteLog($"{ToString()} used {_abilities[randomIndex].Name} against {_enemy}"); _abilities[randomIndex].NumOfUses -= 1; if (_abilities[randomIndex].NumOfUses == 0) { @@ -95,9 +95,24 @@ public override void SetDamage() } } + public override void SetDefaultValues() + { + Hp = 100; + IsDead = false; + IsFire = false; + AddAbilities(); + } + public override string ToString() { return $"Wizard: {Name}"; } + + protected override void AddAbilities() + { + _abilities.Clear(); + _abilities.Add(new Attack(Strength)); + _abilities.Add(new Spellbinding()); + } } } \ No newline at end of file From 575f5f0c0508ea420a9cca2b8a9711f96b3e008b Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 14 Feb 2022 09:26:38 +0300 Subject: [PATCH 11/11] code review --- CourseApp/Program.cs | 11 ++++++++--- CourseApp/RPGSaga/Generators/PlayerFabric.cs | 10 +++++++--- CourseApp/RPGSaga/Heroes/Archer.cs | 10 +++++----- CourseApp/RPGSaga/Heroes/Knight.cs | 4 ++-- CourseApp/RPGSaga/Heroes/Wizard.cs | 2 +- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index a94350eb..96a92ec2 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,14 +1,19 @@ namespace CourseApp { + using System; using CourseApp.RPGSaga.GameBuilder; + using CourseApp.RPGSaga.Generators; public class Program { public static void Main(string[] args) { - var gameBuilder = new GameBuilder(4); - gameBuilder.StartTournament(); - gameBuilder.GetWinner(); + var playerFactory = new PlayerFabric(); + var playerOne = playerFactory.FactoryMethod(); + var playerTwo = playerFactory.FactoryMethod(); + var fight = new FightBuilder(playerOne, playerTwo); + fight.SetTargets(); + Console.WriteLine(fight.StartFight()); } } } diff --git a/CourseApp/RPGSaga/Generators/PlayerFabric.cs b/CourseApp/RPGSaga/Generators/PlayerFabric.cs index 3b29780b..ab436654 100644 --- a/CourseApp/RPGSaga/Generators/PlayerFabric.cs +++ b/CourseApp/RPGSaga/Generators/PlayerFabric.cs @@ -23,17 +23,21 @@ public override Player FactoryMethod() private Player CreatePlayer() { + // Сделать через emum Player hero = null; + var name = _name[Random.Shared.Next(0, _name.Count)]; + var healthpoints = Random.Shared.Next(80, 100); + var strength = Random.Shared.Next(20, 30); switch (_heroesTypes[Random.Shared.Next(0, _heroesTypes.Count)]) { case "Archer": - hero = new Archer(_name[Random.Shared.Next(0, _name.Count)], 95, 14); + hero = new Archer(name, healthpoints, strength); break; case "Knight": - hero = new Knight(_name[Random.Shared.Next(0, _name.Count)], 90, 15); + hero = new Knight(name, healthpoints, strength); break; case "Wizard": - hero = new Wizard(_name[Random.Shared.Next(0, _name.Count)], 100, 13); + hero = new Wizard(name, healthpoints, strength); break; } diff --git a/CourseApp/RPGSaga/Heroes/Archer.cs b/CourseApp/RPGSaga/Heroes/Archer.cs index 43fb72c7..048bc11b 100644 --- a/CourseApp/RPGSaga/Heroes/Archer.cs +++ b/CourseApp/RPGSaga/Heroes/Archer.cs @@ -39,11 +39,6 @@ public override void MakeAMove() Logger.WriteLog($"{ToString()} is burning"); } - if (IsFire) - { - Hp -= 2; - } - Hp -= effect.Damage; if (Hp <= 0) { @@ -66,6 +61,11 @@ public override void MakeAMove() Logger.WriteLog($"{ToString()} has {Hp} HP"); Logger.WriteLog("-------------------------------------------------------"); + if (IsFire) + { + Hp -= 2; + } + if (!_isSkip) { SetDamage(); diff --git a/CourseApp/RPGSaga/Heroes/Knight.cs b/CourseApp/RPGSaga/Heroes/Knight.cs index b7493675..3be64d61 100644 --- a/CourseApp/RPGSaga/Heroes/Knight.cs +++ b/CourseApp/RPGSaga/Heroes/Knight.cs @@ -16,7 +16,7 @@ public class Knight : Player public Knight(string name, int hp, int strength) : base(name, hp, strength) { - _abilities = new List(); + _abilities = new List() { new Attack(Strength), new VengeanceStrike(Strength) }; _effects = new List(); } @@ -56,7 +56,7 @@ public override void MakeAMove() _effects.Remove(effect); } - if (_effects.Count <= 1) + if (effects.Count <= 1) { break; } diff --git a/CourseApp/RPGSaga/Heroes/Wizard.cs b/CourseApp/RPGSaga/Heroes/Wizard.cs index 99aa232f..7cb3bd35 100644 --- a/CourseApp/RPGSaga/Heroes/Wizard.cs +++ b/CourseApp/RPGSaga/Heroes/Wizard.cs @@ -57,7 +57,7 @@ public override void MakeAMove() _effects.Remove(effect); } - if (_effects.Count <= 1) + if (effects.Count <= 1) { break; }