diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml
new file mode 100644
index 0000000..7ab008e
--- /dev/null
+++ b/.github/workflows/dotnetcore.yml
@@ -0,0 +1,31 @@
+name: .NET Core
+
+on: [push, pull_request]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v1
+ - name: Setup .NET Core
+ uses: actions/setup-dotnet@v1
+ with:
+ dotnet-version: 2.1.802
+ - name: Build with dotnet
+ run: |
+ cd CourseApp
+ dotnet build --configuration Release
+ - name: Run tests
+ run: |
+ cd CourseApp.Tests
+ dotnet test
+ - name: Build with dotnet
+ run: |
+ cd RPG
+ dotnet build --configuration Release
+ - name: Run tests
+ run: |
+ cd RPG.Tests
+ dotnet test
diff --git a/.gitignore b/.gitignore
index 35d4ccd..7e79084 100644
--- a/.gitignore
+++ b/.gitignore
@@ -198,7 +198,10 @@ $RECYCLE.BIN/
**/node_modules/*
# Added by Jskonst
+<<<<<<< HEAD
+=======
.vscode/
+>>>>>>> 1a30883c302a9f8e4ef3c380d6a061f88385a877
Properties/
#####
diff --git a/CourseApp.Tests/AgeTest.cs b/CourseApp.Tests/AgeTest.cs
new file mode 100644
index 0000000..fa27adf
--- /dev/null
+++ b/CourseApp.Tests/AgeTest.cs
@@ -0,0 +1,20 @@
+using System;
+using Xunit;
+
+namespace CourseApp.Tests
+{
+ public class AgeTest
+ {
+ [Fact]
+ public void TodayBirthdayTest()
+ {
+ try
+ {
+ Assert.Equal(0, DateTime.Compare(DateTime.Now, AgeClass.CompareTheDate(DateTime.Now, DateTime.Now)));
+ }
+ catch (Exception)
+ {
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj
index 668406b..9dbf076 100644
--- a/CourseApp.Tests/CourseApp.Tests.csproj
+++ b/CourseApp.Tests/CourseApp.Tests.csproj
@@ -1,30 +1,31 @@
-
-
-
- netcoreapp2.1
- True
- 1573,1591,1701;1702;1705
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ../_stylecop/stylecop.ruleset
- true
-
-
-
-
-
-
-
+
+
+
+
+ netcoreapp2.1
+ True
+ 1573,1591,1701;1702;1705
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ../_stylecop/stylecop.ruleset
+ true
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs
index f4e845b..3799045 100644
--- a/CourseApp.Tests/DemoTest.cs
+++ b/CourseApp.Tests/DemoTest.cs
@@ -1,44 +1,45 @@
-using System;
-using System.Collections.Generic;
-using Xunit;
-
-namespace CourseApp.Tests
-{
- public class DemoTest
- {
- [Theory]
- [InlineData(0.7, 5, 0.2196741002474553)]
- [InlineData(2.2, 1.7, 0.4091366343551351)]
- [InlineData(0.1, 4, 0.4617896586816621)]
- public void TestFunction(double b, double x, double exp)
- {
- Assert.Equal(Program.Func(b, x), exp, 3);
- }
- [Fact]
- public void ZeroFunction()
- {
- var res = Program.Func(0.0, 0.0);
- Xunit.Assert.Equal(double.PositiveInfinity, res);
- }
-
- [Fact]
- public void NullMassTest()
- {
- List mass = new List();
- var res = Program.TaskB(2, mass);
- Xunit.Assert.Equal(mass, res);
- }
-
- [Fact]
- public void TestTaskB()
- {
- List x = new List { 1.1, 2.4, 3.6, 1.7, 3.9 };
- var resultB = Program.TaskB(2.5, x);
- var exp = new List { 0.739333760444302, 0.599437811110944, 0.321394270206876, 0.725284786782826, 0.282846892996087 };
- for (int i = 0; i < resultB.Count; i++)
- {
- Xunit.Assert.Equal(exp[i], resultB[i], 3);
- }
- }
- }
+using System;
+using System.Collections.Generic;
+using Xunit;
+
+namespace CourseApp.Tests
+{
+ public class DemoTest
+ {
+ [Theory]
+ [InlineData(0.7, 5, 0.2196741002474553)]
+ [InlineData(2.2, 1.7, 0.4091366343551351)]
+ [InlineData(0.1, 4, 0.4617896586816621)]
+ public void TestFunction(double b, double x, double exp)
+ {
+ Assert.Equal(Program.Func(b, x), exp, 3);
+ }
+
+ [Fact]
+ public void ZeroFunction()
+ {
+ var res = Program.Func(0.0, 0.0);
+ Assert.Equal(double.PositiveInfinity, res);
+ }
+
+ [Fact]
+ public void NullMassTest()
+ {
+ List mass = new List();
+ var res = Program.TaskB(2, mass);
+ Assert.Equal(mass, res);
+ }
+
+ [Fact]
+ public void TestTaskB()
+ {
+ List x = new List { 1.1, 2.4, 3.6, 1.7, 3.9 };
+ var resultB = Program.TaskB(2.5, x);
+ var exp = new List { 0.739333760444302, 0.599437811110944, 0.321394270206876, 0.725284786782826, 0.282846892996087 };
+ for (int i = 0; i < resultB.Count; i++)
+ {
+ Assert.Equal(exp[i], resultB[i], 3);
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/CourseApp.Tests/DogTest.cs b/CourseApp.Tests/DogTest.cs
new file mode 100644
index 0000000..94d7943
--- /dev/null
+++ b/CourseApp.Tests/DogTest.cs
@@ -0,0 +1,71 @@
+using System;
+using Xunit;
+
+namespace CourseApp.Tests
+{
+ public class DogTest
+ {
+ [Fact]
+ public void TestEmptyConstructor()
+ {
+ var item = new Dog();
+ Assert.Equal(0, item.Age);
+ Assert.Equal("Test", item.Name);
+ Assert.Equal("male", item.Gender);
+ }
+
+ [Fact]
+ public void TestSetAge()
+ {
+ var item = new Dog();
+ item.Age = 5;
+ Assert.Equal(5, item.Age);
+ }
+
+ [Fact]
+ public void TestIncorrectSetAge()
+ {
+ var item = new Dog();
+ try
+ {
+ item.Age = -5;
+ }
+ catch (System.Exception)
+ {
+ Console.WriteLine("rewrite age.");
+ Assert.True(true);
+ }
+ }
+
+ [Fact]
+ public void TestIncorrectSetGender()
+ {
+ var item = new Dog();
+ try
+ {
+ item.Gender = "lemonade";
+ }
+ catch (System.Exception)
+ {
+ Console.WriteLine("rewrite gender");
+ Assert.True(true);
+ }
+ }
+
+ [Fact]
+ public void TestName()
+ {
+ var item = new Dog("Eevee");
+ Assert.Equal("Eevee", item.Name);
+ }
+
+ [Fact]
+ public void TestFullConstructor()
+ {
+ var item = new Dog("Mew", 5, "male");
+ Assert.Equal(5, item.Age);
+ Assert.Equal("Mew", item.Name);
+ Assert.Equal("male", item.Gender);
+ }
+ }
+}
\ No newline at end of file
diff --git a/CourseApp.Tests/PigTest.cs b/CourseApp.Tests/PigTest.cs
index 09e2cce..1eb8479 100644
--- a/CourseApp.Tests/PigTest.cs
+++ b/CourseApp.Tests/PigTest.cs
@@ -9,16 +9,17 @@ public class PigTest
public void TestEmptyConstructor()
{
var item = new Pig();
- Assert.Equal(1, item.Age);
+ Assert.Equal(0, item.Age);
Assert.Equal("Test", item.Name);
- Assert.Equal(1, item.Salo);
+ Assert.Equal(0, item.Salo);
Assert.Equal("male", item.Gender);
}
[Theory]
- [InlineData("PigMan", 5, 7,"male")]
- [InlineData("PigGirl", 2, 1,"female")]
- [InlineData("PigPigger", 10, 11,"male")]
+ [InlineData("PigMan", 5, 7, "male")]
+ [InlineData("PigGirl", 2, 1, "female")]
+ [InlineData("PigPigger", 10, 11, "male")]
+
public void TestFullConstructor(string name, int age, int salo, string gender)
{
var item = new Pig(name, age, salo, gender);
@@ -48,7 +49,7 @@ public void TestWrongSetAge()
{
Console.WriteLine("Возраст должен быть больше 1 года");
Assert.True(true);
- }
+ }
}
}
}
\ No newline at end of file
diff --git a/CourseApp/.vscode/launch.json b/CourseApp/.vscode/launch.json
new file mode 100644
index 0000000..208ea3a
--- /dev/null
+++ b/CourseApp/.vscode/launch.json
@@ -0,0 +1,25 @@
+{
+ // Use IntelliSense to learn about possible attributes.
+ // Hover to view descriptions of existing attributes.
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": ".NET Core Launch (console)",
+ "type": "coreclr",
+ "request": "launch",
+ "preLaunchTask": "build",
+ "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/CourseApp.dll",
+ "args": [],
+ "cwd": "${workspaceFolder}",
+ "console": "internalConsole",
+ "stopAtEntry": false
+ },
+ {
+ "name": ".NET Core Attach",
+ "type": "coreclr",
+ "request": "attach",
+ "processId": "${command:pickProcess}"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/CourseApp/.vscode/tasks.json b/CourseApp/.vscode/tasks.json
new file mode 100644
index 0000000..f8c71cd
--- /dev/null
+++ b/CourseApp/.vscode/tasks.json
@@ -0,0 +1,42 @@
+{
+ "version": "2.0.0",
+ "tasks": [
+ {
+ "label": "build",
+ "command": "dotnet",
+ "type": "process",
+ "args": [
+ "build",
+ "${workspaceFolder}/CourseApp.csproj",
+ "/property:GenerateFullPaths=true",
+ "/consoleloggerparameters:NoSummary"
+ ],
+ "problemMatcher": "$msCompile"
+ },
+ {
+ "label": "publish",
+ "command": "dotnet",
+ "type": "process",
+ "args": [
+ "publish",
+ "${workspaceFolder}/CourseApp.csproj",
+ "/property:GenerateFullPaths=true",
+ "/consoleloggerparameters:NoSummary"
+ ],
+ "problemMatcher": "$msCompile"
+ },
+ {
+ "label": "watch",
+ "command": "dotnet",
+ "type": "process",
+ "args": [
+ "watch",
+ "run",
+ "${workspaceFolder}/CourseApp.csproj",
+ "/property:GenerateFullPaths=true",
+ "/consoleloggerparameters:NoSummary"
+ ],
+ "problemMatcher": "$msCompile"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/CourseApp/AgeClass.cs b/CourseApp/AgeClass.cs
new file mode 100644
index 0000000..3c61a37
--- /dev/null
+++ b/CourseApp/AgeClass.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+
+namespace CourseApp
+{
+ public class AgeClass
+ {
+ public static DateTime CompareTheDate(DateTime d1, DateTime d2)
+ {
+ if (d1.Ticks < d2.Ticks)
+ {
+ DateTime result = new DateTime(d2.Ticks - d1.Ticks);
+ return result;
+ }
+
+ throw new Exception();
+ }
+
+ public static string AgeConsole()
+ {
+ Console.WriteLine("Введите год своего рождения:");
+ int years = Convert.ToInt32(Console.ReadLine());
+ Console.WriteLine("Введите месяц своего рождения:");
+ int months = Convert.ToInt32(Console.ReadLine());
+ Console.WriteLine("Введите день своего рождения:");
+ int days = Convert.ToInt32(Console.ReadLine());
+ DateTime result = CompareTheDate(new DateTime(years, months, days), DateTime.Now);
+ return $"Вам {result.Year - 1} лет, {result.Month - 1} месяцев и {result.Day - 1} дней";
+ }
+
+ public static string Age(int years, int months, int days)
+ {
+ DateTime result = CompareTheDate(new DateTime(years, months, days), DateTime.Now);
+ return $"Вам {result.Year - 1} лет, {result.Month - 1} месяцев и {result.Day - 1} дней";
+ }
+
+ public static string Age(DateTime date)
+ {
+ return $"Вам {CompareTheDate(date, DateTime.Now).Year - 1} лет, {CompareTheDate(date, DateTime.Now).Month - 1} месяцев и {CompareTheDate(date, DateTime.Now).Day - 1} дней";
+ }
+ }
+}
diff --git a/CourseApp/Animal.cs b/CourseApp/Animal.cs
new file mode 100644
index 0000000..9c57212
--- /dev/null
+++ b/CourseApp/Animal.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+
+namespace CourseApp
+{
+ public abstract class Animal
+ {
+ private int age;
+
+ private string gender;
+
+ public Animal()
+ : this("Test")
+ {
+ }
+
+ public Animal(string name)
+ : this(name, 0, "male")
+ {
+ }
+
+ public Animal(string name, int age, string gender)
+ {
+ Name = name;
+ Age = age;
+ Gender = gender;
+ }
+
+ public string Name { get; set; }
+
+ public int Age
+ {
+ get
+ {
+ return this.age;
+ }
+
+ set
+ {
+ if (value >= 0 && value < 20)
+ {
+ this.age = value;
+ }
+ else
+ {
+ throw new System.Exception();
+ }
+ }
+ }
+
+ public string Gender
+ {
+ get
+ {
+ return this.gender;
+ }
+
+ set
+ {
+ if (value == "male" || value == "female")
+ {
+ this.gender = value;
+ }
+ else
+ {
+ throw new System.Exception();
+ }
+ }
+ }
+
+ public override string ToString()
+ {
+ return $"Имя:{Name},Возраст:{Age},Пол:{Gender}";
+ }
+
+ public void AgeUp()
+ {
+ this.age++;
+ }
+
+ public abstract void Voice();
+ }
+}
\ No newline at end of file
diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj
index b244e47..00c8d55 100644
--- a/CourseApp/CourseApp.csproj
+++ b/CourseApp/CourseApp.csproj
@@ -12,7 +12,7 @@
- ../_stylecop/stylecop.ruleset
+ ../_stylecop/stylecop.ruleset
true
diff --git a/CourseApp/CourseApp.sln b/CourseApp/CourseApp.sln
new file mode 100644
index 0000000..3dac3f4
--- /dev/null
+++ b/CourseApp/CourseApp.sln
@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.28307.852
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CourseApp", "CourseApp.csproj", "{17CB0273-34D3-4D23-965F-FC4AD0A83D0F}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CourseApp.Tests", "..\CourseApp.Tests\CourseApp.Tests.csproj", "{E0133767-62A2-4B4A-87A2-BD09BC775E0A}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {17CB0273-34D3-4D23-965F-FC4AD0A83D0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {17CB0273-34D3-4D23-965F-FC4AD0A83D0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {17CB0273-34D3-4D23-965F-FC4AD0A83D0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {17CB0273-34D3-4D23-965F-FC4AD0A83D0F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E0133767-62A2-4B4A-87A2-BD09BC775E0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E0133767-62A2-4B4A-87A2-BD09BC775E0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E0133767-62A2-4B4A-87A2-BD09BC775E0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E0133767-62A2-4B4A-87A2-BD09BC775E0A}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {1849B280-B447-4D18-9764-F412B7768C4F}
+ EndGlobalSection
+EndGlobal
diff --git a/CourseApp/Dog.cs b/CourseApp/Dog.cs
new file mode 100644
index 0000000..3cdfd8b
--- /dev/null
+++ b/CourseApp/Dog.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+
+namespace CourseApp
+{
+ public class Dog : Animal
+ {
+ public Dog()
+ : this("Test")
+ {
+ }
+
+ public Dog(string name)
+ : this(name, 0, "male")
+ {
+ }
+
+ public Dog(string name, int age, string gender)
+ {
+ Name = name;
+ Age = age;
+ Gender = gender;
+ }
+
+ public Dog(string name, string breed)
+ : base(name)
+ {
+ Breed = breed;
+ }
+
+ public string Breed { get; set; }
+
+ public override void Voice()
+ {
+ Console.WriteLine("гав :D");
+ }
+
+ public override string ToString()
+ {
+ return $"Имя:{Name},Возраст:{Age},Пол:{Gender},Порода:{Breed}";
+ }
+ }
+}
\ No newline at end of file
diff --git a/CourseApp/Pig.cs b/CourseApp/Pig.cs
index 73dc4f1..dd46d18 100644
--- a/CourseApp/Pig.cs
+++ b/CourseApp/Pig.cs
@@ -1,29 +1,28 @@
using System;
using System.Collections.Generic;
+using System.Text;
namespace CourseApp
{
- public class Pig
+ public class Pig : Animal
{
private int salo;
- private int age;
- private string gender;
- public string Name { get; set; }
+
public Pig()
- : this("Test")
+ : base("Test")
{
}
public Pig(string name)
- : this(name, 1,"male")
+ : base(name, 0, "male")
{
}
- public Pig(string name, int age, string gender)
- : this(name, age, 1, "male")
+ public Pig(string name, int age)
+ : this(name, age, 0, "male")
{
}
-
+
public Pig(string name, int age, int salo, string gender)
{
Name = name;
@@ -32,42 +31,6 @@ public Pig(string name, int age, int salo, string gender)
Gender = gender;
}
- public int Age
- {
- get
- {
- return this.age;
- }
- set
- {
- if (value >= 1 && value <= 15)
- {
- this.age = value;
- }
- else
- {
- Console.WriteLine("Возраст свиньи должен быть менее 15.");
- }
- }
- }
- public string Gender
- {
- get
- {
- return this.gender;
- }
- set
- {
- if (value == "male" || value == "female")
- {
- this.gender = value;
- }
- else
- {
- throw new System.Exception();
- }
- }
- }
public int Salo
{
get
@@ -77,7 +40,7 @@ public int Salo
set
{
- if (value >= 0)
+ if (value >= 1)
{
this.salo = value;
}
@@ -88,23 +51,16 @@ public int Salo
}
}
- public override string ToString()
+ public override void Voice()
{
- return $"Имя:{Name},Возраст:{Age},Cало:{Salo}";
- return @" _
- (_)
- _ __ _ __ _
-| '_ \| |/ _` |
-| |_) | | (_| |
-| .__/|_|\__, |
-| | __/ |
-|_| |___/
-";
+ Console.WriteLine("Хрю-хрю :)");
}
- public void Aging()
+
+ public override string ToString()
{
- this.age++;
+ return $"Имя:{Name},Возраст:{Age},Cало:{Salo}";
}
+
public void LostSalo()
{
this.salo--;
diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs
index 3fe39da..a1bdc07 100644
--- a/CourseApp/Program.cs
+++ b/CourseApp/Program.cs
@@ -1,53 +1,63 @@
-using System;
+using System;
using System.Collections.Generic;
-
+
namespace CourseApp
{
public class Program
{
public static double Func(double b, double x)
{
- var y = (1 + Math.Pow(Math.Sin(Math.Pow(b, 3) + Math.Pow(x, 3)), 2)) / Math.Pow(Math.Pow(b, 3) + Math.Pow(x, 3), 1/3f);
+ var y = (1 + Math.Pow(Math.Sin(Math.Pow(b, 3) + Math.Pow(x, 3)), 2)) / Math.Pow(Math.Pow(b, 3) + Math.Pow(x, 3), 1 / 3f);
+
return y;
}
+
public static List TaskA(double b, double xn, double xk, double dx)
{
- int i = 0;
- List y = new List();
- for (double x = xn; x < xk; x += dx)
- {
- y.Add(Func(b, x));
- i++;
- }
- return y;
+ int i = 0;
+ List y = new List();
+
+ for (double x = xn; x < xk; x += dx)
+ {
+ y.Add(Func(b, x));
+ i++;
+ }
+
+ return y;
}
+
public static List TaskB(double b, List x)
{
- List y = new List();
+ List y = new List();
for (var i = 0; i < x.Count; i++)
{
y.Add(Func(b, x[i]));
}
+
return y;
}
+
public static void Main(string[] args)
{
- double xn = 1.280;
- double xk = 3.280;
- double dx = 0.4;
- double b = 2.5;
- Console.WriteLine("Answer Task A :");
- foreach (var item in TaskA(b, xn, xk, dx))
- {
- Console.WriteLine($"y = {item}");
- }
- List x = new List { 1.1, 2.4, 3.6, 1.7, 3.9 };
+ double xn = 1.280;
+ double xk = 3.280;
+ double dx = 0.4;
+ double b = 2.5;
+ Console.WriteLine("Answer Task A :");
+ foreach (var item in TaskA(b, xn, xk, dx))
+ {
+ Console.WriteLine($"y = {item}");
+ }
+
+ List x = new List { 1.1, 2.4, 3.6, 1.7, 3.9 };
var resultTaskB = TaskB(b, x);
Console.WriteLine($"Answer Task B:");
foreach (var item in resultTaskB)
{
Console.WriteLine($"y= {item}");
}
+
+ Console.WriteLine(AgeClass.AgeConsole());
}
}
}
diff --git a/RPG.Tests/RPG.Tests.csproj b/RPG.Tests/RPG.Tests.csproj
new file mode 100644
index 0000000..98af73f
--- /dev/null
+++ b/RPG.Tests/RPG.Tests.csproj
@@ -0,0 +1,31 @@
+
+
+
+ netcoreapp2.0
+
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ../_stylecop/stylecop.ruleset
+ true
+
+
+
+
+
\ No newline at end of file
diff --git a/RPG.Tests/TestingFights.cs b/RPG.Tests/TestingFights.cs
new file mode 100644
index 0000000..04f0c32
--- /dev/null
+++ b/RPG.Tests/TestingFights.cs
@@ -0,0 +1,120 @@
+using System;
+using Xunit;
+using RPG;
+
+namespace RPG.Tests
+{
+ public class TestingFights
+ {
+ [Fact]
+ public void CreationTest()
+ {
+ Hero knight = new Knight();
+ Hero archer = new Archer();
+ Hero wizard = new Wizard();
+ Hero necromancer = new Necromancer();
+
+ if (knight.Health > 0 && knight.Strength > 0 && archer.Health > 0 && archer.Strength > 0 && wizard.Health > 0 && wizard.Strength > 0 && necromancer.Health > 0 && necromancer.Strength > 0)
+ {
+ Assert.True(true);
+ }
+ }
+
+ [Fact]
+ public void KnightSkillsTest()
+ {
+ Hero knight = new Knight();
+
+ int damage;
+ string skillName;
+
+ knight.Skill(out skillName, out damage);
+
+ if ((skillName == "Удар возмездия" || skillName == "Удар с размаху" || skillName == "Раскол земли") && damage > 0)
+ {
+ Assert.True(true);
+ }
+ }
+
+ [Fact]
+ public void NecromancerSkillsTest()
+ {
+ Hero necromancer = new Necromancer();
+
+ int damage;
+ string skillName;
+
+ necromancer.Skill(out skillName, out damage);
+
+ if ((skillName == "Мрачная жатва" || skillName == "Трупное копье" || skillName == "Вампиризм") && damage > 0)
+ {
+ Assert.True(true);
+ }
+ }
+
+ [Fact]
+ public void ArcherSkillsTest()
+ {
+ Hero archer = new Archer();
+
+ int damage;
+ string skillName;
+
+ archer.Skill(out skillName, out damage);
+
+ if (skillName == "Самонаводящаяся стрела" && archer.buf && damage == 0)
+ {
+ Assert.True(true);
+ }
+ else if ((skillName == "Скоростная стрельба" || skillName == "Стрела стихий") && damage > 0)
+ {
+ Assert.True(true);
+ }
+ }
+
+ [Fact]
+ public void WizardSkillsTest()
+ {
+ Hero wizard = new Wizard();
+
+ int damage;
+ string skillName;
+
+ wizard.Skill(out skillName, out damage);
+
+ if (skillName == "Объятия смерти" && wizard.sleepTime > 0 && damage == 1)
+ {
+ Assert.True(true);
+ }
+ else if (skillName == "Жатва душ" && damage > 0)
+ {
+ Assert.True(true);
+ }
+ }
+
+ [Fact]
+ public void GetDamageTest()
+ {
+ Hero wizard = new Wizard();
+
+ int health = wizard.GetDamage(30);
+
+ Assert.Equal(wizard.maxHealth - 30, health);
+ }
+
+ [Fact]
+ public void AtackTest()
+ {
+ Hero archer = new Archer();
+
+ int damage;
+
+ archer.Atack(out damage);
+
+ if (damage > 0)
+ {
+ Assert.True(true);
+ }
+ }
+ }
+}
diff --git a/RPG/Archer.cs b/RPG/Archer.cs
new file mode 100644
index 0000000..3a40a9c
--- /dev/null
+++ b/RPG/Archer.cs
@@ -0,0 +1,65 @@
+using System;
+
+namespace RPG
+{
+ public class Archer : Hero
+ {
+ Random random = new Random();
+
+ public Archer()
+ : base()
+ {
+ typeClass = "Лучник";
+ skills = new string[]{"Самонаводящаяся стрела", "Скоростная стрельба", "Стрела стихий"};
+ }
+
+ public override void Skill(out string skillName, out int damage)
+ {
+ int probability = random.Next(0, 100);
+ if(!buf)
+ {
+ if(probability <= 15)
+ {
+ skillName = "Стрела стихий";
+ }
+ else if(probability <= 70)
+ {
+ skillName = "Самонаводящаяся стрела";
+ }
+ else
+ {
+ skillName = "Скоростная стрельба";
+ }
+ }
+ else
+ {
+ if(probability <= 50)
+ {
+ skillName = "Стрела стихий";
+ }
+ else
+ {
+ skillName = "Скоростная стрельба";
+ }
+ }
+
+ switch(skillName)
+ {
+ case "Стрела стихий":
+ damage = (int)(Strength * 1.8);
+ break;
+ case "Скоростная стрельба":
+ damage = (int)(Strength * 2.5);
+ break;
+ case "Самонаводящаяся стрела":
+ bufName = "Самонаводящаяся стрела";
+ buf = true;
+ damage = 0;
+ break;
+ default:
+ damage = 0;
+ break;
+ }
+ }
+ }
+}
diff --git a/RPG/Game.cs b/RPG/Game.cs
new file mode 100644
index 0000000..0658f27
--- /dev/null
+++ b/RPG/Game.cs
@@ -0,0 +1,167 @@
+using System;
+using System.Collections.Generic;
+
+namespace RPG
+{
+ public class Game
+ {
+ public List heroes = new List();
+ Logger logger = new Logger();
+ Random random = new Random();
+ Hero hero1;
+ Hero hero2;
+ int counter = 0;
+
+ public void Start(int numOfHeroes)
+ {
+ CreateHeroes(numOfHeroes);
+ while(heroes.Count > 1)
+ {
+ Fight();
+ }
+ Console.WriteLine($"\n=========\nПобедитель в игре - {heroes[0].typeClass} {heroes[0].Name}\n=========");
+ }
+ public void CreateHeroes(int numOfHeroes)
+ {
+ while(numOfHeroes > 0)
+ {
+ switch(random.Next(0,4))
+ {
+ case 0:
+ heroes.Add(new Archer());
+ break;
+ case 1:
+ heroes.Add(new Knight());
+ break;
+ case 2:
+ heroes.Add(new Wizard());
+ break;
+ case 3:
+ heroes.Add(new Necromancer());
+ break;
+ default:
+ heroes.Add(new Wizard());
+ break;
+ }
+ numOfHeroes--;
+ }
+ }
+ public void Atack(Hero hero1, Hero hero2)
+ {
+ int damage;
+
+ if(hero1.buf)
+ {
+ hero1.Atack(out damage);
+ logger.Atack(hero1, hero2, damage);
+ hero2.GetDamage(damage + 10);
+ }
+ else
+ {
+ hero1.Atack(out damage);
+ logger.Atack(hero1, hero2, damage);
+ hero2.GetDamage(damage);
+ }
+ }
+ public void UseSkill(Hero hero1, Hero hero2)
+ {
+ int damage;
+ string skillName;
+
+ if(hero1.buf)
+ {
+ hero1.Skill(out skillName, out damage);
+ logger.Skill(hero1, hero2, skillName, damage);
+ hero2.GetDamage(damage + 10);
+ }
+ else
+ {
+ hero1.Skill(out skillName, out damage);
+ logger.Skill(hero1, hero2, skillName, damage);
+ hero2.GetDamage(damage);
+ }
+ }
+
+ public void Fight()
+ {
+ int i = random.Next(0, heroes.Count - 1);
+ hero1 = heroes[i];
+ heroes.RemoveAt(i);
+
+ i = random.Next(0, heroes.Count);
+ hero2 = heroes[i];
+ heroes.RemoveAt(i);
+
+ int turn = random.Next(0, 1);
+ counter++;
+ Console.WriteLine("=========");
+ Console.WriteLine($"Бой №{counter}");
+
+ while (true)
+ {
+ if(turn == 0)
+ {
+ if(hero2.sleepTime == 0)
+ {
+ if(random.Next(0,10) > 6)
+ {
+ UseSkill(hero1, hero2);
+ }
+ else
+ {
+ Atack(hero1, hero2);
+ }
+ }
+ else
+ {
+ logger.Sleep(hero1);
+ hero2.sleepTime--;
+ }
+
+ if(hero2.Health <= 0)
+ {
+ hero1.sleepTime = 0;
+ hero1.buf = false;
+ heroes.Add(hero1);
+ logger.Winner(hero1);
+ logger.Death(hero2);
+ break;
+ }
+
+ turn = 1;
+ }
+ else
+ {
+ if(hero1.sleepTime == 0)
+ {
+ if(random.Next(0,10) > 6)
+ {
+ UseSkill(hero2, hero1);
+ }
+ else
+ {
+ Atack(hero2, hero1);
+ }
+ }
+
+ else
+ {
+ logger.Sleep(hero2);
+ hero1.sleepTime--;
+ }
+
+ if(hero1.Health <= 0)
+ {
+ hero2.sleepTime = 0;
+ hero2.buf = false;
+ heroes.Add(hero2);
+ logger.Winner(hero2);
+ logger.Death(hero1);
+ break;
+ }
+ turn = 0;
+ }
+ }
+ }
+ }
+}
diff --git a/RPG/Hero.cs b/RPG/Hero.cs
new file mode 100644
index 0000000..d63c850
--- /dev/null
+++ b/RPG/Hero.cs
@@ -0,0 +1,55 @@
+using System;
+
+namespace RPG
+{
+ public class Hero
+ {
+ Random random = new Random();
+ public string Name { get; protected set; }
+ public int Strength { get; protected set; }
+ public int Health { get; set; }
+ public string typeClass;
+ public string[] skills;
+ public string skillName;
+ public bool buf = false;
+ public string bufName;
+ public int sleepTime = 0;
+ public int maxHealth;
+ public Hero()
+ {
+ Health = random.Next(100,300);
+ maxHealth = Health;
+ Name = Names[random.Next(0,9)];
+ Strength = random.Next(10,50);
+ }
+ public static string[] Names = new string[10]{
+ "Player1",
+ "Player2",
+ "Player3",
+ "Player4",
+ "Player5",
+ "Player6",
+ "Player7",
+ "Player8",
+ "Player9",
+ "Player10"
+ };
+
+ public virtual void Skill(out string skillName, out int damage)
+ {
+ skillName = "";
+ damage = 0;
+ }
+
+ public void Atack(out int damage)
+ {
+ damage = random.Next(1, Strength);
+ }
+
+ public int GetDamage(int damage)
+ {
+ Health -= damage;
+ return Health;
+ }
+ }
+}
diff --git a/RPG/Knight.cs b/RPG/Knight.cs
new file mode 100644
index 0000000..953dcaa
--- /dev/null
+++ b/RPG/Knight.cs
@@ -0,0 +1,50 @@
+using System;
+
+namespace RPG
+{
+ public class Knight : Hero
+ {
+ Random random = new Random();
+
+ public Knight()
+ : base()
+ {
+ typeClass = "Рыцарь";
+ skills = new string[]{"Удар возмездия", "Удар с размаху", "Раскол земли"};
+ }
+
+ public override void Skill(out string skillName, out int damage)
+ {
+ int probability = random.Next(0, 100);
+ if(probability <= 20)
+ {
+ skillName = "Удар возмездия";
+ }
+ else if(probability <= 90)
+ {
+ skillName = "Удар с размаху";
+ }
+ else
+ {
+ skillName = "Раскол земли";
+ }
+
+ switch(skillName)
+ {
+ case "Удар возмездия":
+ damage = (int)Math.Floor(Strength * 1.5);
+ break;
+ case "Удар с размаху":
+ damage = (int)Math.Floor(Strength * 1.8);
+ break;
+ case "Раскол земли":
+ sleepTime = 3;
+ damage = (int)Math.Floor(Strength * 2.5);
+ break;
+ default:
+ damage = 0;
+ break;
+ }
+ }
+ }
+}
diff --git a/RPG/Logger.cs b/RPG/Logger.cs
new file mode 100644
index 0000000..289a1b7
--- /dev/null
+++ b/RPG/Logger.cs
@@ -0,0 +1,80 @@
+using System;
+
+namespace RPG
+{
+ class Logger
+ {
+ public void Atack(Hero hero1, Hero hero2, int damage)
+ {
+ if(hero1.typeClass == "Рыцарь")
+ {
+ Console.Write($"{hero1.Name} {hero1.typeClass} ({hero1.Health} / {hero1.maxHealth}) ударил мечом {hero2.Name} {hero2.typeClass} ({hero2.Health} / {hero2.maxHealth}) и нанёс {damage} урона.");
+ }
+ else if(hero1.typeClass == "Лучник")
+ {
+ Console.Write($"{hero1.Name} {hero1.typeClass} ({hero1.Health} / {hero1.maxHealth}) выстрелил в {hero2.Name} {hero2.typeClass} ({hero2.Health} / {hero2.maxHealth}) и нанёс {damage} урона.");
+ }
+ else if(hero1.typeClass == "Маг")
+ {
+ Console.Write($"{hero1.Name} {hero1.typeClass} ({hero1.Health} / {hero1.maxHealth}) ударил посохом {hero2.Name} {hero2.typeClass} ({hero2.Health} / {hero2.maxHealth}) и нанёс {damage} урона.");
+ }
+ else
+ {
+ Console.Write($"{hero1.Name} {hero1.typeClass} ({hero1.Health} / {hero1.maxHealth}) ударил {hero2.Name} {hero2.typeClass} ({hero2.Health} / {hero2.maxHealth}) и нанёс {damage} урона.");
+ }
+
+ if(hero1.buf)
+ {
+ Console.WriteLine($" Дополнительный урон 10 единиц из-за усиления \"{hero1.bufName}\".");
+ }
+ else
+ {
+ Console.WriteLine();
+ }
+ }
+
+ public void Skill(Hero hero1, Hero hero2, string skillName, int damage)
+ {
+ if(hero1.sleepTime > 0 && damage == 0)
+ {
+ Console.WriteLine($"{hero1.Name} {hero1.typeClass} ({hero1.Health} / {hero1.maxHealth}) использует умение \"{skillName}\" и оглушает {hero2.Name} {hero2.typeClass} ({hero2.Health} / {hero2.maxHealth}) на {hero1.sleepTime} хода.");
+ }
+ else if(hero1.sleepTime > 1)
+ {
+ Console.WriteLine($"{hero1.Name} {hero1.typeClass} ({hero1.Health} / {hero1.maxHealth}) использовал(-a) умение \"{skillName}\" и нанес {hero2.Name} {hero2.typeClass} {damage} урона. {hero2.Name} {hero2.typeClass} ({hero2.Health} / {hero2.maxHealth}) оглушен на {hero1.sleepTime} ход(-а).");
+ }
+ else if(hero1.buf && damage == 0)
+ {
+ Console.WriteLine($"{hero1.Name} {hero1.typeClass} ({hero1.Health} / {hero1.maxHealth}) активировал усиление \"{skillName}\"");
+ }
+ else
+ {
+ Console.Write($"{hero1.Name} {hero1.typeClass} ({hero1.Health} / {hero1.maxHealth}) использовал умение \"{skillName}\" и нанес {hero2.Name} {hero2.typeClass} ({hero2.Health} / {hero2.maxHealth}) {damage} урона.");
+
+ if(hero1.buf)
+ {
+ Console.WriteLine($" Дополнительный урон 10 единиц из-за усиления \"{hero1.bufName}\".");
+ }
+ else
+ {
+ Console.WriteLine();
+ }
+ }
+ }
+
+ public void Sleep(Hero hero)
+ {
+ Console.WriteLine($"{hero.Name} {hero.typeClass} ({hero.Health} / {hero.maxHealth}) оглушен и пропускает ход.");
+ }
+
+ public void Winner(Hero hero)
+ {
+ Console.WriteLine($"{hero.Name} {hero.typeClass} ({hero.Health} / {hero.maxHealth}) победил!");
+ }
+
+ public void Death(Hero hero)
+ {
+ Console.WriteLine($"{hero.Name} {hero.typeClass} погибает");
+ }
+ }
+}
diff --git a/RPG/Necromancer.cs b/RPG/Necromancer.cs
new file mode 100644
index 0000000..c90da17
--- /dev/null
+++ b/RPG/Necromancer.cs
@@ -0,0 +1,65 @@
+using System;
+
+namespace RPG
+{
+ public class Necromancer : Hero
+ {
+ Random random = new Random();
+
+ public Necromancer()
+ : base()
+ {
+ typeClass = "Некромант";
+ skills = new string[]{"Мрачная жатва", "Трупное копье", "Вампиризм"};
+ }
+
+ public override void Skill(out string skillName, out int damage)
+ {
+ int probability = random.Next(0, 100);
+ if(!buf)
+ {
+ if(probability <= 15)
+ {
+ skillName = "Вампиризм";
+ }
+ else if(probability <= 70)
+ {
+ skillName = "Мрачная жатва";
+ }
+ else
+ {
+ skillName = "Трупное копье";
+ }
+ }
+ else
+ {
+ if(probability <= 50)
+ {
+ skillName = "Вампиризм";
+ }
+ else
+ {
+ skillName = "Трупное копье";
+ }
+ }
+
+ switch(skillName)
+ {
+ case "Вампиризм":
+ damage = (int)(Strength * 1.8);
+ break;
+ case "Мрачная жатва":
+ damage = (int)(Strength * 2.5);
+ break;
+ case "Трупное копье":
+ bufName = "Трупное копье";
+ buf = true;
+ damage = 0;
+ break;
+ default:
+ damage = 0;
+ break;
+ }
+ }
+ }
+}
diff --git a/RPG/Program.cs b/RPG/Program.cs
new file mode 100644
index 0000000..dec3ee2
--- /dev/null
+++ b/RPG/Program.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+
+namespace RPG
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ Game game = new Game();
+ Console.Write("Введите число героев: ");
+ int numOfHeroes = Int32.Parse(Console.ReadLine());
+
+ if(numOfHeroes % 2 != 0)
+ {
+ numOfHeroes += 1;
+ }
+
+ game.Start(numOfHeroes);
+
+ Console.ReadKey();
+ }
+ }
+}
diff --git a/RPG/RPG.csproj b/RPG/RPG.csproj
new file mode 100644
index 0000000..f94b956
--- /dev/null
+++ b/RPG/RPG.csproj
@@ -0,0 +1,8 @@
+
+
+
+ Exe
+ netcoreapp2.0
+
+
+
\ No newline at end of file
diff --git a/RPG/Wizard.cs b/RPG/Wizard.cs
new file mode 100644
index 0000000..140aeed
--- /dev/null
+++ b/RPG/Wizard.cs
@@ -0,0 +1,43 @@
+using System;
+
+namespace RPG
+{
+ public class Wizard : Hero
+ {
+ Random random = new Random();
+
+ public Wizard()
+ : base()
+ {
+ skills = new string[]{"Объятия смерти","Жатва душ"};
+ typeClass = "Маг";
+ }
+
+ public override void Skill(out string skillName, out int damage)
+ {
+ int probability = random.Next(0, 100);
+ if(probability <= 60 && sleepTime == 0)
+ {
+ skillName = "Объятия смерти";
+ }
+ else
+ {
+ skillName = "Жатва душ";
+ }
+
+ switch(skillName)
+ {
+ case "Объятия смерти":
+ sleepTime = 5;
+ damage = 1;
+ break;
+ case "Жатва душ":
+ damage = (int)Math.Floor(Strength * 1.5);
+ break;
+ default:
+ damage = 1;
+ break;
+ }
+ }
+ }
+}
diff --git a/courseworkspace.code-workspace b/courseworkspace.code-workspace
index 4f9af01..fc9ab32 100644
--- a/courseworkspace.code-workspace
+++ b/courseworkspace.code-workspace
@@ -5,6 +5,12 @@
},
{
"path": "CourseApp.Tests"
+ },
+ {
+ "path": "RPG"
+ },
+ {
+ "path": "RPG.Tests"
}
],
"settings": {}