From aeb27bc23b08cdf09d3f75540aef1d1c06e6c7f9 Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 10 Oct 2019 09:39:40 +0300 Subject: [PATCH 01/25] Sample of 1st lab --- CourseApp/Program.cs | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 248bbe4..11e476f 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -4,9 +4,61 @@ namespace CourseApp { public class Program { + public static double MyFunction(double a, double b, double x) + { + var c = (b * x) + a; + return c; + } + + public static double[] TaskA ( + double a, + double b, + double xn, + double xk, + double dx) + { + var steps = (int)Math.Floor((xk - xn) / dx); + var y = new double[steps]; + var i = 0; + for (var x = xn; x < xk; x += dx) + { + y[i] = MyFunction(a, b, x); + i++; + } + + return y; + } + + public static double[] TaskB ( + double a, + double b, + double[] x) + { + var y = new double[x.Length]; + for (int i = 0; i < x.Length; i++) + { + y[i] = MyFunction(a, b, x[i]); + } + + return y; + } + public static void Main(string[] args) { Console.WriteLine("Hello World!"); + var taskA = TaskA(2, 3, 0, 5, 1); + for (var i = 0; i < taskA.Length; i++) + { + Console.WriteLine($"y={taskA[i]}"); + } + + var xB = new double[] { 0, 1, 2, 3 }; + var taskB = TaskB(2, 3, xB); + for (var i = 0; i < xB.Length; i++) + { + Console.WriteLine($"x={xB[i]} y={taskB[i]}"); + } + Console.ReadLine(); } } From 02472201c8e437f910a9fcd8e11ad50403aae5fa Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 17 Oct 2019 09:32:31 +0300 Subject: [PATCH 02/25] Tests samples --- CourseApp.Tests/DemoTest.cs | 25 +++++++++++++++++++++++-- CourseApp/CourseApp.sln | 31 +++++++++++++++++++++++++++++++ CourseApp/Program.cs | 4 +++- 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 CourseApp/CourseApp.sln diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index fdc46f5..bd31c5c 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -5,10 +5,31 @@ namespace CourseApp.Tests { public class DemoTest { + [Theory] + [InlineData(0, 0, 0, double.NaN)] + [InlineData(1, 1, 2, 2.5)] + [InlineData(-1, 1, 1, 0)] + public void TestCalc(double a, double b, double x, double exp) + { + var res = Program.MyFunction(a, b, x); + Assert.Equal(exp, res, 3); + } + + [Fact] + public void TestNormalA() + { + } + + [Fact] + public void TestNormalB() + { + } + [Fact] - public void Test1() + public void TestZeroLengthB() { - Assert.True(true); + var res = Program.TaskB(1, 1, new double[0]); + Assert.Empty(res); } } } 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/Program.cs b/CourseApp/Program.cs index 11e476f..e887881 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -6,7 +6,7 @@ public class Program { public static double MyFunction(double a, double b, double x) { - var c = (b * x) + a; + var c = (b * x) + (a / x); return c; } @@ -47,6 +47,8 @@ public static void Main(string[] args) { Console.WriteLine("Hello World!"); var taskA = TaskA(2, 3, 0, 5, 1); + Console.WriteLine(taskA); + for (var i = 0; i < taskA.Length; i++) { Console.WriteLine($"y={taskA[i]}"); From d514055c9f7c9797067e4a2a8d7c641baa08abe6 Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 24 Oct 2019 08:32:42 +0300 Subject: [PATCH 03/25] Added actions file --- .github/workflows/dotnetcore.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/dotnetcore.yml diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml new file mode 100644 index 0000000..9c411d0 --- /dev/null +++ b/.github/workflows/dotnetcore.yml @@ -0,0 +1,23 @@ +name: .NET Core + +on: [push] + +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 From b29aa6068fc4563d806b34b69b12709aa396960b Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 24 Oct 2019 08:37:06 +0300 Subject: [PATCH 04/25] Fixed run steps (#28) --- .github/workflows/dotnetcore.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 9c411d0..a09addb 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -14,10 +14,10 @@ jobs: with: dotnet-version: 2.1.802 - name: Build with dotnet - run: + run: | cd CourseApp dotnet build --configuration Release - name: Run tests - run: + run: | cd CourseApp.Tests dotnet test From dbae387a93373aae5ee85254037203dd830c012b Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 24 Oct 2019 09:25:23 +0300 Subject: [PATCH 05/25] Test actions on PR (#30) --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index a09addb..22cc4eb 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -1,6 +1,6 @@ name: .NET Core -on: [push] +on: [push, pull_request] jobs: build: From 953427ebb4df2222f1edbd3967812883ed4ecb0a Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 24 Oct 2019 09:28:33 +0300 Subject: [PATCH 06/25] Added tests and sample A|B tasks --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 556d11d..b422454 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# Tprogramming_147_2019 \ No newline at end of file +# Tprogramming_147_2019 +Konstantinov Eugeny \ No newline at end of file From 62b5d9ec96a03500857576f39c0a2aabe5aa348f Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 7 Nov 2019 09:14:46 +0300 Subject: [PATCH 07/25] Added class task example, added vscode conf --- .gitignore | 1 - CourseApp.Tests/PlatypusTest.cs | 55 ++++++++++++++++++++++++++++++ CourseApp/.vscode/launch.json | 25 ++++++++++++++ CourseApp/.vscode/tasks.json | 42 +++++++++++++++++++++++ CourseApp/Platypus.cs | 60 +++++++++++++++++++++++++++++++++ CourseApp/Program.cs | 3 ++ 6 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 CourseApp.Tests/PlatypusTest.cs create mode 100644 CourseApp/.vscode/launch.json create mode 100644 CourseApp/.vscode/tasks.json create mode 100644 CourseApp/Platypus.cs diff --git a/.gitignore b/.gitignore index 35d4ccd..24cb440 100644 --- a/.gitignore +++ b/.gitignore @@ -198,7 +198,6 @@ $RECYCLE.BIN/ **/node_modules/* # Added by Jskonst -.vscode/ Properties/ ##### diff --git a/CourseApp.Tests/PlatypusTest.cs b/CourseApp.Tests/PlatypusTest.cs new file mode 100644 index 0000000..77c4d8f --- /dev/null +++ b/CourseApp.Tests/PlatypusTest.cs @@ -0,0 +1,55 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class PlatypusTest + { + [Fact] + public void TestEmptyConstructor() + { + var item = new Platypus(); + Assert.Equal(0, item.Age); + Assert.Equal("Untitled", item.Name); + Assert.True(item.IsMale); + } + + [Fact] + public void TestView() + { + var item = new Platypus(); + var view = @" + _.-^~~^^^`~-,_,,~''''''```~,''``~'``~, + ______,' -o :. _ . ; ,'`, `. +( -\.._,.;;'._ ,( } _`_-_,, `, `, + ``~~~~~~' ((/'((((____/~~~~~~'(,(,___> `~' + "; + Assert.Equal(view, item.View()); + } + + [Fact] + public void TestSetAge() + { + var item = new Platypus(); + item.Age = 5; + Assert.Equal(5, item.Age); + } + + [Fact] + public void TestIncorrectSetAge() + { + var item = new Platypus(); + item.Age = -5; + Assert.Equal(0, item.Age); + } + + [Fact] + public void TestCorrectIncorrectSetAge() + { + var item = new Platypus(); + item.Age = 10; + item.Age = -5; + Assert.Equal(10, item.Age); + } + } +} 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/Platypus.cs b/CourseApp/Platypus.cs new file mode 100644 index 0000000..eb3d463 --- /dev/null +++ b/CourseApp/Platypus.cs @@ -0,0 +1,60 @@ +using System; + +namespace CourseApp +{ + public class Platypus + { + private int age; + + public Platypus() + : this(0, "Untitled", true) + { + } + + public Platypus(int age, string name, bool isMale) + { + Name = name; + Age = age; + IsMale = isMale; + } + + public string Name { get; set; } + + public int Age + { + get + { + return this.age; + } + + set + { + if (value >= 0 && value < 20) + { + this.age = value; + } + else + { + Console.WriteLine("Age should be > 0 and < than 20"); + } + } + } + + public bool IsMale { get; set; } + + public bool IsPoisoned + { + get { return this.IsMale; } + } + + public string View() + { + return @" + _.-^~~^^^`~-,_,,~''''''```~,''``~'``~, + ______,' -o :. _ . ; ,'`, `. +( -\.._,.;;'._ ,( } _`_-_,, `, `, + ``~~~~~~' ((/'((((____/~~~~~~'(,(,___> `~' + "; + } + } +} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index e887881..a43396c 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -61,6 +61,9 @@ public static void Main(string[] args) Console.WriteLine($"x={xB[i]} y={taskB[i]}"); } + var item = new Platypus(); + Console.WriteLine(item.View()); + Console.ReadLine(); } } From 0d30c7535b1a599b86806e0414683d7dcc04350c Mon Sep 17 00:00:00 2001 From: Dmitry-ops <52451095+Dmitry-ops@users.noreply.github.com> Date: Mon, 16 Dec 2019 09:20:41 +0300 Subject: [PATCH 08/25] =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=20=D0=B3=D0=B8?= =?UTF-8?q?=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dotnetcore.yml | 2 +- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp/CourseApp.csproj | 2 +- CourseApp/Program.cs | 57 +++++++++++--------------- 4 files changed, 28 insertions(+), 35 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 22cc4eb..3828afc 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -12,7 +12,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 2.1.802 + dotnet-version: 2.0.9 - name: Build with dotnet run: | cd CourseApp diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 8fb7e4a..05826cc 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1 + True 1573,1591,1701;1702;1705 false diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index b244e47..18c71a6 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.1 + True 1573,1591,1701;1702;1705; diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index a43396c..59605be 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,43 +1,38 @@ -using System; +using System.Collections; +using System.Collections.Generic; +using System; namespace CourseApp { public class Program { - public static double MyFunction(double a, double b, double x) + public static double MyFunction(double x) { - var c = (b * x) + (a / x); - return c; + var y = Math.Pow(Math.Pow(Math.Asin(x), 2) + Math.Pow(Math.Acos(x), 4), 3); + return y; } - public static double[] TaskA ( - double a, - double b, + public static List TaskA( double xn, double xk, double dx) { - var steps = (int)Math.Floor((xk - xn) / dx); - var y = new double[steps]; - var i = 0; + List y = new List(); for (var x = xn; x < xk; x += dx) { - y[i] = MyFunction(a, b, x); - i++; + y.Add(MyFunction(x)); } return y; } - public static double[] TaskB ( - double a, - double b, - double[] x) + public static List TaskB( + List x) { - var y = new double[x.Length]; - for (int i = 0; i < x.Length; i++) + List y = new List(5); + foreach (double i in x) { - y[i] = MyFunction(a, b, x[i]); + y.Add(MyFunction(i)); } return y; @@ -46,25 +41,23 @@ public static double[] TaskB ( public static void Main(string[] args) { Console.WriteLine("Hello World!"); - var taskA = TaskA(2, 3, 0, 5, 1); - Console.WriteLine(taskA); - - for (var i = 0; i < taskA.Length; i++) + List taskA = TaskA(0.26, 0.66, 0.08); + foreach (var item in taskA) { - Console.WriteLine($"y={taskA[i]}"); + Console.WriteLine($"y={item}"); } - var xB = new double[] { 0, 1, 2, 3 }; - var taskB = TaskB(2, 3, xB); - for (var i = 0; i < xB.Length; i++) + List xB = new List { 0.1, 0.35, 0.4, 0.55, 0.6 }; + List taskB = TaskB(xB); + for (int i = 0; i < 5; i++) { - Console.WriteLine($"x={xB[i]} y={taskB[i]}"); + Console.WriteLine($"x={xB[i]}"); } - var item = new Platypus(); - Console.WriteLine(item.View()); - - Console.ReadLine(); + foreach (var item in taskB) + { + Console.WriteLine($"y={item}"); + } } } } From 403c9972ec30a7f77703681be8ff3d330ebd6bef Mon Sep 17 00:00:00 2001 From: Dmitry-ops <52451095+Dmitry-ops@users.noreply.github.com> Date: Mon, 16 Dec 2019 18:17:07 +0300 Subject: [PATCH 09/25] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp.Tests/DemoTest.cs | 37 ++++++++++++++++++-------- CourseApp/CourseApp.csproj | 2 +- CourseApp/Program.cs | 2 +- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 05826cc..8fb7e4a 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@ - + netcoreapp2.1 True 1573,1591,1701;1702;1705 false diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index bd31c5c..c4d7cda 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Xunit; namespace CourseApp.Tests @@ -6,30 +7,44 @@ namespace CourseApp.Tests public class DemoTest { [Theory] - [InlineData(0, 0, 0, double.NaN)] - [InlineData(1, 1, 2, 2.5)] - [InlineData(-1, 1, 1, 0)] - public void TestCalc(double a, double b, double x, double exp) + [InlineData(0.2, 45.024015896718936)] + [InlineData(0.3, 18.87433958817845)] + public void TestMyFunction(double x, double exp) { - var res = Program.MyFunction(a, b, x); - Assert.Equal(exp, res, 3); + Assert.Equal(Program.MyFunction(x), exp, 3); } [Fact] - public void TestNormalA() + + public void TestTaskA() { + double xn = 0.26; + double xk = 0.66; + double dx = 0.08; + List res = Program.TaskA(xn, xk, dx); + List expy = new List { 26.84410487237168, 13.21117766406966, 6.447227535266805, 3.220397731030495, 1.7472761588502188, 1.1298385487203866 }; + for (int i = 0; i < 6; i++) + { + Assert.Equal(expy[i], res[i], 3); + } } [Fact] - public void TestNormalB() + public void Test1() { + Assert.True(true); } [Fact] - public void TestZeroLengthB() + public void TestTaskB() { - var res = Program.TaskB(1, 1, new double[0]); - Assert.Empty(res); + List xB = new List { 0.1, 0.35, 0.4, 0.55, 0.6 }; + List taskB = Program.TaskB(xB); + List expy = new List { 102.99803805648071, 12.078220437571703, 7.709481911813682, 2.16507891445927, 1.5347282613199904 }; + for (int i = 0; i < 5; i++) + { + Assert.Equal(expy[i], taskB[i], 3); + } } } } diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index 18c71a6..b244e47 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,7 @@ Exe - + netcoreapp2.1 True 1573,1591,1701;1702;1705; diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 59605be..b604f47 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -40,7 +40,7 @@ public static List TaskB( public static void Main(string[] args) { - Console.WriteLine("Hello World!"); + Console.WriteLine(MyFunction(0.3)); List taskA = TaskA(0.26, 0.66, 0.08); foreach (var item in taskA) { From fea4f80413619ed015862be9f85cd90d584a4a7d Mon Sep 17 00:00:00 2001 From: Dmitry-ops <52451095+Dmitry-ops@users.noreply.github.com> Date: Mon, 16 Dec 2019 20:32:56 +0300 Subject: [PATCH 10/25] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp/CourseApp.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 8fb7e4a..fb93e6a 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1 + netcoreapp2.0 True 1573,1591,1701;1702;1705 false diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index b244e47..dffae8d 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.1 + netcoreapp2.0 True 1573,1591,1701;1702;1705; From 54e0836f8e9d3dc74dcf07f3d5fdda637ffaca90 Mon Sep 17 00:00:00 2001 From: nzrvdm <52451095+Dmitry-ops@users.noreply.github.com> Date: Mon, 16 Dec 2019 21:22:24 +0300 Subject: [PATCH 11/25] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 2db6ffb..523cfb8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ # Tprogramming_147_2019 -<<<<<<< HEAD Nazarov Dmitrij ======= Konstantinov Eugeny From c051f7f2bc4dbacc155f0083f19bd1fd18853f85 Mon Sep 17 00:00:00 2001 From: nzrvdm <52451095+Dmitry-ops@users.noreply.github.com> Date: Mon, 16 Dec 2019 21:23:03 +0300 Subject: [PATCH 12/25] Update CourseApp.Tests.csproj --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index fb93e6a..8fb7e4a 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.0 + netcoreapp2.1 True 1573,1591,1701;1702;1705 false From 9bfd145436da5d7c61c5193bb895955dfe426f9a Mon Sep 17 00:00:00 2001 From: nzrvdm <52451095+Dmitry-ops@users.noreply.github.com> Date: Mon, 16 Dec 2019 21:23:29 +0300 Subject: [PATCH 13/25] Update CourseApp.csproj --- CourseApp/CourseApp.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index dffae8d..b244e47 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.0 + netcoreapp2.1 True 1573,1591,1701;1702;1705; From cd1d6ac577043d0cc954a3d3662152dadec198f2 Mon Sep 17 00:00:00 2001 From: nzrvdm <52451095+Dmitry-ops@users.noreply.github.com> Date: Mon, 16 Dec 2019 21:23:52 +0300 Subject: [PATCH 14/25] Update dotnetcore.yml --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 3828afc..006c7f6 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -12,7 +12,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 2.0.9 + dotnet-version: 2.1 - name: Build with dotnet run: | cd CourseApp From c7ea2d29f6cdd4b33a40d19b05e75b70e7ef6fa0 Mon Sep 17 00:00:00 2001 From: Dmitry-ops <52451095+Dmitry-ops@users.noreply.github.com> Date: Mon, 16 Dec 2019 21:36:04 +0300 Subject: [PATCH 15/25] =?UTF-8?q?=D0=A2=D0=95=D0=A1=D0=A2=D0=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp.Tests/dotnetcore.yml | 23 +++++++++++++++++++++++ CourseApp/CourseApp.csproj | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 CourseApp.Tests/dotnetcore.yml diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index fb93e6a..8fb7e4a 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.0 + netcoreapp2.1 True 1573,1591,1701;1702;1705 false diff --git a/CourseApp.Tests/dotnetcore.yml b/CourseApp.Tests/dotnetcore.yml new file mode 100644 index 0000000..22cc4eb --- /dev/null +++ b/CourseApp.Tests/dotnetcore.yml @@ -0,0 +1,23 @@ +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 diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index dffae8d..b244e47 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.0 + netcoreapp2.1 True 1573,1591,1701;1702;1705; From f8c6ec05aaadd1567a87dd7edcfd3882d2474b63 Mon Sep 17 00:00:00 2001 From: nzrvdm <52451095+Dmitry-ops@users.noreply.github.com> Date: Tue, 17 Dec 2019 16:24:18 +0300 Subject: [PATCH 16/25] Update dotnetcore.yml --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 006c7f6..22cc4eb 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -12,7 +12,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 2.1 + dotnet-version: 2.1.802 - name: Build with dotnet run: | cd CourseApp From d7c02eed9b2079231250ce89de6f25f129e6b0fd Mon Sep 17 00:00:00 2001 From: Dmitry-ops <52451095+Dmitry-ops@users.noreply.github.com> Date: Sun, 22 Dec 2019 23:31:27 +0300 Subject: [PATCH 17/25] added 2 lab --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp.Tests/HeroTest.cs | 56 ++++++++++++++++++++ CourseApp.Tests/PlatypusTest.cs | 55 -------------------- CourseApp/Hero.cs | 72 ++++++++++++++++++++++++++ CourseApp/Platypus.cs | 60 --------------------- 5 files changed, 129 insertions(+), 116 deletions(-) create mode 100644 CourseApp.Tests/HeroTest.cs delete mode 100644 CourseApp.Tests/PlatypusTest.cs create mode 100644 CourseApp/Hero.cs delete mode 100644 CourseApp/Platypus.cs diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 8fb7e4a..14017b5 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -2,7 +2,7 @@ netcoreapp2.1 - True + False 1573,1591,1701;1702;1705 false diff --git a/CourseApp.Tests/HeroTest.cs b/CourseApp.Tests/HeroTest.cs new file mode 100644 index 0000000..70632f4 --- /dev/null +++ b/CourseApp.Tests/HeroTest.cs @@ -0,0 +1,56 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class HeroTest + { + [Fact] + public void TestEmptyConstructor() + { + var item = new Hero(); + Assert.Equal(0, item.Level); + Assert.Equal("No role", item.Role); + Assert.True(item.Attack); + } + + [Fact] + public void TestSetAge() + { + var item = new Hero(); + item.Level = 5; + Assert.Equal(5, item.Level); + } + + [Fact] + public void TestShoot() + { + var item = new Hero("Sniper", 10, true); + var act = item.Shoot(true); + Assert.Equal($"Hero Sniper and 10 made the shot!", act); + } + + [Fact] + public void TestNumShoot() + { + var item = new Hero("Sniper", 10, true); + var act = item.NumShoot(15); + Assert.Equal($"Sniper made of 15 shots!", act); + } + + [Fact] + public void TestCorrectIncorrectSetLevel() + { + var item = new Hero(); + try + { + item.Level = -5; + Assert.Equal(-5, item.Level); + } + catch (System.Exception) + { + Assert.True(true); + } + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/PlatypusTest.cs b/CourseApp.Tests/PlatypusTest.cs deleted file mode 100644 index 77c4d8f..0000000 --- a/CourseApp.Tests/PlatypusTest.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using Xunit; - -namespace CourseApp.Tests -{ - public class PlatypusTest - { - [Fact] - public void TestEmptyConstructor() - { - var item = new Platypus(); - Assert.Equal(0, item.Age); - Assert.Equal("Untitled", item.Name); - Assert.True(item.IsMale); - } - - [Fact] - public void TestView() - { - var item = new Platypus(); - var view = @" - _.-^~~^^^`~-,_,,~''''''```~,''``~'``~, - ______,' -o :. _ . ; ,'`, `. -( -\.._,.;;'._ ,( } _`_-_,, `, `, - ``~~~~~~' ((/'((((____/~~~~~~'(,(,___> `~' - "; - Assert.Equal(view, item.View()); - } - - [Fact] - public void TestSetAge() - { - var item = new Platypus(); - item.Age = 5; - Assert.Equal(5, item.Age); - } - - [Fact] - public void TestIncorrectSetAge() - { - var item = new Platypus(); - item.Age = -5; - Assert.Equal(0, item.Age); - } - - [Fact] - public void TestCorrectIncorrectSetAge() - { - var item = new Platypus(); - item.Age = 10; - item.Age = -5; - Assert.Equal(10, item.Age); - } - } -} diff --git a/CourseApp/Hero.cs b/CourseApp/Hero.cs new file mode 100644 index 0000000..6100677 --- /dev/null +++ b/CourseApp/Hero.cs @@ -0,0 +1,72 @@ +using System; + +namespace CourseApp +{ + public class Hero + { + private double level; + + public Hero() + : this("No role", 0, true) + { + } + + public Hero(string role, double level, bool attack) + { + Role = role; + Level = level; + Attack = attack; + } + + public string Role { get; set; } + + public double Level + { + get + { + return this.level; + } + + set + { + if (value >= 0 && value < 20) + { + this.level = value; + } + else + { + throw new Exception("Enter correct level"); + } + } + } + + public bool Attack { get; set; } + + public bool CanShoot + { + get { return this.Attack; } + } + + public string Shoot(bool canShoot) + { + if (canShoot == true) + { + return $"Hero {Role} and {Level} made the shot!"; + } + else + { + return $"Hero {Role} and {Level} not made the shot!"; + } + } + + public override string ToString() + { + return $"Hero-{Role}, {Level}, {Attack}"; + } + + public string NumShoot(int shot) + { + return $"{Role} made of {shot} shots!"; + } + } +} \ No newline at end of file diff --git a/CourseApp/Platypus.cs b/CourseApp/Platypus.cs deleted file mode 100644 index eb3d463..0000000 --- a/CourseApp/Platypus.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; - -namespace CourseApp -{ - public class Platypus - { - private int age; - - public Platypus() - : this(0, "Untitled", true) - { - } - - public Platypus(int age, string name, bool isMale) - { - Name = name; - Age = age; - IsMale = isMale; - } - - public string Name { get; set; } - - public int Age - { - get - { - return this.age; - } - - set - { - if (value >= 0 && value < 20) - { - this.age = value; - } - else - { - Console.WriteLine("Age should be > 0 and < than 20"); - } - } - } - - public bool IsMale { get; set; } - - public bool IsPoisoned - { - get { return this.IsMale; } - } - - public string View() - { - return @" - _.-^~~^^^`~-,_,,~''''''```~,''``~'``~, - ______,' -o :. _ . ; ,'`, `. -( -\.._,.;;'._ ,( } _`_-_,, `, `, - ``~~~~~~' ((/'((((____/~~~~~~'(,(,___> `~' - "; - } - } -} \ No newline at end of file From 3f3f8ea7c80e8da589028b0c11e60a7ed7f2dee8 Mon Sep 17 00:00:00 2001 From: Dmitry-ops <52451095+Dmitry-ops@users.noreply.github.com> Date: Sat, 4 Jan 2020 17:12:51 +0300 Subject: [PATCH 18/25] ya sdelal' --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 14017b5..8fb7e4a 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -2,7 +2,7 @@ netcoreapp2.1 - False + True 1573,1591,1701;1702;1705 false From 6df2620a0473d8d99b6d53abb60d90099b899f3a Mon Sep 17 00:00:00 2001 From: Dmitry-ops <52451095+Dmitry-ops@users.noreply.github.com> Date: Sat, 4 Jan 2020 17:23:46 +0300 Subject: [PATCH 19/25] ya sdelal'(1) --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 523cfb8..1a204a4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,2 @@ -# Tprogramming_147_2019 Nazarov Dmitrij -======= -Konstantinov Eugeny ->>>>>>> master +# Tprogramming_147_2019 From caf57b04af5e583b31ea6be11d1c42cf93a1adb1 Mon Sep 17 00:00:00 2001 From: Dmitry-ops <52451095+Dmitry-ops@users.noreply.github.com> Date: Mon, 6 Jan 2020 16:33:35 +0300 Subject: [PATCH 20/25] polymorthism and age --- CourseApp.Tests/AgeCounterTest.cs | 55 ++++++++++++ CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp.Tests/HeroTest.cs | 79 ++++++++++-------- ...0\257\321\200\320\273\321\213\320\272.lnk" | Bin 0 -> 1059 bytes CourseApp/AgeCounter.cs | 51 +++++++++++ CourseApp/Character.cs | 59 +++++++++++++ CourseApp/Enemy.cs | 39 +++++++++ CourseApp/Hero.cs | 41 +-------- CourseApp/Program.cs | 9 ++ 9 files changed, 261 insertions(+), 74 deletions(-) create mode 100644 CourseApp.Tests/AgeCounterTest.cs create mode 100644 "CourseApp/.vscode/CourseApp - \320\257\321\200\320\273\321\213\320\272.lnk" create mode 100644 CourseApp/AgeCounter.cs create mode 100644 CourseApp/Character.cs create mode 100644 CourseApp/Enemy.cs diff --git a/CourseApp.Tests/AgeCounterTest.cs b/CourseApp.Tests/AgeCounterTest.cs new file mode 100644 index 0000000..bf02d1b --- /dev/null +++ b/CourseApp.Tests/AgeCounterTest.cs @@ -0,0 +1,55 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class AgeCounterTest + { + [Fact] + public void CorrectAgeInputTest() + { + var yeah = new AgeCounter(); + Assert.Equal($"Возраст:21 лет, 0 месяцев, 2 дней", yeah.CountAge(12, 10, 1999, 13, 10, 2020)); + } + + [Fact] + public void FutureDateInputTest() + { + var time = new AgeCounter(); + try + { + Assert.Equal($"Возраст:-2 лет, 2 месяцев, 6 дней", time.CountAge(16, 6, 2021, 19, 12, 2019)); + } + catch + { + Assert.True(true); + } + } + + [Fact] + public void CurrentDayIsBirthdayTest() + { + var time = new AgeCounter(); + var day = DateTime.Today.Day; + var month = DateTime.Today.Month; + var year = DateTime.Today.Year; + try + { + Assert.Equal($"Возраст:0 лет, 0 месяцев, 0 дней", time.CountAge(5, 1, 2020, 5, 1, 2020)); + } + catch + { + Assert.True(true); + } + } + + [Theory] + [InlineData(30, 11, 2000, 19, 0, 19)] + [InlineData(16, 11, 2000, 2, 1, 19)] + public void CurrectYearCountTest(int d, int m, int y, int expD, int expM, int expY) + { + var time = new AgeCounter(); + Assert.Equal($"Возраст:{expY} лет, {expM} месяцев, {expD} дней", time.CountAge(d, m, y, 19, 12, 2019)); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 8fb7e4a..3d63af4 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -11,7 +11,7 @@ - + ll diff --git a/CourseApp.Tests/HeroTest.cs b/CourseApp.Tests/HeroTest.cs index 70632f4..2ca18f4 100644 --- a/CourseApp.Tests/HeroTest.cs +++ b/CourseApp.Tests/HeroTest.cs @@ -14,43 +14,50 @@ public void TestEmptyConstructor() Assert.True(item.Attack); } - [Fact] - public void TestSetAge() - { - var item = new Hero(); - item.Level = 5; - Assert.Equal(5, item.Level); - } + [Fact] + public void TestSetAge() + { + var item = new Hero(); + item.Level = 5; + Assert.Equal(5, item.Level); + } - [Fact] - public void TestShoot() - { - var item = new Hero("Sniper", 10, true); - var act = item.Shoot(true); - Assert.Equal($"Hero Sniper and 10 made the shot!", act); - } + [Fact] + public void TestShoot() + { + var item = new Hero("Sniper", 10, true); + var act = item.Shoot(true); + Assert.Equal($"Hero Sniper and 10 made the shot!", act); + } + + [Fact] + public void TestNumShoot() + { + var item = new Hero("Sniper", 10, true); + var act = item.NumShoot(15); + Assert.Equal($"Sniper made of 15 shots!", act); + } - [Fact] - public void TestNumShoot() - { - var item = new Hero("Sniper", 10, true); - var act = item.NumShoot(15); - Assert.Equal($"Sniper made of 15 shots!", act); - } + [Fact] + public void TestCorrectIncorrectSetLevel() + { + var item = new Hero(); + try + { + item.Level = -5; + Assert.Equal(-5, item.Level); + } + catch (System.Exception) + { + Assert.True(true); + } + } - [Fact] - public void TestCorrectIncorrectSetLevel() - { - var item = new Hero(); - try - { - item.Level = -5; - Assert.Equal(-5, item.Level); - } - catch (System.Exception) - { - Assert.True(true); - } - } - } + [Fact] + public void TestCorrectArray() + { + var characters = new Character[] { new Hero(), new Enemy() }; + Assert.Equal(characters[1].ToString(), $"Enemy-No role, 0, True"); + } + } } \ No newline at end of file diff --git "a/CourseApp/.vscode/CourseApp - \320\257\321\200\320\273\321\213\320\272.lnk" "b/CourseApp/.vscode/CourseApp - \320\257\321\200\320\273\321\213\320\272.lnk" new file mode 100644 index 0000000000000000000000000000000000000000..95f4e9471dc725f630ae626d450cad2e635fa1bb GIT binary patch literal 1059 zcmb7DT}V@57=E|Tg=W-DE0b&@iHm5S$v`)gHa44ubk??hE(W@#&Z*lD+oYl&y6GZX zltpx5g@!f4BD+YbNDRD)x*7e^pU_PfhKYBLF6w#Da(XeSzQgl=@Atm%d7ksV-*=jc zNL8$cC7Mty?Kneuq=EmjJ3Tu+@>(@g@wBggba7Ua$g48-S-VqJOj_qBDOEmW4r;Ey z&7&=%cy&Eh+sxi<(W0}949a4Y^YRf51%h#^qkIx*Zag8S{2bLIf9#|H%UC-43MMH) zL5d@|8aBgpUOLyWA&=7~Ib0_Y@@DzI_&LXXqY7XCQZo2I-4Dq_GDRr@-YEGfgeOR0 ztXjZsq*}~1B*HhLz69JE&5P0@lZI^4UYEO(HSJl=uYS(4=962w_TW^nP}!i@3%wY% zlNI{1!cDXv^9F!h%yTusV;@iiECU)JS&V#4lAF+A^v~;&qme+=7YYT#ffj?Ywxvci zn7p<~Z#33!mBFnhJ)YJK!N38`JbHX`JR)!HlG{3sK4Y9pk5-+U{xH@&Je4#Aeua1I z#`|9;%Vr86+>L)uPxkyZ{~TY91`mY5ZE!o?v*P3THahJ{{zw%K#X2hXAl}Bp+CTXB z&X<#pY-C3FGpE0qX_RpVmc_*R%CR{|spiJKx;1g_+wDrkmvaS+v6HLiYY<-rkcG{K zg719o`Fxdo$8U0@wSp*Y7tFBbWCiT-OhP^EHlYrc%(4 now.Ticks) + { + throw new Exception("плохая дата;)"); + } + else if (birthday.Ticks == now.Ticks) + { + throw new Exception("нельзя вводить текущую дату"); + } + else + { + var age = new DateTime(today.Ticks - birthday.Ticks); + + return $"Возраст:{age.Year - 1} лет, {age.Month - 1} месяцев, {age.Day - 1} дней"; + } + } + + public string CountAge(int day, int month, int year, int nowDay, int nowMonth, int nowYear) + { + var birthday = new DateTime(year, month, day); + var today = new DateTime(nowYear, nowMonth, nowDay); + + if (birthday.Ticks > now.Ticks) + { + throw new Exception("плохая дата;)"); + } + else if (birthday.Ticks == now.Ticks) + { + throw new Exception("нельзя вводить текущую дату"); + } + else + { + var age = new DateTime(today.Ticks - birthday.Ticks); + + return $"Возраст:{age.Year - 1} лет, {age.Month - 1} месяцев, {age.Day - 1} дней"; + } + } + } +} \ No newline at end of file diff --git a/CourseApp/Character.cs b/CourseApp/Character.cs new file mode 100644 index 0000000..f10895e --- /dev/null +++ b/CourseApp/Character.cs @@ -0,0 +1,59 @@ +using System; + +namespace CourseApp +{ + public abstract class Character + { + private double level; + + public Character() + : this("No role", 0, true) + { + } + + public Character(string role, double level, bool attack) + { + Role = role; + Level = level; + Attack = attack; + } + + public string Role { get; set; } + + public double Level + { + get + { + return this.level; + } + + set + { + if (value >= 0 && value < 20) + { + this.level = value; + } + else + { + throw new Exception("Enter correct level"); + } + } + } + + public bool Attack { get; set; } + + public bool CanShoot + { + get { return this.Attack; } + } + + public abstract string Shoot(bool canShoot); + + public new abstract string ToString(); + + public virtual string NumShoot(int shot) + { + return $"{Role} made of {shot} shots to enemy!"; + } + } +} \ No newline at end of file diff --git a/CourseApp/Enemy.cs b/CourseApp/Enemy.cs new file mode 100644 index 0000000..3796145 --- /dev/null +++ b/CourseApp/Enemy.cs @@ -0,0 +1,39 @@ +using System; + +namespace CourseApp +{ + public class Enemy : Character + { + public Enemy() + : this("No role", 0, true) + { + } + + public Enemy(string role, double level, bool attack) + : base(role, level, attack) + { + } + + public override string Shoot(bool canShoot) + { + if (canShoot == true) + { + return $"Enemy {Role} and {Level} made the shot!"; + } + else + { + return $"Enemy {Role} and {Level} not made the shot!"; + } + } + + public override string ToString() + { + return $"Enemy-{Role}, {Level}, {Attack}"; + } + + public override string NumShoot(int shot) + { + return $"{Role} made of {shot} to himself!"; + } + } +} \ No newline at end of file diff --git a/CourseApp/Hero.cs b/CourseApp/Hero.cs index 6100677..4cae8a6 100644 --- a/CourseApp/Hero.cs +++ b/CourseApp/Hero.cs @@ -2,52 +2,19 @@ namespace CourseApp { - public class Hero + public class Hero : Character { - private double level; - public Hero() : this("No role", 0, true) { } public Hero(string role, double level, bool attack) + : base(role, level, attack) { - Role = role; - Level = level; - Attack = attack; - } - - public string Role { get; set; } - - public double Level - { - get - { - return this.level; - } - - set - { - if (value >= 0 && value < 20) - { - this.level = value; - } - else - { - throw new Exception("Enter correct level"); - } - } - } - - public bool Attack { get; set; } - - public bool CanShoot - { - get { return this.Attack; } } - public string Shoot(bool canShoot) + public override string Shoot(bool canShoot) { if (canShoot == true) { @@ -64,7 +31,7 @@ public override string ToString() return $"Hero-{Role}, {Level}, {Attack}"; } - public string NumShoot(int shot) + public override string NumShoot(int shot) { return $"{Role} made of {shot} shots!"; } diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index b604f47..f09c1a7 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -40,6 +40,12 @@ public static List TaskB( public static void Main(string[] args) { + var characters = new Character[] { new Hero(), new Enemy() }; + for (int i = 0; i < 2; i++) + { + Console.WriteLine(characters[i].Shoot(true)); + } + Console.WriteLine(MyFunction(0.3)); List taskA = TaskA(0.26, 0.66, 0.08); foreach (var item in taskA) @@ -58,6 +64,9 @@ public static void Main(string[] args) { Console.WriteLine($"y={item}"); } + + var countAge = new AgeCounter(); + Console.WriteLine(countAge.CountAge(20, 10, 2010)); } } } From 5edbc3af68d5e299660bba9d7fce7325b2d41c91 Mon Sep 17 00:00:00 2001 From: Dmitry-ops <52451095+Dmitry-ops@users.noreply.github.com> Date: Mon, 6 Jan 2020 16:40:56 +0300 Subject: [PATCH 21/25] 1 --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 3d63af4..8fb7e4a 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -11,7 +11,7 @@ - ll + From ee567722b0b1011d4f820b4763cc93eaae3f1a69 Mon Sep 17 00:00:00 2001 From: Dmitry-ops <52451095+Dmitry-ops@users.noreply.github.com> Date: Thu, 9 Jan 2020 17:31:03 +0300 Subject: [PATCH 22/25] RpG --- Game | 1 + Tprogramming_147_2019 | 1 + 2 files changed, 2 insertions(+) create mode 160000 Game create mode 160000 Tprogramming_147_2019 diff --git a/Game b/Game new file mode 160000 index 0000000..804eae3 --- /dev/null +++ b/Game @@ -0,0 +1 @@ +Subproject commit 804eae35035d5b5a120c559f8598791646de2df0 diff --git a/Tprogramming_147_2019 b/Tprogramming_147_2019 new file mode 160000 index 0000000..f41e442 --- /dev/null +++ b/Tprogramming_147_2019 @@ -0,0 +1 @@ +Subproject commit f41e4420f50c010f3c3841a650b7a290ea8adfbe From 046fa829028ed62c5d208e85fe9d80bf37f3207c Mon Sep 17 00:00:00 2001 From: Dmitry-ops <52451095+Dmitry-ops@users.noreply.github.com> Date: Thu, 9 Jan 2020 17:44:30 +0300 Subject: [PATCH 23/25] RpG v2 --- Tprogramming_147_2019 | 1 - 1 file changed, 1 deletion(-) delete mode 160000 Tprogramming_147_2019 diff --git a/Tprogramming_147_2019 b/Tprogramming_147_2019 deleted file mode 160000 index f41e442..0000000 --- a/Tprogramming_147_2019 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f41e4420f50c010f3c3841a650b7a290ea8adfbe From b169fb6b21850c78890c6811268050c4a725604d Mon Sep 17 00:00:00 2001 From: Dmitry-ops <52451095+Dmitry-ops@users.noreply.github.com> Date: Thu, 9 Jan 2020 17:52:13 +0300 Subject: [PATCH 24/25] delete --- Game | 1 - 1 file changed, 1 deletion(-) delete mode 160000 Game diff --git a/Game b/Game deleted file mode 160000 index 804eae3..0000000 --- a/Game +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 804eae35035d5b5a120c559f8598791646de2df0 From b06ea6a06f9b274b12747b97717bbcc1f76c69d0 Mon Sep 17 00:00:00 2001 From: Dmitry-ops <52451095+Dmitry-ops@users.noreply.github.com> Date: Thu, 9 Jan 2020 17:55:24 +0300 Subject: [PATCH 25/25] RpG v3 --- Game/Archer.cs | 24 +++++++ Game/Fight.cs | 171 ++++++++++++++++++++++++++++++++++++++++++++++++ Game/Game.cs | 46 +++++++++++++ Game/Hero.cs | 65 ++++++++++++++++++ Game/Knight.cs | 21 ++++++ Game/Logger.cs | 61 +++++++++++++++++ Game/Mage.cs | 23 +++++++ Game/Program.cs | 25 +++++++ Game/RPG.csproj | 8 +++ 9 files changed, 444 insertions(+) create mode 100644 Game/Archer.cs create mode 100644 Game/Fight.cs create mode 100644 Game/Game.cs create mode 100644 Game/Hero.cs create mode 100644 Game/Knight.cs create mode 100644 Game/Logger.cs create mode 100644 Game/Mage.cs create mode 100644 Game/Program.cs create mode 100644 Game/RPG.csproj diff --git a/Game/Archer.cs b/Game/Archer.cs new file mode 100644 index 0000000..ca62a62 --- /dev/null +++ b/Game/Archer.cs @@ -0,0 +1,24 @@ +using System; + +namespace RPG +{ + public class Archer : Hero + { + Random random = new Random(); + + public Archer() + : base() + { + heroClass = "Archer"; + skillName = "Fire arrows"; + } + + public override int Skill() + { + bufName = "Fire arrows"; + buf = true; + bufDamage = 5; + return 0; + } + } +} diff --git a/Game/Fight.cs b/Game/Fight.cs new file mode 100644 index 0000000..9af65fa --- /dev/null +++ b/Game/Fight.cs @@ -0,0 +1,171 @@ +using System; +using System.Collections.Generic; + +namespace RPG +{ + public struct Fight + { + public Hero hero1; + public Hero hero2; + } + + public class Fights + { + + static Logger logger = new Logger(); + static Random rnd = new Random(); + static List fight = new List(); + static int rounds = 0; + + static void CreateFights() + { + while (Game.heroes.Count > 1) + { + int k = rnd.Next(0, Game.heroes.Count - 1); + Fight fights = new Fight(); + fights.hero1 = Game.heroes[k]; + Game.heroes.RemoveAt(k); + + k = rnd.Next(0, Game.heroes.Count); + fights.hero2 = Game.heroes[k]; + Game.heroes.RemoveAt(k); + + fight.Add(fights); + } + } + + static void Atack(Hero attacking, Hero attacked) + { + int damage; + + if(attacking.buf) + { + damage = attacking.Atack(); + logger.Atack(attacking, attacked, damage); + attacked.GetDamage(damage + attacking.bufDamage); + } + else + { + damage = attacking.Atack(); + logger.Atack(attacking, attacked, damage); + attacked.GetDamage(damage); + } + } + + static void Skill(Hero attacking, Hero attacked) + { + int damage; + + if(attacking.buf || attacking.sleepTime > 0) + { + Atack(attacking, attacked); + } + else + { + damage = attacking.Skill(); + logger.Skill(attacking, attacked, attacking.skillName, damage); + attacked.GetDamage(damage); + } + } + + static void Win(Hero winner, Hero loser) + { + winner.sleepTime = 0; + winner.buf = false; + Game.heroes.Add(winner); + logger.Win(winner); + logger.Death(loser); + } + + public static void Fight() + { + CreateFights(); + int i = rnd.Next(0, fight.Count); + Hero hero1 = fight[i].hero1; + Hero hero2 = fight[i].hero2; + fight.RemoveAt(i); + + int turn = rnd.Next(0, 1); + rounds++; + Console.WriteLine("========="); + Console.WriteLine($"Кон №{rounds}\n"); + while (true) + { + + if(turn == 0) + { + if(hero2.sleepTime == 0) + { + if(rnd.Next(0,10) > 6) + { + Skill(hero1, hero2); + } + else + { + Atack(hero1, hero2); + } + } + else + { + logger.Sleep(hero1); + hero2.sleepTime--; + } + + if(hero2.Health <= 0) + { + Win(hero1, hero2); + if(fight.Count == 0) + { + break; + } + + i = rnd.Next(0, fight.Count); + hero1 = fight[i].hero1; + hero2 = fight[i].hero2; + fight.RemoveAt(i); + } + + + + turn = 1; + } + else + { + if(hero1.sleepTime == 0) + { + if(rnd.Next(0,10) > 6) + { + Skill(hero2, hero1); + } + else + { + Atack(hero2, hero1); + } + } + else + { + logger.Sleep(hero2); + hero1.sleepTime--; + } + + if(hero1.Health <= 0) + { + Win(hero2, hero1); + if(fight.Count == 0) + { + break; + } + i = rnd.Next(0, fight.Count); + hero1 = fight[i].hero1; + hero2 = fight[i].hero2; + fight.RemoveAt(i); + } + + + + turn = 0; + } + } + } + } +} diff --git a/Game/Game.cs b/Game/Game.cs new file mode 100644 index 0000000..de8ec80 --- /dev/null +++ b/Game/Game.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; + +namespace RPG +{ + public class Game + { + public static List heroes = new List(); + Random rnd = new Random(); + + public void Start(int numOfHeroes) + { + CreateHeroes(numOfHeroes); + while(heroes.Count != 1) + { + Fights.Fight(); + } + + Console.WriteLine($"\nWinner - {heroes[0].Name} ({heroes[0].heroClass})"); + } + + public void CreateHeroes(int numOfHeroes) + { + + while(numOfHeroes > 0) + { + switch(rnd.Next(0,3)) + { + case 0: + heroes.Add(new Archer()); + break; + case 1: + heroes.Add(new Knight()); + break; + case 2: + heroes.Add(new Mage()); + break; + default: + heroes.Add(new Mage()); + break; + } + numOfHeroes--; + } + } + } +} diff --git a/Game/Hero.cs b/Game/Hero.cs new file mode 100644 index 0000000..358cfe0 --- /dev/null +++ b/Game/Hero.cs @@ -0,0 +1,65 @@ +using System; + +namespace RPG +{ + public class Hero + { + Random random = new Random(); + public string heroClass; + public string skillName; + public bool buf = false; + public string bufName; + public int bufDamage; + public int sleepTime = 0; + public int maxHealth; + + public Hero() + { + Health = random.Next(100,200); + maxHealth = Health; + Name = Names[random.Next(0,20)]; + Strength = random.Next(10,50); + } + + public static string[] Names = new string[20]{ + "Kelley", + "Winifred", + "Michael", + "Christina", + "Lionel", + "Ami", + "Jacob", + "Della", + "Nicholas", + "Rose", + "Edward", + "Caroline", + "Clyde", + "Tiffany", + "Leo", + "Marion", + "Stephen", + "Maryann", + "Virgil", + "Betty" + }; + public string Name { get; protected set; } + public int Strength { get; protected set; } + public int Health { get; set; } + + public virtual int Skill() + { + return 0; + } + + public int Atack() + { + return random.Next(1, Strength); + } + + public void GetDamage(int damage) + { + Health -= damage; + } + } +} diff --git a/Game/Knight.cs b/Game/Knight.cs new file mode 100644 index 0000000..b3bccb7 --- /dev/null +++ b/Game/Knight.cs @@ -0,0 +1,21 @@ +using System; + +namespace RPG +{ + public class Knight : Hero + { + Random random = new Random(); + + public Knight() + : base() + { + heroClass = "Knight"; + skillName = "Retaliation strike"; + } + + public override int Skill() + { + return (int)Math.Floor(Strength * 1.5); + } + } +} diff --git a/Game/Logger.cs b/Game/Logger.cs new file mode 100644 index 0000000..a626ebe --- /dev/null +++ b/Game/Logger.cs @@ -0,0 +1,61 @@ +using System; + +namespace RPG +{ + class Logger + { + public void Atack(Hero hero1, Hero hero2, int damage) + { + Console.Write($"{hero1.Name} ({hero1.heroClass}) hit {hero2.Name} ({hero2.heroClass}) and deals {damage} damage"); + + if(hero1.buf) + { + Console.WriteLine($" Additional damage of {hero1.bufDamage} units due to the amplification \"{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.heroClass}) used skill \"{skillName}\" and stuns {hero2.Name} ({hero2.heroClass}) for {hero1.sleepTime} turns."); + } + else if(hero1.buf && damage == 0) + { + Console.WriteLine($"{hero1.Name} ({hero1.heroClass}) used buf \"{skillName}\""); + } + else + { + Console.Write($"{hero1.Name} ({hero1.heroClass}) used skill \"{skillName}\" and deals {hero2.Name} ({hero2.heroClass}) {damage} damage."); + + if(hero1.buf) + { + Console.WriteLine($" Additional damage of {hero1.bufDamage} units due to the amplification \"{hero1.bufName}\"."); + } + else + { + Console.WriteLine(); + } + } + } + + public void Sleep(Hero hero) + { + Console.WriteLine($"{hero.Name} ({hero.heroClass}) stunned and skips turn."); + } + + public void Win(Hero hero) + { + Console.WriteLine($"{hero.Name} ({hero.heroClass}) won!"); + } + + public void Death(Hero hero) + { + Console.WriteLine($"{hero.Name} ({hero.heroClass}) is dead.\n"); + } + } +} diff --git a/Game/Mage.cs b/Game/Mage.cs new file mode 100644 index 0000000..ef2f9e5 --- /dev/null +++ b/Game/Mage.cs @@ -0,0 +1,23 @@ +using System; + +namespace RPG +{ + public class Mage : Hero + { + Random random = new Random(); + + public Mage() + : base() + { + heroClass = "Mage"; + skillName = "Fascination"; + } + + public override int Skill() + { + + sleepTime = 2; + return 0; + } + } +} diff --git a/Game/Program.cs b/Game/Program.cs new file mode 100644 index 0000000..98c0d79 --- /dev/null +++ b/Game/Program.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; + +namespace RPG +{ + class Program + { + static void Main(string[] args) + { + Game game = new Game(); + Console.Write("Enter the number of heroes: "); + + int numOfHeroes = Int32.Parse(Console.ReadLine()); + + if(numOfHeroes % 2 != 0) + { + numOfHeroes += 1; + } + + game.Start(numOfHeroes); + + Console.ReadKey(); + } + } +} diff --git a/Game/RPG.csproj b/Game/RPG.csproj new file mode 100644 index 0000000..958d2f1 --- /dev/null +++ b/Game/RPG.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.0 + + +