diff --git a/CourseApp.RPGSagaTests/CourseApp.RPGSagaTests.csproj b/CourseApp.RPGSagaTests/CourseApp.RPGSagaTests.csproj new file mode 100644 index 0000000..7b01765 --- /dev/null +++ b/CourseApp.RPGSagaTests/CourseApp.RPGSagaTests.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + false + + + + + + + + + + diff --git a/CourseApp.RPGSagaTests/RPGSagaTests.cs b/CourseApp.RPGSagaTests/RPGSagaTests.cs new file mode 100644 index 0000000..4462fe2 --- /dev/null +++ b/CourseApp.RPGSagaTests/RPGSagaTests.cs @@ -0,0 +1,11 @@ +namespace CourseApp.RPGSagaTests +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void TestMethod1() + { + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/AutoMethodsTests.cs b/CourseApp.Tests/AutoMethodsTests.cs new file mode 100644 index 0000000..64bea8e --- /dev/null +++ b/CourseApp.Tests/AutoMethodsTests.cs @@ -0,0 +1,49 @@ +namespace CourseApp.Tests +{ + using CourseApp.RPGSaga; + using Xunit; + + public class AutoMethodsTests + { + [Fact] + public void GetInfo_SetSampleData_ReturnCorrectInfo_Auto() + { + Transport auto = new Auto(4.9, 1.71, 2145, 333, 250, "Audi Q8"); + Assert.Equal( + @"Info for Audi Q8 +Weight: 2145 kg +Length: 4,9 m +Height: 1,71 m +Power: 333 horsepower +Max Speed: 250 km\h", auto.GetInfo()); + } + + [Fact] + public void CheckConstructor_SetSampleData_ReturnCorrectInfo_Auto() + { + Transport auto = new Auto(); + + Assert.Equal( + @"Info for Auto +Weight: 0 kg +Length: 0 m +Height: 0 m +Power: 0 horsepower +Max Speed: 0 km\h", auto.GetInfo()); + } + + [Fact] + public void Movement_CallMovementMethod_CorrectMove_Auto() + { + Transport auto = new Auto(); + Assert.Equal(ActionTypes.Move, auto.Movement()); + } + + [Fact] + public void ToString_CheckStringPresentation_CorrectPresentationOfInstance() + { + Transport auto = new Auto(4.9, 1.71, 2145, 333, 250, "Audi Q8"); + Assert.Equal("Auto Audi Q8", auto.ToString()); + } + } +} diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs deleted file mode 100644 index cf7cbb1..0000000 --- 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/PlaneMethodsTests.cs b/CourseApp.Tests/PlaneMethodsTests.cs new file mode 100644 index 0000000..f7e6e81 --- /dev/null +++ b/CourseApp.Tests/PlaneMethodsTests.cs @@ -0,0 +1,63 @@ +namespace CourseApp.Tests +{ + using CourseApp.RPGSaga; + using Xunit; + + public class PlaneMethodsTests + { + [Fact] + public void GetInfo_SetSampleData_ReturnCorrectInfo() + { + Transport plane = new Plane(9.22, 2.74, 1361, 450, 255, "DHC-2 Beaver"); + Assert.Equal( + @"Info for DHC-2 Beaver +Weight: 1361 kg +Length: 9,22 m +Height: 2,74 m +Power: 450 horsepower +Max Speed: 255 km\h", plane.GetInfo()); + } + + [Fact] + public void CheckConstructor_SetSampleData_ReturnCorrectInfo() + { + Transport plane = new Plane(); + + Assert.Equal( + @"Info for Plane +Weight: 0 kg +Length: 0 m +Height: 0 m +Power: 0 horsepower +Max Speed: 0 km\h", plane.GetInfo()); + } + + [Fact] + public void Movement_CallMovementMethod_CorrectMoveInfo() + { + var plane = new Plane(); + Assert.Equal(ActionTypes.Move, plane.Movement()); + } + + [Fact] + public void Landing_CallLandingMethod_CorrectLandingInfo() + { + var plane = new Plane(); + Assert.Equal(ActionTypes.LAnding, plane.Landing()); + } + + [Fact] + public void Takeoff_CallLandingMethod_CorrectTakeoffInfo() + { + var plane = new Plane(); + Assert.Equal(ActionTypes.TAkeoff, plane.Takeoff()); + } + + [Fact] + public void ToString_CheckStringPresentation_CorrectPresentationOfInstance() + { + Transport plane = new Plane(9.22, 2.74, 1361, 450, 255, "DHC-2 Beaver"); + Assert.Equal("Plane DHC-2 Beaver", plane.ToString()); + } + } +} diff --git a/CourseApp/Class/ActionTypes.cs b/CourseApp/Class/ActionTypes.cs new file mode 100644 index 0000000..b3c1295 --- /dev/null +++ b/CourseApp/Class/ActionTypes.cs @@ -0,0 +1,33 @@ +namespace CourseApp.RPGSaga +{ + /// + /// Types of actions. + /// + public enum ActionTypes + { + /// + /// No type. + /// + Nothing, + + /// + /// Type for movement. + /// + Move, + + /// + /// Type for takeoff. + /// + TAkeoff, + + /// + /// Types for landing. + /// + LAnding, + + /// + /// Types for beep. + /// + BEep, + } +} diff --git a/CourseApp/Class/Auto.cs b/CourseApp/Class/Auto.cs new file mode 100644 index 0000000..f14d499 --- /dev/null +++ b/CourseApp/Class/Auto.cs @@ -0,0 +1,38 @@ +namespace CourseApp.RPGSaga +{ + using System; + + public class Auto : Transport + { + private ActionTypes actionType; + + public Auto() + : this(0, 0, 0, 0, 0, "Auto") + { + } + + public Auto(double length, double height, int weight, int power, int maxSpeed, string model) + : base(length, height, weight, power, maxSpeed, model) + { + } + + public override string ToString() + { + return $"Auto {Model}"; + } + + public override ActionTypes Movement() + { + actionType = ActionTypes.Move; + Console.WriteLine($"{Model} is moving at a speed {Speed}km/h"); + return actionType; + } + + public ActionTypes Beep() + { + actionType = ActionTypes.BEep; + Console.WriteLine("Beep"); + return actionType; + } + } +} diff --git a/CourseApp/Class/ILanding.cs b/CourseApp/Class/ILanding.cs new file mode 100644 index 0000000..5b97233 --- /dev/null +++ b/CourseApp/Class/ILanding.cs @@ -0,0 +1,6 @@ +namespace CourseApp.RPGSaga; + +public interface ILanding +{ + public ActionTypes Landing(); +} \ No newline at end of file diff --git a/CourseApp/Class/ITakeoff.cs b/CourseApp/Class/ITakeoff.cs new file mode 100644 index 0000000..7e5c896 --- /dev/null +++ b/CourseApp/Class/ITakeoff.cs @@ -0,0 +1,6 @@ +namespace CourseApp.RPGSaga; + +public interface ITakeoff +{ + public ActionTypes Takeoff(); +} \ No newline at end of file diff --git a/CourseApp/Class/Plane.cs b/CourseApp/Class/Plane.cs new file mode 100644 index 0000000..cdd8668 --- /dev/null +++ b/CourseApp/Class/Plane.cs @@ -0,0 +1,47 @@ +namespace CourseApp.RPGSaga +{ + using System; + + public class Plane : Transport, ILanding, ITakeoff + { + private ActionTypes actionType; + + public Plane() + : this(0, 0, 0, 0, 0, "Plane") + { + } + + public Plane(double length, double height, int weight, int power, int maxSpeed, string model) + : base(length, height, weight, power, maxSpeed, model) + { + } + + public string Direction { get; set; } + + public override string ToString() + { + return $"Plane {Model}"; + } + + public ActionTypes Takeoff() + { + actionType = ActionTypes.TAkeoff; + Console.WriteLine($"{Model} taking off"); + return actionType; + } + + public ActionTypes Landing() + { + actionType = ActionTypes.LAnding; + Console.WriteLine($"{Model} going to land"); + return actionType; + } + + public override ActionTypes Movement() + { + actionType = ActionTypes.Move; + Console.WriteLine($"{Model} is moving at a speed {Speed}km/h in the {Direction}"); + return actionType; + } + } +} diff --git a/CourseApp/Class/Transport.cs b/CourseApp/Class/Transport.cs new file mode 100644 index 0000000..45bff70 --- /dev/null +++ b/CourseApp/Class/Transport.cs @@ -0,0 +1,77 @@ +namespace CourseApp +{ + using System; + using CourseApp.RPGSaga; + + public abstract class Transport + { + private int _speed; + + public Transport() + : this(0, 0, 0, 0, 0, "No_name") + { + } + + public Transport(double length, double height, int weight, int power, int maxSpeed, string model) + { + Length = length; + Weight = weight; + Power = power; + Height = height; + MaxSpeed = maxSpeed; + Model = model; + } + + public string Model { get; set; } + + public int Power { get; } + + public double Length { get; } + + public int Weight { get; } + + public double Height { get; } + + public int MaxSpeed { get; } + + public int Speed + { + get + { + return _speed; + } + + set + { + try + { + if (value > MaxSpeed || value < 0) + { + throw new Exception($"speed is too large or too little for {Model}"); + } + else + { + _speed = value; + } + } + catch (Exception e) + { + new ArgumentException($"Error: {e.Message}"); + Console.WriteLine($"Error: {e.Message}"); + } + } + } + + public abstract ActionTypes Movement(); + + public string GetInfo() + { + return @$"Info for {Model} +Weight: {Weight} kg +Length: {Length} m +Height: {Height} m +Power: {Power} horsepower +Max Speed: {MaxSpeed} km\h"; + } + } +} diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index eb22147..ba2f49f 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -15,8 +15,4 @@ true - - - - diff --git a/CourseApp/Game.cs b/CourseApp/Game.cs new file mode 100644 index 0000000..3988cbe --- /dev/null +++ b/CourseApp/Game.cs @@ -0,0 +1,141 @@ +namespace CourseApp.RPGSaga +{ + using System; + using System.Collections.Generic; + + public class Game + { + private static string[] _names = new string[20] { "Евгений", "Евграф", "Евдоким", "Евсей", "Евстафий", "Авдей", "Авксентий", "Агапит", "Агафон", "Акакий", "Ждан", "Зиновий", "Иакинф", "Иван", "Игнатий", "Вавила", "Вадим", "Валентин", "Валерий", "Валерьян" }; + private static Random _random = new Random(); + private static bool death; + + public static void Main(string[] args) + { + List battle = new List(); + int battleCounter = 0; + int roundCounter = 0; + + var numberOfPlayers = GameInitial(); + + if (numberOfPlayers == 0) + { + return; + } + + var players = HeroFactory(numberOfPlayers, new List { }); + + while (players.Count > 1) + { + battle.Add(players[_random.Next(0, players.Count)]); + players.Remove(battle[0]); + battle.Add(players[_random.Next(0, players.Count)]); + players.Remove(battle[1]); + + Logger.Space(); + + if (battleCounter % 2 == 0) + { + Logger.WriteLog($"Кон {roundCounter += 1}"); + } + + Logger.Space(); + Logger.WriteLog(battle[0].ToString() + " vs " + battle[1].ToString()); + + while (death == false) + { + if (_random.Next(0, 5) == 2) + { + battle[0].Ultimate(); + Logger.WriteLog(battle[0].ToString() + " ультует!"); + } + else + { + battle[1].GetDamage(battle[0].GiveDamage()); + Logger.WriteLog(battle[0].ToString() + $" наносит {battle[0].GiveDamage()} урона противнику: " + battle[1].ToString()); + } + + if (battle[1].Health < 1) + { + death = true; + players.Add(battle[0]); + Logger.WriteLog(battle[1].ToString() + " погибает"); + break; + } + + if (_random.Next(0, 10) == 2) + { + battle[1].Ultimate(); + Logger.WriteLog(battle[1].ToString() + " ультует!"); + } + else + { + battle[0].GetDamage(battle[1].GiveDamage()); + Logger.WriteLog(battle[1].ToString() + $" наносит {battle[1].GiveDamage()} урона противнику: " + battle[0].ToString()); + } + + if (battle[0].Health < 1) + { + death = true; + players.Add(battle[1]); + Logger.WriteLog(battle[0].ToString() + " погибает"); + break; + } + } + + death = false; + battle.Clear(); + battleCounter++; + } + + Logger.Space(); + Logger.WriteLog(players[0].ToString() + " побеждает! Здоровья погибшим)"); + Logger.Space(); + Logger.WriteLog(@" ___ ___ ______ ___ ___ + \ \ ____ / / |_ _| | \ | | + \ \ / \ / / | | | \| | + \ \/ /\ \/ / _| |_ | \ | + \____/ \____/ |______| |___|\_____| + +"); + } + + public static int GameInitial() + { + Console.Write("Введите кол-во героев: "); + int numberOfPlayers = Convert.ToInt16(Console.ReadLine()); + Console.WriteLine(); + if (numberOfPlayers % 2.0 != 0 || numberOfPlayers <= 0) + { + Console.WriteLine("Количество героев нечетное!"); + return 0; + } + + return numberOfPlayers; + } + + public static List HeroFactory(int numberOfPlayers, List players) + { + for (int i = 0; i < numberOfPlayers; i++) + { + var randomName = _names[_random.Next(0, 20)]; + switch (CreatePlayers.GetHeroType()) + { + case PlayerTypes.NotType: + new Exception("Player has not type"); + break; + case PlayerTypes.Knight: + players.Add(new Knight(randomName)); + break; + case PlayerTypes.Archer: + players.Add(new Archer(randomName)); + break; + case PlayerTypes.Wizard: + players.Add(new Wizard(randomName)); + break; + } + } + + return players; + } + } +} diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs deleted file mode 100644 index d6d2c87..0000000 --- a/CourseApp/Program.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace CourseApp -{ - using System; - - public class Program - { - public static void Main(string[] args) - { - Console.WriteLine("Hello World"); - } - } -} diff --git a/CourseApp/RPGSaga/Archer.cs b/CourseApp/RPGSaga/Archer.cs new file mode 100644 index 0000000..04e2db5 --- /dev/null +++ b/CourseApp/RPGSaga/Archer.cs @@ -0,0 +1,41 @@ +namespace CourseApp.RPGSaga +{ + public class Archer : Player + { + private bool ult = false; + + public Archer(string name) + { + Name = name; + } + + public override string ToString() + { + return $"(Лучник) {Name}"; + } + + public override void Ultimate() + { + if (ult == true) + { + GiveDamage(); + } + else + { + ult = true; + } + } + + public override int GiveDamage() + { + if (ult == false) + { + return Strength; + } + else + { + return Strength + 2; + } + } + } +} diff --git a/CourseApp/RPGSaga/CreatePlayers.cs b/CourseApp/RPGSaga/CreatePlayers.cs new file mode 100644 index 0000000..5d1038f --- /dev/null +++ b/CourseApp/RPGSaga/CreatePlayers.cs @@ -0,0 +1,25 @@ +namespace CourseApp.RPGSaga +{ + using System; + + public static class CreatePlayers + { + private static Random _random = new (); + + public static PlayerTypes GetHeroType() + { + var type = _random.Next(0, 3); + switch (type) + { + case 0: + return PlayerTypes.Knight; + case 1: + return PlayerTypes.Wizard; + case 2: + return PlayerTypes.Archer; + default: + return PlayerTypes.NotType; + } + } + } +} diff --git a/CourseApp/RPGSaga/Knight.cs b/CourseApp/RPGSaga/Knight.cs new file mode 100644 index 0000000..8525834 --- /dev/null +++ b/CourseApp/RPGSaga/Knight.cs @@ -0,0 +1,37 @@ +namespace CourseApp.RPGSaga +{ + using System; + + public class Knight : Player + { + private bool ult = false; + + public Knight(string name) + { + Name = name; + } + + public override string ToString() + { + return $"(Рыцарь) {Name}"; + } + + public override void Ultimate() + { + ult = true; + } + + public override int GiveDamage() + { + if (ult == false) + { + return Strength; + } + else + { + ult = false; + return (int)Math.Round(Strength * 1.3); + } + } + } +} diff --git a/CourseApp/RPGSaga/Logger.cs b/CourseApp/RPGSaga/Logger.cs new file mode 100644 index 0000000..364d28e --- /dev/null +++ b/CourseApp/RPGSaga/Logger.cs @@ -0,0 +1,17 @@ +namespace CourseApp.RPGSaga +{ + using System; + + public static class Logger + { + public static void WriteLog(string message) + { + Console.WriteLine($"{DateTime.Now} : {message}"); + } + + public static void Space() + { + Console.WriteLine(); + } + } +} diff --git a/CourseApp/RPGSaga/Player.cs b/CourseApp/RPGSaga/Player.cs new file mode 100644 index 0000000..8ce6463 --- /dev/null +++ b/CourseApp/RPGSaga/Player.cs @@ -0,0 +1,34 @@ +namespace CourseApp.RPGSaga +{ + using System; + + public abstract class Player + { + private Random randomValue = new Random(); + + public Player() + { + Health = randomValue.Next(40, 100); + Strength = randomValue.Next(20, 40); + } + + public PlayerTypes MyProperty { get; set; } + + public string Name { get; set; } + + public int Health { get; set; } + + public int Strength { get; set; } + + public virtual void Ultimate() + { + } + + public abstract int GiveDamage(); + + public virtual void GetDamage(int damage) + { + Health -= damage; + } + } +} diff --git a/CourseApp/RPGSaga/PlayerTypes.cs b/CourseApp/RPGSaga/PlayerTypes.cs new file mode 100644 index 0000000..cebcfa6 --- /dev/null +++ b/CourseApp/RPGSaga/PlayerTypes.cs @@ -0,0 +1,28 @@ +namespace CourseApp.RPGSaga +{ + /// + /// Types of actions. + /// + public enum PlayerTypes + { + /// + /// No type. + /// + NotType, + + /// + /// Type for Knight. + /// + Knight, + + /// + /// Type for Archer. + /// + Archer, + + /// + /// Types for Wizard. + /// + Wizard, + } +} diff --git a/CourseApp/RPGSaga/Wizard.cs b/CourseApp/RPGSaga/Wizard.cs new file mode 100644 index 0000000..6067548 --- /dev/null +++ b/CourseApp/RPGSaga/Wizard.cs @@ -0,0 +1,41 @@ +namespace CourseApp.RPGSaga +{ + public class Wizard : Player + { + public Wizard(string name) + { + Name = name; + Invisible = false; + } + + public bool Invisible { get; set; } + + public override string ToString() + { + return $"(Маг) {Name}"; + } + + public override void Ultimate() + { + Invisible = true; + } + + public override int GiveDamage() + { + return Strength; + } + + public override void GetDamage(int damage) + { + if (Invisible == false) + { + Health -= damage; + } + else + { + Invisible = false; + Logger.WriteLog($"{ToString()} использует неуязвимость!"); + } + } + } +} diff --git a/CourseApp/stylecop.json b/CourseApp/stylecop.json new file mode 100644 index 0000000..4a96e8f --- /dev/null +++ b/CourseApp/stylecop.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "documentationRules": { + "documentExposedElements": false, + "documentInterfaces": false, + "companyName": "Test Company", + "copyrightText": "This source code is Copyright © {companyName} and MAY NOT be copied, reproduced,\npublished, distributed or transmitted to or stored in any manner without prior\nwritten consent from {companyName} (www.yourcompany.com).", + "xmlHeader":false + } + } +} \ No newline at end of file