diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 22cc4ebc..878105a5 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -6,13 +6,17 @@ jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + dotnet: [ '2.1', '3.1.x', '5.0.x' ] + steps: - uses: actions/checkout@v1 - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 2.1.802 + dotnet-version: ${{ matrix.dotnet-version }} - name: Build with dotnet run: | cd CourseApp diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..ef74c129 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/CourseApp/bin/Debug/netcoreapp2.1/CourseApp.dll", + "args": [], + "cwd": "${workspaceFolder}/CourseApp", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..7dea23c5 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/CourseApp/CourseApp.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/CourseApp/CourseApp.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/CourseApp/CourseApp.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 8dc39cc2..158d6300 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1 + netcoreapp5 True false diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs deleted file mode 100644 index cf7cbb14..00000000 --- a/CourseApp.Tests/DemoTest.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace CourseApp.Tests -{ - using Xunit; - - public class DemoTest - { - [Fact] - public void Test1() - { - Assert.True(true); - } - } -} diff --git a/CourseApp.Tests/PistolTest.cs b/CourseApp.Tests/PistolTest.cs new file mode 100644 index 00000000..24db2291 --- /dev/null +++ b/CourseApp.Tests/PistolTest.cs @@ -0,0 +1,18 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class PistolTest + { + [Theory] + [InlineData( 1, 0)] + [InlineData( 2, 1)] + public void Test(int a, int exp) + { + Pistol actualResult = new Pistol(" ", 0, a); + actualResult.Shot(); + Assert.Equal(exp, actualResult.Clip); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/WeaponTest.cs b/CourseApp.Tests/WeaponTest.cs new file mode 100644 index 00000000..32f8e2a8 --- /dev/null +++ b/CourseApp.Tests/WeaponTest.cs @@ -0,0 +1,46 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class WeaponTest + { + [Theory] + [InlineData("Name", "Name")] + [InlineData(" ", " ")] + public void TestModel(string a, string exp) + { + Pistol actualResult = new Pistol(a); + Assert.Equal(exp, actualResult.Model); + } + + [Theory] + [InlineData(9, 9)] + [InlineData(-9, -9)] + public void TestCaliber(int a, int exp) + { + Pistol actualResult = new Pistol(" ", a); + Assert.Equal(exp, actualResult.Caliber); + } + + [Theory] + [InlineData(0, 0)] + [InlineData(-1, -1)] + [InlineData(8, 8)] + public void TestAge(int a, int exp) + { + Pistol actualResult = new Pistol(" ", 0, a); + Assert.Equal(exp, actualResult.Clip); + } + + [Theory] + [InlineData("Name", 9, 5, "model: Name caliber: 9 Clip: 5")] + [InlineData( " ", 0, -7, "model: caliber: 0 Clip: -7")] + public void TesteEditInf(string n, int b, int a, string exp) + { + Pistol actualResult = new Pistol(); + actualResult.EditInf(n, b, a); + Assert.Equal(exp, actualResult.ToString()); + } + } +} \ No newline at end of file diff --git a/CourseApp/.vscode/launch.json b/CourseApp/.vscode/launch.json index 208ea3ac..ef6f337e 100644 --- a/CourseApp/.vscode/launch.json +++ b/CourseApp/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "build", - "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/CourseApp.dll", + "program": "${workspaceFolder}/bin/Debug/netcoreapp5/CourseApp.dll", "args": [], "cwd": "${workspaceFolder}", "console": "internalConsole", diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index 260260d3..20032b88 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.1 + netcoreapp5 True diff --git a/CourseApp/Interfaces/IPlayer.cs b/CourseApp/Interfaces/IPlayer.cs new file mode 100644 index 00000000..3d9b4d8e --- /dev/null +++ b/CourseApp/Interfaces/IPlayer.cs @@ -0,0 +1,11 @@ +namespace CourseApp +{ + public interface IPlayer + { + string Name { get; set; } + + double Health { get; set; } + + int Strength { get; set; } + } +} \ No newline at end of file diff --git a/CourseApp/Pistol.cs b/CourseApp/Pistol.cs new file mode 100644 index 00000000..4885a6a7 --- /dev/null +++ b/CourseApp/Pistol.cs @@ -0,0 +1,33 @@ +using System; + +namespace CourseApp +{ + public class Pistol : Weapon + { + public Pistol() + : base () + { + } + + public Pistol(string newmodel) + : base(newmodel) + { + } + + public Pistol(string newmodel, int newcaliber) + : base(newmodel, newcaliber) + { + } + + public Pistol(string newmodel, int newcaliber, int newClip) + : base (newmodel, newcaliber, newClip) + { + } + + public override string Shot() + { + Clip--; + return "Sound"; + } + } +} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 51d2a96d..7ef85284 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,13 +1,17 @@ namespace CourseApp { - using System; - - public class Program - { - public static void Main(string[] args) - { - Console.WriteLine($"Hello world"); + using System; + using System.Collections.Generic; + + public class Program + { + public static void Main(string[] args) { + int participants = 0; + Game start = new Game(); + participants = start.StartTheTournament(participants); + Arena arena = new Arena(); + arena.Tour(participants); Console.ReadLine(); - } - } -} + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGsaga/Archer.cs b/CourseApp/RPGsaga/Archer.cs new file mode 100644 index 00000000..6025de5a --- /dev/null +++ b/CourseApp/RPGsaga/Archer.cs @@ -0,0 +1,26 @@ +namespace CourseApp +{ + using System; + + public class Archer : Player + { + public Archer(string name, double health, int strength) + : base(name, health, strength) + { + ClassPlayer = "Лучник"; + UltimateName = "Ядовитая стрела"; + } + + public override int Ultimate(Player player, Player rival) + { + UltimateDamage = 2; + Logger.LoggerOutput($"{ClassPlayer} {Name} использовал особую способность {UltimateName}!"); + return Strength += UltimateDamage; + } + + public override string InfoOutput() + { + return $"Призвание: {ClassPlayer} ; Имя бойца: {Name} ; Здоровье бойца: {Health} ; Сила бойца {Strength}"; + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGsaga/Knight.cs b/CourseApp/RPGsaga/Knight.cs new file mode 100644 index 00000000..e36e63df --- /dev/null +++ b/CourseApp/RPGsaga/Knight.cs @@ -0,0 +1,25 @@ +namespace CourseApp +{ + using System; + + public class Knight : Player + { + public Knight(string name, double health, int strength) + : base(name, health, strength) + { + ClassPlayer = "Рыцарь"; + UltimateName = "Удар"; + } + + public override int Ultimate(Player player, Player rival) + { + Logger.LoggerOutput($"{ClassPlayer} {Name} использовал особую способность {UltimateName}!"); + return Strength = (int)(Strength * 1.3); + } + + public override string InfoOutput() + { + return $"Призвание: {ClassPlayer} ; Имя бойца: {Name} ; Здоровье бойца: {Health} ; Сила бойца {Strength}"; + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGsaga/Logger.cs b/CourseApp/RPGsaga/Logger.cs new file mode 100644 index 00000000..666c778c --- /dev/null +++ b/CourseApp/RPGsaga/Logger.cs @@ -0,0 +1,12 @@ +namespace CourseApp +{ + using System; + + public class Logger + { + public static void LoggerOutput(string logger) + { + Console.WriteLine(logger); + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGsaga/Player.cs b/CourseApp/RPGsaga/Player.cs new file mode 100644 index 00000000..75137309 --- /dev/null +++ b/CourseApp/RPGsaga/Player.cs @@ -0,0 +1,83 @@ +namespace CourseApp +{ + using System; + + public abstract class Player : IPlayer + { + public Player(string name, double health, int strength) + { + Name = name; + Health = health; + Strength = strength; + Afk = 0; + Effect = false; + DefaultHealth = health; + } + + public int Afk { get; set; } + + public double DefaultHealth { get; set; } + + public string Name { get; set; } + + public string ClassPlayer { get; set; } + + public bool Effect { get; set; } + + public string UltimateName { get; set; } + + public int UltimateDamage { get; set; } + + public int DamageInfo { get; set; } + + public double Health { get; set; } + + public int Strength { get; set; } + + public virtual int Ultimate(Player player, Player rival) + { + return 0; + } + + public int AtTheAttackWarrior(Player warrior, Player warriorRival) + { + if (warrior.Effect) + { + warrior.Effect = false; + return DamageInfo = warrior.Ultimate(warrior, warriorRival); + } + else + { + return DamageInfo = Strength; + } + } + + public int AtTheAttackWarriorRival(Player warrior, Player warriorRival) + { + if (warriorRival.Effect) + { + warriorRival.Effect = false; + return DamageInfo = warriorRival.Ultimate(warrior, warriorRival); + } + else + { + return DamageInfo = Strength; + } + } + + public virtual string InfoOutput() + { + return $"Имя бойца: {Name} ; Здоровье бойца: {Health} ; Сила бойца: {Strength}"; + } + + public void GetDamage(int damage) + { + Health -= damage; + } + + public void ResetHealth() + { + Health = DefaultHealth; + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGsaga/Wizzard.cs b/CourseApp/RPGsaga/Wizzard.cs new file mode 100644 index 00000000..56724135 --- /dev/null +++ b/CourseApp/RPGsaga/Wizzard.cs @@ -0,0 +1,36 @@ +namespace CourseApp +{ + using System; + + public class Wizard : Player + { + public Wizard(string name, double health, int strength) + : base(name, health, strength) + { + ClassPlayer = "Волшебник"; + UltimateName = "Волшебный ульт"; + } + + public override int Ultimate(Player player, Player rival) + { + if (player.Effect) + { + player.Afk = 1; + rival.Afk = 2; + } + else if (rival.Effect) + { + player.Afk = 2; + rival.Afk = 1; + } + + Logger.LoggerOutput($"{ClassPlayer} {Name} особую способность {UltimateName}!"); + return 0; + } + + public override string InfoOutput() + { + return $"Призвание: {ClassPlayer} ; Имя бойца: {Name} ; Здоровье бойца: {Health} ; Сила бойца {Strength}"; + } + } +} \ No newline at end of file diff --git a/CourseApp/Tour/Arena.cs b/CourseApp/Tour/Arena.cs new file mode 100644 index 00000000..c567498b --- /dev/null +++ b/CourseApp/Tour/Arena.cs @@ -0,0 +1,100 @@ +namespace CourseApp +{ + using System; + using System.Collections.Generic; + + public class Arena + { + private readonly Random random = new Random(); + private Logger logger = new Logger(); + private List warriors = new List(); + private List winners = new List(); + private Participants list = new Participants(); + + + private int round = 1; + private int battle = 1; + + private Fight fight = new Fight(); + + public void Tour(int participants) + { + warriors = list.AddAtList(participants); + + Logger.LoggerOutput("Участники предстоящего турнира:"); + foreach (Player item in warriors) + { + Logger.LoggerOutput($"{item.ClassPlayer} {item.Name}"); + } + + Logger.LoggerOutput("================================================================="); + Logger.LoggerOutput($"Тур {round++}-й"); + while (warriors.Count + winners.Count > 1) + { + if (warriors.Count >= 2) + { + int randomWarriorFirst = random.Next(0, warriors.Count); + int randomWarriorSecond = random.Next(0, warriors.Count); + while (randomWarriorFirst == randomWarriorSecond) + { + randomWarriorSecond = random.Next(0, warriors.Count); + } + + Player warrior = warriors[randomWarriorFirst]; + Player warriorRival = warriors[randomWarriorSecond]; + Logger.LoggerOutput($"И {battle++}-й бой! {warrior.ClassPlayer} {warrior.Name} VS {warriorRival.ClassPlayer} {warriorRival.Name} \n"); + fight.Zaruba(warrior, warriorRival); + Console.WriteLine("\n"); + if (warrior.Health <= 0) + { + Logger.LoggerOutput($"{warrior.ClassPlayer} {warrior.Name} терпит поражение и выбывает турнира!"); + warriorRival.ResetHealth(); + warriors.Remove(warrior); + warriors.Remove(warriorRival); + winners.Add(warriorRival); + } + else + { + Logger.LoggerOutput($"{warriorRival.ClassPlayer} {warriorRival.Name} терпит поражение и выбывает турнира!"); + warrior.ResetHealth(); + warriors.Remove(warrior); + warriors.Remove(warriorRival); + winners.Add(warrior); + } + } + + if ((winners.Count >= 2) && (warriors.Count == 0)) + { + int randomWarriorFirst = random.Next(0, winners.Count); + int randomWarriorSecond = random.Next(0, winners.Count); + while (randomWarriorFirst == randomWarriorSecond) + { + randomWarriorSecond = random.Next(0, winners.Count); + } + + Logger.LoggerOutput("================================================================="); + Logger.LoggerOutput($"Тур {round++}-й"); + Player warrior = winners[randomWarriorFirst]; + Player warriorRival = winners[randomWarriorSecond]; + Logger.LoggerOutput($"И {battle++}-й бой! {warrior.ClassPlayer} {warrior.Name} VS {warriorRival.ClassPlayer} {warriorRival.Name} \n"); + fight.Zaruba(warrior, warriorRival); + if (warrior.Health <= 0) + { + Logger.LoggerOutput($"{warrior.ClassPlayer} {warrior.Name} терпит поражение и выбывает из турнира!"); + warriorRival.ResetHealth(); + winners.Remove(warrior); + } + else + { + Logger.LoggerOutput($"{warriorRival.ClassPlayer} {warriorRival.Name} терпит поражение и выбывает из турнира!"); + warrior.ResetHealth(); + winners.Remove(warriorRival); + } + } + } + + Logger.LoggerOutput($"\nПобедитель турнира - {winners[0].ClassPlayer} {winners[0].Name}! =)"); + Logger.LoggerOutput("Всем спасибо, всем пока!"); + } + } +} \ No newline at end of file diff --git a/CourseApp/Tour/Fight.cs b/CourseApp/Tour/Fight.cs new file mode 100644 index 00000000..1dc8f173 --- /dev/null +++ b/CourseApp/Tour/Fight.cs @@ -0,0 +1,56 @@ +namespace CourseApp +{ + using System; + using System.Collections.Generic; + + public class Fight + { + private readonly Random random = new Random(); + private int counterOne = 0; + private int counterTwo = 0; + + public Tuple Zaruba(Player warrior, Player warriorRival) + { + while ((warrior.Health > 0) && (warriorRival.Health > 0)) + { + if ((random.Next(1, 5) == 1) && (warrior.Effect == false) && (counterOne != 1)) + { + counterOne = 1; + warrior.Effect = true; + } + + if ((random.Next(1, 5) == 2) && (warriorRival.Effect == false) && (counterTwo != 2)) + { + counterTwo = 2; + warriorRival.Effect = true; + } + + if ((warrior.Afk > 0) && (warrior.Health > 0)) + { + Logger.LoggerOutput($"{warrior.Name} не может нанести удар и пропускает ход!"); + warrior.Afk--; + } + else if (warrior.Health > 0) + { + warriorRival.GetDamage(warrior.AtTheAttackWarrior(warrior, warriorRival)); + Logger.LoggerOutput($"{warriorRival.Name} теряет {warrior.DamageInfo} хп от удара {warrior.Name}!"); + } + + if ((warriorRival.Afk > 0) && (warriorRival.Health > 0)) + { + Logger.LoggerOutput($"{warriorRival.Name} не может нанести удар и пропускает ход!"); + warriorRival.Afk--; + } + else if (warriorRival.Health > 0) + { + warrior.GetDamage(warriorRival.AtTheAttackWarriorRival(warrior, warriorRival)); + Logger.LoggerOutput($"{warrior.Name} теряет {warriorRival.DamageInfo} хп от удара {warriorRival.Name}!"); + } + } + + counterOne = 0; + counterTwo = 0; + return new Tuple(warrior, warriorRival); + } + } +} \ No newline at end of file diff --git a/CourseApp/Tour/Game.cs b/CourseApp/Tour/Game.cs new file mode 100644 index 00000000..a68041ee --- /dev/null +++ b/CourseApp/Tour/Game.cs @@ -0,0 +1,20 @@ +namespace CourseApp +{ + using System; + + public class Game + { + public int StartTheTournament(int tourname) + { + Logger.LoggerOutput("Введите количество участников турнира: "); + tourname = Convert.ToInt32(Console.ReadLine()); + while ((tourname % 2 != 0) && (tourname > 0)) + { + Logger.LoggerOutput("Введите корректное количество участников турнира(кратное двум и больше нуля!): "); + tourname = Convert.ToInt32(Console.ReadLine()); + } + + return tourname; + } + } +} \ No newline at end of file diff --git a/CourseApp/Tour/Participants.cs b/CourseApp/Tour/Participants.cs new file mode 100644 index 00000000..26011cb6 --- /dev/null +++ b/CourseApp/Tour/Participants.cs @@ -0,0 +1,40 @@ +namespace CourseApp +{ + using System; + using System.Collections.Generic; + + public class Participants + { + private readonly Random random = new Random(); + private List arrayOfName = new List() + { + "Сергор", "Тана", "Миваль", "Натали", "Валек", "Мэнни", "Шилли", "Фарила", "Мара", "Зашеир", "Хасеир", + "Асеир", "Гузлик", "Линкольн", "Зашеир", "Ригард", "Мехмед", "Незуко", "Танджиро", "Субару", "Рэм", + "Аот", "Урхур", "Нефис", "Азар-Де", "Мара", "Ромеро", "Хуектория", "Додик", "Эссвелэ", "Дима", + "Румян", "Кто-то", + }; + + private List warriors = new List(); + + public List AddAtList(int participants) + { + while (warriors.Count < participants) + { + switch (random.Next(0, 3)) + { + case 0: + warriors.Add(new Archer(arrayOfName[random.Next(0, 20)], random.Next(100, 130), random.Next(10, 20))); + break; + case 1: + warriors.Add(new Knight(arrayOfName[random.Next(0, 20)], random.Next(100, 130), random.Next(10, 20))); + break; + case 2: + warriors.Add(new Wizard(arrayOfName[random.Next(0, 20)], random.Next(100, 130), random.Next(10, 20))); + break; + } + } + + return warriors; + } + } +} \ No newline at end of file diff --git a/CourseApp/Weapon.cs b/CourseApp/Weapon.cs new file mode 100644 index 00000000..3e8d046c --- /dev/null +++ b/CourseApp/Weapon.cs @@ -0,0 +1,85 @@ +using System; + +namespace CourseApp +{ + public abstract class Weapon + { + private string model; + private int caliber; + + public Weapon() + : this (" ", 0, 0) + { + } + + public Weapon(string newmodel) + : this(newmodel, 0, 0) + { + } + + public Weapon(string newmodel, int newcaliber) + : this(newmodel, newcaliber, 0) + { + } + + public Weapon(string newmodel, int newcaliber, int newClip) + { + this.model = newmodel; + this.caliber = newcaliber; + this.Clip = newClip; + } + + public virtual string Model + { + get + { + return model; + } + + set + { + if (value.Length < 3) + { + model = "Неизвестно"; + } + else + { + model = value; + } + } + } + + public virtual int Caliber + { + get + { + return caliber; + } + + set + { + if (value < 0) + { + caliber = 0; + } + else + { + caliber = value; + } + } + } + + public virtual int Clip { get; set; } + + public override string ToString() => $"model: {model} caliber: {caliber} Clip: {Clip}"; + + public virtual void EditInf(string newmodel, int newcaliber, int newClip) + { + model = newmodel; + caliber = newcaliber; + Clip = newClip; + } + + public abstract string Shot(); + } +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 5794e3fc..b2a2650a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build-env +FROM mcr.microsoft.com/dotnet/core/sdk:5.0 AS build-env WORKDIR /app # Copy csproj and restore as distinct layers @@ -11,7 +11,7 @@ COPY ./_stylecop/ /_stylecop/ RUN dotnet publish -c Release -o out # Build runtime image -FROM mcr.microsoft.com/dotnet/core/aspnet:2.1 +FROM mcr.microsoft.com/dotnet/core/aspnet:5.0 WORKDIR /app COPY --from=build-env /app/out . ENTRYPOINT ["dotnet", "CourseApp.dll"] \ No newline at end of file