diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml new file mode 100644 index 0000000..22cc4eb --- /dev/null +++ b/.github/workflows/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/.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/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/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index fdc46f5..c4d7cda 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -1,14 +1,50 @@ using System; +using System.Collections.Generic; using Xunit; namespace CourseApp.Tests { public class DemoTest { + [Theory] + [InlineData(0.2, 45.024015896718936)] + [InlineData(0.3, 18.87433958817845)] + public void TestMyFunction(double x, double exp) + { + Assert.Equal(Program.MyFunction(x), exp, 3); + } + + [Fact] + + 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 Test1() { Assert.True(true); } + + [Fact] + public void TestTaskB() + { + 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.Tests/HeroTest.cs b/CourseApp.Tests/HeroTest.cs new file mode 100644 index 0000000..2ca18f4 --- /dev/null +++ b/CourseApp.Tests/HeroTest.cs @@ -0,0 +1,63 @@ +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); + } + } + + [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.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/.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 0000000..95f4e94 Binary files /dev/null and "b/CourseApp/.vscode/CourseApp - \320\257\321\200\320\273\321\213\320\272.lnk" differ 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/AgeCounter.cs b/CourseApp/AgeCounter.cs new file mode 100644 index 0000000..e39c408 --- /dev/null +++ b/CourseApp/AgeCounter.cs @@ -0,0 +1,51 @@ +using System; + +namespace CourseApp +{ + public class AgeCounter + { + private DateTime now = DateTime.Today; + + public string CountAge(int day, int month, int year) + { + var birthday = new DateTime(year, month, day); + var today = DateTime.Today; + + 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} дней"; + } + } + + 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/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/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 new file mode 100644 index 0000000..4cae8a6 --- /dev/null +++ b/CourseApp/Hero.cs @@ -0,0 +1,39 @@ +using System; + +namespace CourseApp +{ + public class Hero : Character + { + public Hero() + : this("No role", 0, true) + { + } + + public Hero(string role, double level, bool attack) + : base(role, level, attack) + { + } + + public override 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 override string NumShoot(int shot) + { + return $"{Role} made of {shot} shots!"; + } + } +} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 248bbe4..f09c1a7 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,13 +1,72 @@ -using System; +using System.Collections; +using System.Collections.Generic; +using System; namespace CourseApp { public class Program { + public static double MyFunction(double x) + { + var y = Math.Pow(Math.Pow(Math.Asin(x), 2) + Math.Pow(Math.Acos(x), 4), 3); + return y; + } + + public static List TaskA( + double xn, + double xk, + double dx) + { + List y = new List(); + for (var x = xn; x < xk; x += dx) + { + y.Add(MyFunction(x)); + } + + return y; + } + + public static List TaskB( + List x) + { + List y = new List(5); + foreach (double i in x) + { + y.Add(MyFunction(i)); + } + + return y; + } + public static void Main(string[] args) { - Console.WriteLine("Hello World!"); - Console.ReadLine(); + 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) + { + Console.WriteLine($"y={item}"); + } + + 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]}"); + } + + foreach (var item in taskB) + { + Console.WriteLine($"y={item}"); + } + + var countAge = new AgeCounter(); + Console.WriteLine(countAge.CountAge(20, 10, 2010)); } } } 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 + + + diff --git a/README.md b/README.md index 028d53d..1a204a4 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ +Nazarov Dmitrij # Tprogramming_147_2019 -Nazarov Dmitrij \ No newline at end of file