From 11c5a6763ccbcf50356f2209de526fe0393721ff Mon Sep 17 00:00:00 2001 From: SellTheCat Date: Sat, 19 Nov 2022 15:12:35 +0300 Subject: [PATCH 1/3] Added RPGSaga, realize CharacterMultiplying --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp/Program.cs | 16 ++++- CourseApp/RPGSaga/Bowman.cs | 30 +++++++++ CourseApp/RPGSaga/CharFactory.cs | 19 ++++++ CourseApp/RPGSaga/GetName.cs | 17 +++++ CourseApp/RPGSaga/Knight.cs | 30 +++++++++ CourseApp/RPGSaga/MultiplyChars.cs | 28 ++++++++ CourseApp/RPGSaga/Player.cs | 93 ++++++++++++++++++++++++++ CourseApp/{ => Vehicles}/Car.cs | 2 +- CourseApp/{ => Vehicles}/Copter.cs | 6 +- CourseApp/{ => Vehicles}/Phone.cs | 2 +- CourseApp/{ => Vehicles}/Plane.cs | 2 +- CourseApp/{ => Vehicles}/Vehicle.cs | 2 +- 13 files changed, 239 insertions(+), 10 deletions(-) create mode 100644 CourseApp/RPGSaga/Bowman.cs create mode 100644 CourseApp/RPGSaga/CharFactory.cs create mode 100644 CourseApp/RPGSaga/GetName.cs create mode 100644 CourseApp/RPGSaga/Knight.cs create mode 100644 CourseApp/RPGSaga/MultiplyChars.cs create mode 100644 CourseApp/RPGSaga/Player.cs rename CourseApp/{ => Vehicles}/Car.cs (96%) rename CourseApp/{ => Vehicles}/Copter.cs (94%) rename CourseApp/{ => Vehicles}/Phone.cs (97%) rename CourseApp/{ => Vehicles}/Plane.cs (98%) rename CourseApp/{ => Vehicles}/Vehicle.cs (97%) diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index e43252f..a330a77 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -2,7 +2,7 @@ net6.0 - True + false false diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 5e6076a..c764a51 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -3,12 +3,24 @@ using System; using System.Collections.Generic; using System.Text; + using RPGSaga; public class Program { public static void Main(string[] args) { - var def = new Plane() { Speed = 1000, Height = 11000 }; + var artur = new Knight() { Name = "Артур", Maxhealth = 80, Power = 5 }; + artur.Greetings(); + artur.DealDamage(); + artur.VengStrike(); + var heros = new MultiplyChars(); + List twoheros = heros.CreateN(4); + foreach (var player in twoheros) + { + player.Greetings(); + } + + /* var def = new Plane() { Speed = 1000, Height = 11000 }; var ssj = new Copter() { Name = "SSJ100", Speed = 800, Diagonal = 8.2 }; var airbus = new Plane("Airbus", -1, 9500); var pt300 = new Copter("ПТ300", 800, 5000); @@ -18,7 +30,7 @@ public static void Main(string[] args) foreach (var vehicle in transport) { Console.WriteLine(vehicle.Display()); - } + } */ } } } \ No newline at end of file diff --git a/CourseApp/RPGSaga/Bowman.cs b/CourseApp/RPGSaga/Bowman.cs new file mode 100644 index 0000000..8fad822 --- /dev/null +++ b/CourseApp/RPGSaga/Bowman.cs @@ -0,0 +1,30 @@ +namespace RPGSaga +{ + using System; + using System.Collections.Generic; + using System.Text; + + public class Bowman : Player + { + public Bowman() + { + Name = "Лучник"; + Maxhealth = 50; + Power = 7; + } + + public Bowman(string name, double maxhealth, double power) + { + Name = name; + Maxhealth = maxhealth; + Power = power; + } + + public double Firearrows() + { + var damage = 0; + Console.WriteLine($"{Name} стреляет огненной стрелой"); + return damage; + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/CharFactory.cs b/CourseApp/RPGSaga/CharFactory.cs new file mode 100644 index 0000000..4c86243 --- /dev/null +++ b/CourseApp/RPGSaga/CharFactory.cs @@ -0,0 +1,19 @@ +namespace RPGSaga +{ + using System; + using System.Collections.Generic; + using System.Text; + + public class CharFactory + { + public Player CreateChar(string type, string name, double maxhealth, double power) + { + if (type == "Knight") + { + return new Knight(name, maxhealth, power); + } + + return new Bowman(name, maxhealth, power); + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/GetName.cs b/CourseApp/RPGSaga/GetName.cs new file mode 100644 index 0000000..818c82b --- /dev/null +++ b/CourseApp/RPGSaga/GetName.cs @@ -0,0 +1,17 @@ +namespace RPGSaga +{ + using System; + using System.Collections.Generic; + using System.Text; + + public class GetName + { + private List namelist = new List() { "Артур", "Ланселот", "Гавейн", "Мерлин", "Арагорн", "Боромир", "Гимли", "Леголас", "Робин" }; + + public string RandomName() + { + Random r = new Random(); + return namelist[r.Next(0, namelist.Count)]; + } + } +} diff --git a/CourseApp/RPGSaga/Knight.cs b/CourseApp/RPGSaga/Knight.cs new file mode 100644 index 0000000..802ec44 --- /dev/null +++ b/CourseApp/RPGSaga/Knight.cs @@ -0,0 +1,30 @@ +namespace RPGSaga +{ + using System; + using System.Collections.Generic; + using System.Text; + + public class Knight : Player + { + public Knight() + { + Name = "Рыцарь"; + Maxhealth = 80; + Power = 5; + } + + public Knight(string name, double maxhealth, double power) + { + Name = name; + Maxhealth = maxhealth; + Power = power; + } + + public double VengStrike() + { + var damage = Power * 1.3; + Console.WriteLine($"{Name} наносит {damage} урона"); + return damage; + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/MultiplyChars.cs b/CourseApp/RPGSaga/MultiplyChars.cs new file mode 100644 index 0000000..4acfc97 --- /dev/null +++ b/CourseApp/RPGSaga/MultiplyChars.cs @@ -0,0 +1,28 @@ +namespace RPGSaga +{ + using System; + using System.Collections.Generic; + using System.Text; + + public class MultiplyChars + { + private List heros; + + public List CreateN(int n) + { + heros = new List(); + var factory = new CharFactory(); + for (int i = 1; i <= n; i++) + { + Random r = new Random(); + double maxhealth = r.Next(1, 100); + double power = r.Next(1, 10); + var getname = new GetName(); + string name = getname.RandomName(); + heros.Add(factory.CreateChar("Bowman", name, maxhealth, power)); + } + + return heros; + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Player.cs b/CourseApp/RPGSaga/Player.cs new file mode 100644 index 0000000..93e45e0 --- /dev/null +++ b/CourseApp/RPGSaga/Player.cs @@ -0,0 +1,93 @@ +namespace RPGSaga +{ + using System; + using System.Collections.Generic; + using System.Text; + + public abstract class Player + { + private double maxhealth; + /* private double health; */ + private double power; + + public Player() + { + Name = "<Безымянный>"; + Maxhealth = 100; + Power = 1; + } + + public Player(string name, double maxhealth, double power) + { + Name = name; + Maxhealth = maxhealth; + Power = power; + } + + public string Name { get; set; } + + public double Maxhealth + { + get + { + return maxhealth; + } + + set + { + if (value > 0 && value <= 100) + { + maxhealth = value; + } + else + { + maxhealth = 50; + } + } + } + + public double Health + { + get + { + return maxhealth; + } + } + + public double Power + { + get + { + return power; + } + + set + { + if (value > 0 && value <= 10) + { + power = value; + } + else + { + power = 5; + } + } + } + + public void Greetings() + { + Console.WriteLine($"Игрок {Name} (здоровье {Maxhealth}, атака {Power}) готов к бою!"); + } + + public double DealDamage() + { + Console.WriteLine($"{Name} наносит {Power} урона"); + return Power; + } + +/* public double GetDamage() + { + Health = Health - damage + } */ + } +} \ No newline at end of file diff --git a/CourseApp/Car.cs b/CourseApp/Vehicles/Car.cs similarity index 96% rename from CourseApp/Car.cs rename to CourseApp/Vehicles/Car.cs index b78a30c..ae8f695 100644 --- a/CourseApp/Car.cs +++ b/CourseApp/Vehicles/Car.cs @@ -1,4 +1,4 @@ -namespace CourseApp +namespace Vehicles { using System; using System.Collections.Generic; diff --git a/CourseApp/Copter.cs b/CourseApp/Vehicles/Copter.cs similarity index 94% rename from CourseApp/Copter.cs rename to CourseApp/Vehicles/Copter.cs index 10da959..38eebb0 100644 --- a/CourseApp/Copter.cs +++ b/CourseApp/Vehicles/Copter.cs @@ -1,4 +1,4 @@ -namespace CourseApp +namespace Vehicles { using System; using System.Collections.Generic; @@ -11,8 +11,8 @@ public class Copter : Plane public Copter() { Name = "Boing737"; - Speed = 800; - Height = 8000; + Speed = 60; + Height = 1000; Diagonal = 8.4; } diff --git a/CourseApp/Phone.cs b/CourseApp/Vehicles/Phone.cs similarity index 97% rename from CourseApp/Phone.cs rename to CourseApp/Vehicles/Phone.cs index 3260118..ccbc031 100644 --- a/CourseApp/Phone.cs +++ b/CourseApp/Vehicles/Phone.cs @@ -1,4 +1,4 @@ -namespace CourseApp +namespace Vehicles { using System; diff --git a/CourseApp/Plane.cs b/CourseApp/Vehicles/Plane.cs similarity index 98% rename from CourseApp/Plane.cs rename to CourseApp/Vehicles/Plane.cs index 8fc0bd4..bace5ae 100644 --- a/CourseApp/Plane.cs +++ b/CourseApp/Vehicles/Plane.cs @@ -1,4 +1,4 @@ -namespace CourseApp +namespace Vehicles { using System; using System.Collections.Generic; diff --git a/CourseApp/Vehicle.cs b/CourseApp/Vehicles/Vehicle.cs similarity index 97% rename from CourseApp/Vehicle.cs rename to CourseApp/Vehicles/Vehicle.cs index 42e0468..a9caaaa 100644 --- a/CourseApp/Vehicle.cs +++ b/CourseApp/Vehicles/Vehicle.cs @@ -1,4 +1,4 @@ -namespace CourseApp +namespace Vehicles { using System; using System.Collections.Generic; From a9a9d84f7200762768c0df026b3a202dc994b6cc Mon Sep 17 00:00:00 2001 From: SellTheCat Date: Sat, 19 Nov 2022 15:23:00 +0300 Subject: [PATCH 2/3] Fixed tests for vehicles --- CourseApp.Tests/DemoTest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index 174ab9b..36c906b 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -1,6 +1,7 @@ namespace CourseApp.Tests { using Xunit; + using Vehicles; public class DemoTest { From c29c328728984acb578119ce3f6c9b7a0486b9eb Mon Sep 17 00:00:00 2001 From: SellTheCat Date: Sat, 24 Dec 2022 22:44:32 +0300 Subject: [PATCH 3/3] Added but not fixed battle maker & match maker --- CourseApp.Tests/TestSaga.cs | 30 ++++++++++++++++++++++++++ CourseApp/CourseApp.csproj | 2 +- CourseApp/Program.cs | 4 ++-- CourseApp/RPGSaga/BattleMaker.cs | 36 ++++++++++++++++++++++++++++++++ CourseApp/RPGSaga/MatchMaker.cs | 27 ++++++++++++++++++++++++ CourseApp/RPGSaga/Player.cs | 11 ++++++++-- 6 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 CourseApp.Tests/TestSaga.cs create mode 100644 CourseApp/RPGSaga/BattleMaker.cs create mode 100644 CourseApp/RPGSaga/MatchMaker.cs diff --git a/CourseApp.Tests/TestSaga.cs b/CourseApp.Tests/TestSaga.cs new file mode 100644 index 0000000..4888bbb --- /dev/null +++ b/CourseApp.Tests/TestSaga.cs @@ -0,0 +1,30 @@ +namespace CourseApp.Tests +{ + using Xunit; + using Vehicles; + + public class TestMatch + { + [Fact] + public void Test1() + { + Assert.True(true); + } + + [Fact] + public void TestBattleWinner1() + { + var top = new Player("Knight", "top", 100, 10); + var low = new Player("Knight", "low", 10, 1); + var winner = Battle(top, low); + Assert.Equal(top, winner); + } + public void TestBattleWinner2() + { + top = new Player("Knight", "top", 100, 10); + low = new Player("Knight", "low", 10, 1); + var winner = Battle(low, top); + Assert.Equal(top, winner); + } + } +} \ No newline at end of file diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index 7305fad..b94a7a4 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -3,7 +3,7 @@ Exe net6.0 - True + False diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index c764a51..abe8ee3 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -13,8 +13,8 @@ public static void Main(string[] args) artur.Greetings(); artur.DealDamage(); artur.VengStrike(); - var heros = new MultiplyChars(); - List twoheros = heros.CreateN(4); + var mc = new MultiplyChars(); + var twoheros = mc.CreateN(2); foreach (var player in twoheros) { player.Greetings(); diff --git a/CourseApp/RPGSaga/BattleMaker.cs b/CourseApp/RPGSaga/BattleMaker.cs new file mode 100644 index 0000000..cc5762d --- /dev/null +++ b/CourseApp/RPGSaga/BattleMaker.cs @@ -0,0 +1,36 @@ +namespace RPGSaga +{ + using System; + using System.Collections.Generic; + using System.Text; + + public class BattleMaker + { + public static Player Battle(Player player1, Player player2) + { + player1.health = player1.Maxhealth; + player2.health = player2.Maxhealth; + var winner = player1; + while (player1.health > 0 && player2.health > 0) + { + player1.DealDamage(); + player2.health = player2.health - player1.Power; + if (player2.health <= 0) + { + winner = player1; + Console.WriteLine($"Игрок {player1} победил!"); + return winner; + } + player2.DealDamage(); + player1.health = player1.health - player2.Power; + if (player2.health <= 0) + { + winner = player2; + Console.WriteLine($"Игрок {player2} победил!"); + return winner; + } + } + return winner; + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/MatchMaker.cs b/CourseApp/RPGSaga/MatchMaker.cs new file mode 100644 index 0000000..9125e7f --- /dev/null +++ b/CourseApp/RPGSaga/MatchMaker.cs @@ -0,0 +1,27 @@ +namespace RPGSaga +{ + using System; + using System.Collections.Generic; + using System.Text; + + public class MatchMaker + { + public MatchMaker() + { + var multiplyheros = new MultiplyChars(); + heros = multiplyheros.CreateN(N); + } + private int N = 4; + List heros; + public void Match() + { + for (int i = 1; i <= N; i += 2) + { + heros[i].Greetings(); + heros[i + 1].Greetings(); + BattleMaker.Battle(heros[i], heros[i + 1]); +/* return Battle(heros[i], heros[i + 1]); */ + } + } + } +} \ No newline at end of file diff --git a/CourseApp/RPGSaga/Player.cs b/CourseApp/RPGSaga/Player.cs index 93e45e0..6605829 100644 --- a/CourseApp/RPGSaga/Player.cs +++ b/CourseApp/RPGSaga/Player.cs @@ -6,8 +6,9 @@ namespace RPGSaga public abstract class Player { + public string Type; + public double health; private double maxhealth; - /* private double health; */ private double power; public Player() @@ -23,7 +24,13 @@ public Player(string name, double maxhealth, double power) Maxhealth = maxhealth; Power = power; } - + public Player(string type, string name, double maxhealth, double power) + { + Type = type; + Name = name; + Maxhealth = maxhealth; + Power = power; + } public string Name { get; set; } public double Maxhealth