From 290a0fef2f3d73ac8f976bb24e7ec8247d281eea Mon Sep 17 00:00:00 2001 From: Artem Date: Wed, 12 Apr 2023 21:23:31 +0300 Subject: [PATCH 1/3] =?UTF-8?q?+=D0=98=D0=B3=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Game/Game.sln | 25 ++++++++ Game/Game/EventLoop.cs | 98 ++++++++++++++++++++++++++++++++ Game/Game/Game.cs | 36 ++++++++++++ Game/Game/Game.csproj | 10 ++++ Game/Game/InvalidMapException.cs | 3 + Game/Game/Program.cs | 18 ++++++ 6 files changed, 190 insertions(+) create mode 100644 Game/Game.sln create mode 100644 Game/Game/EventLoop.cs create mode 100644 Game/Game/Game.cs create mode 100644 Game/Game/Game.csproj create mode 100644 Game/Game/InvalidMapException.cs create mode 100644 Game/Game/Program.cs diff --git a/Game/Game.sln b/Game/Game.sln new file mode 100644 index 0000000..5250f1e --- /dev/null +++ b/Game/Game.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33403.182 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Game", "Game\Game.csproj", "{9B96D5C7-8B64-463D-9AA8-E25AA17831C8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9B96D5C7-8B64-463D-9AA8-E25AA17831C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9B96D5C7-8B64-463D-9AA8-E25AA17831C8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9B96D5C7-8B64-463D-9AA8-E25AA17831C8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9B96D5C7-8B64-463D-9AA8-E25AA17831C8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {44167783-B5A0-436E-A141-633477AFAD18} + EndGlobalSection +EndGlobal diff --git a/Game/Game/EventLoop.cs b/Game/Game/EventLoop.cs new file mode 100644 index 0000000..ca203fc --- /dev/null +++ b/Game/Game/EventLoop.cs @@ -0,0 +1,98 @@ +using System.IO; +using System.Text; + +namespace Game; + +public delegate void ArrowHandler(int startPositionLeft, int startPositionTop); + +public class EventLoop +{ + public void Run(ArrowHandler left, ArrowHandler right, ArrowHandler up, ArrowHandler down, string fileWithMap) + { + int sizeLong = 0; + int sizeWidth = 0; + var file = new StreamReader(fileWithMap); + int sizeDogSymbols = 0; + int sizeSpaces = 0; + bool isFirst = true; + while (!file.EndOfStream) + { + if (!isFirst) + { + if (sizeWidth == 1 && sizeDogSymbols != sizeLong) + { + throw new InvalidMapException(); + } + else if (sizeWidth != 1 && sizeDogSymbols != 2 || sizeSpaces != sizeLong - sizeDogSymbols) + { + throw new InvalidMapException(); + } + } + var line = file.ReadLine(); + ++sizeWidth; + int size = line.Count(x => x == '@'); + if (line == null) + { + throw new NullReferenceException(); + } + if (sizeLong != 0 && sizeLong != line.Length) + { + throw new InvalidMapException(); + } + sizeLong = line.Length; + sizeDogSymbols = line.Count(x => x == '@'); + sizeSpaces = line.Count(x => x == ' '); + isFirst = false; + Console.WriteLine(line); + } + if (sizeDogSymbols != sizeLong) + { + throw new InvalidMapException(); + } + + if (sizeWidth < 3 || sizeLong < 3) + { + throw new InvalidMapException(); + } + Console.SetCursorPosition(sizeLong / 2, sizeWidth / 2); + Console.Write('@'); + int startPositionLeft = Console.CursorLeft - 1; + int startPositionTop = Console.CursorTop; + Console.SetCursorPosition(startPositionLeft, startPositionTop); + while (true) + { + var key = Console.ReadKey(true); + switch (key.Key) + { + case ConsoleKey.LeftArrow: + if (startPositionLeft != 1) + { + left(startPositionLeft, startPositionTop); + --startPositionLeft; + } + break; + case ConsoleKey.RightArrow: + if (startPositionLeft != sizeLong - 2) + { + right(startPositionLeft, startPositionTop); + ++startPositionLeft; + } + break; + case ConsoleKey.UpArrow: + if (startPositionTop != 1) + { + up(startPositionLeft, startPositionTop); + --startPositionTop; + } + break; + case ConsoleKey.DownArrow: + if (startPositionTop != sizeWidth - 2) + { + down(startPositionLeft, startPositionTop); + ++startPositionTop; + } + break; + } + } + } +} diff --git a/Game/Game/Game.cs b/Game/Game/Game.cs new file mode 100644 index 0000000..9630f8d --- /dev/null +++ b/Game/Game/Game.cs @@ -0,0 +1,36 @@ +namespace Game; + +public class Game +{ + public void OnLeft(int startPositionLeft, int startPositionTop) + { + Console.Write(' '); + Console.SetCursorPosition(startPositionLeft - 1, startPositionTop); + Console.Write('@'); + Console.SetCursorPosition(startPositionLeft - 1, startPositionTop); + } + + public void OnRight(int startPositionLeft, int startPositionTop) + { + Console.Write(' '); + Console.SetCursorPosition(startPositionLeft + 1, startPositionTop); + Console.Write('@'); + Console.SetCursorPosition(startPositionLeft + 1, startPositionTop); + } + + public void OnUp(int startPositionLeft, int startPositionTop) + { + Console.Write(' '); + Console.SetCursorPosition(startPositionLeft, startPositionTop - 1); + Console.Write('@'); + Console.SetCursorPosition(startPositionLeft, startPositionTop - 1); + } + + public void OnDown(int startPositionLeft, int startPositionTop) + { + Console.Write(' '); + Console.SetCursorPosition(startPositionLeft, startPositionTop + 1); + Console.Write('@'); + Console.SetCursorPosition(startPositionLeft, startPositionTop + 1); + } +} diff --git a/Game/Game/Game.csproj b/Game/Game/Game.csproj new file mode 100644 index 0000000..f02677b --- /dev/null +++ b/Game/Game/Game.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + + diff --git a/Game/Game/InvalidMapException.cs b/Game/Game/InvalidMapException.cs new file mode 100644 index 0000000..7e79dfa --- /dev/null +++ b/Game/Game/InvalidMapException.cs @@ -0,0 +1,3 @@ +namespace Game; + +public class InvalidMapException : Exception {} \ No newline at end of file diff --git a/Game/Game/Program.cs b/Game/Game/Program.cs new file mode 100644 index 0000000..c155546 --- /dev/null +++ b/Game/Game/Program.cs @@ -0,0 +1,18 @@ +namespace Game; + +public class Program +{ + public static void Main() + { + var game = new Game(); + var eventLoop = new EventLoop(); + var filePath = @"C:\Users\User\source\repos\HomeworksCSharp\Game\Map.txt"; + eventLoop.Run( + new ArrowHandler(game.OnLeft), + new ArrowHandler(game.OnRight), + new ArrowHandler(game.OnUp), + new ArrowHandler(game.OnDown), + filePath + ); + } +} \ No newline at end of file From 1dd59a150ddc4127f40d4baa86f099dc5a7d1c3d Mon Sep 17 00:00:00 2001 From: Artem Date: Fri, 14 Apr 2023 09:42:41 +0300 Subject: [PATCH 2/3] =?UTF-8?q?+=D0=A2=D0=B5=D1=81=D1=82=D1=8Bwq?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Game/Game.sln | 8 +- Game/Game/EventLoop.cs | 61 +++-- Game/Game/Game.cs | 71 ++++-- Game/Game/Interface.cs | 29 +++ Game/Game/PrintInConsole.cs | 35 +++ Game/Game/PrintInList.cs | 48 ++++ Game/Game/Program.cs | 32 ++- Game/Game/WorkWithConsole.cs | 13 ++ Game/TestsForGame/TestsForGame.cs | 216 ++++++++++++++++++ Game/TestsForGame/TestsForGame.csproj | 23 ++ Game/TestsForGame/Usings.cs | 1 + .../IncorrectMapWithIncorrectSymbol.txt | 3 + .../IncorrectMapWithToSmallSize.txt | 2 + .../net7.0/TestsForGame/MapWithCloseWalls.txt | 3 + .../Debug/net7.0/TestsForGame/NormalMap.txt | 7 + 15 files changed, 502 insertions(+), 50 deletions(-) create mode 100644 Game/Game/Interface.cs create mode 100644 Game/Game/PrintInConsole.cs create mode 100644 Game/Game/PrintInList.cs create mode 100644 Game/Game/WorkWithConsole.cs create mode 100644 Game/TestsForGame/TestsForGame.cs create mode 100644 Game/TestsForGame/TestsForGame.csproj create mode 100644 Game/TestsForGame/Usings.cs create mode 100644 Game/TestsForGame/bin/Debug/net7.0/TestsForGame/IncorrectMapWithIncorrectSymbol.txt create mode 100644 Game/TestsForGame/bin/Debug/net7.0/TestsForGame/IncorrectMapWithToSmallSize.txt create mode 100644 Game/TestsForGame/bin/Debug/net7.0/TestsForGame/MapWithCloseWalls.txt create mode 100644 Game/TestsForGame/bin/Debug/net7.0/TestsForGame/NormalMap.txt diff --git a/Game/Game.sln b/Game/Game.sln index 5250f1e..c6e097f 100644 --- a/Game/Game.sln +++ b/Game/Game.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33403.182 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Game", "Game\Game.csproj", "{9B96D5C7-8B64-463D-9AA8-E25AA17831C8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Game", "Game\Game.csproj", "{9B96D5C7-8B64-463D-9AA8-E25AA17831C8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsForGame", "TestsForGame\TestsForGame.csproj", "{8F9ECC7B-3D85-4839-930E-90A426CD0E34}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {9B96D5C7-8B64-463D-9AA8-E25AA17831C8}.Debug|Any CPU.Build.0 = Debug|Any CPU {9B96D5C7-8B64-463D-9AA8-E25AA17831C8}.Release|Any CPU.ActiveCfg = Release|Any CPU {9B96D5C7-8B64-463D-9AA8-E25AA17831C8}.Release|Any CPU.Build.0 = Release|Any CPU + {8F9ECC7B-3D85-4839-930E-90A426CD0E34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8F9ECC7B-3D85-4839-930E-90A426CD0E34}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8F9ECC7B-3D85-4839-930E-90A426CD0E34}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8F9ECC7B-3D85-4839-930E-90A426CD0E34}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Game/Game/EventLoop.cs b/Game/Game/EventLoop.cs index ca203fc..30d3e54 100644 --- a/Game/Game/EventLoop.cs +++ b/Game/Game/EventLoop.cs @@ -1,13 +1,27 @@ -using System.IO; -using System.Text; +namespace Game; -namespace Game; - -public delegate void ArrowHandler(int startPositionLeft, int startPositionTop); +public delegate void ArrowHandler(int startPositionLeft, int startPositionTop, WorkWithConsole data, ref List<((int, int), char)> forTests); +/// +/// Event handler implementation class +/// public class EventLoop { - public void Run(ArrowHandler left, ArrowHandler right, ArrowHandler up, ArrowHandler down, string fileWithMap) + /// + /// Event Handler + /// + /// Function for moving to the left + /// Function for moving to the right + /// Function for moving to the up + /// Function for moving to the down + /// File with map + /// The selected type for testing or normal operation + /// A list intended for entering results for tests ONLY + /// List of commands for tests ONLY + /// Incorrectly set map + /// Checking that the read card line is not empty + public void Run(ArrowHandler left, ArrowHandler right, ArrowHandler up, ArrowHandler down, + string fileWithMap, WorkWithConsole data, ref List<((int, int), char)> forTests, List listKeys = null) { int sizeLong = 0; int sizeWidth = 0; @@ -54,41 +68,46 @@ public void Run(ArrowHandler left, ArrowHandler right, ArrowHandler up, ArrowHan { throw new InvalidMapException(); } - Console.SetCursorPosition(sizeLong / 2, sizeWidth / 2); - Console.Write('@'); - int startPositionLeft = Console.CursorLeft - 1; - int startPositionTop = Console.CursorTop; - Console.SetCursorPosition(startPositionLeft, startPositionTop); + data.SetCursorPosition(sizeLong / 2, sizeWidth / 2, ref forTests); + data.Print('@', ref forTests); + int startPositionLeft = sizeLong / 2; + int startPositionTop = sizeWidth / 2; + data.SetCursorPosition(startPositionLeft, startPositionTop, ref forTests); + var checkType = new PrintInList(); while (true) { - var key = Console.ReadKey(true); - switch (key.Key) + if (data.GetType() == checkType.GetType() && listKeys.Count == 0) + { + return; + } + var key = data.Comparison(listKeys); + switch (key) { - case ConsoleKey.LeftArrow: + case "left": if (startPositionLeft != 1) { - left(startPositionLeft, startPositionTop); + left(startPositionLeft, startPositionTop, data, ref forTests); --startPositionLeft; } break; - case ConsoleKey.RightArrow: + case "right": if (startPositionLeft != sizeLong - 2) { - right(startPositionLeft, startPositionTop); + right(startPositionLeft, startPositionTop, data, ref forTests); ++startPositionLeft; } break; - case ConsoleKey.UpArrow: + case "up": if (startPositionTop != 1) { - up(startPositionLeft, startPositionTop); + up(startPositionLeft, startPositionTop, data, ref forTests); --startPositionTop; } break; - case ConsoleKey.DownArrow: + case "down": if (startPositionTop != sizeWidth - 2) { - down(startPositionLeft, startPositionTop); + down(startPositionLeft, startPositionTop, data, ref forTests); ++startPositionTop; } break; diff --git a/Game/Game/Game.cs b/Game/Game/Game.cs index 9630f8d..66b2426 100644 --- a/Game/Game/Game.cs +++ b/Game/Game/Game.cs @@ -1,36 +1,67 @@ namespace Game; +/// +/// A class that implements actions in the game +/// public class Game { - public void OnLeft(int startPositionLeft, int startPositionTop) + /// + /// Move to the Left + /// + /// X coordinate + /// Y coordinate + /// Selected type: testing or normal launch + /// The list of entering results for tests ONLY + public void OnLeft(int startPositionLeft, int startPositionTop, WorkWithConsole data, ref List<((int, int), char)> forTests) { - Console.Write(' '); - Console.SetCursorPosition(startPositionLeft - 1, startPositionTop); - Console.Write('@'); - Console.SetCursorPosition(startPositionLeft - 1, startPositionTop); + data.Print(' ', ref forTests); + data.SetCursorPosition(startPositionLeft - 1, startPositionTop, ref forTests); + data.Print('@', ref forTests); + data.SetCursorPosition(startPositionLeft - 1, startPositionTop, ref forTests); } - public void OnRight(int startPositionLeft, int startPositionTop) + /// + /// Move to the Right + /// + /// X coordinate + /// Y coordinate + /// Selected type: testing or normal launch + /// The list of entering results for tests ONLY + public void OnRight(int startPositionLeft, int startPositionTop, WorkWithConsole data, ref List<((int, int), char)> forTests) { - Console.Write(' '); - Console.SetCursorPosition(startPositionLeft + 1, startPositionTop); - Console.Write('@'); - Console.SetCursorPosition(startPositionLeft + 1, startPositionTop); + data.Print(' ', ref forTests); + data.SetCursorPosition(startPositionLeft + 1, startPositionTop, ref forTests); + data.Print('@', ref forTests); + data.SetCursorPosition(startPositionLeft + 1, startPositionTop, ref forTests); } - public void OnUp(int startPositionLeft, int startPositionTop) + /// + /// Move to the Up + /// + /// X coordinate + /// Y coordinate + /// Selected type: testing or normal launch + /// The list of entering results for tests ONLY + public void OnUp(int startPositionLeft, int startPositionTop, WorkWithConsole data, ref List<((int, int), char)> forTests) { - Console.Write(' '); - Console.SetCursorPosition(startPositionLeft, startPositionTop - 1); - Console.Write('@'); - Console.SetCursorPosition(startPositionLeft, startPositionTop - 1); + data.Print(' ', ref forTests); + data.SetCursorPosition(startPositionLeft, startPositionTop - 1, ref forTests); + data.Print('@', ref forTests); + data.SetCursorPosition(startPositionLeft, startPositionTop - 1, ref forTests); } - public void OnDown(int startPositionLeft, int startPositionTop) + /// + /// Move to the Down + /// + /// X coordinate + /// Y coordinate + /// Selected type: testing or normal launch + /// The list of entering results for tests ONLY + public void OnDown(int startPositionLeft, int startPositionTop, WorkWithConsole data, ref List<((int, int), char)> forTests) { - Console.Write(' '); - Console.SetCursorPosition(startPositionLeft, startPositionTop + 1); - Console.Write('@'); - Console.SetCursorPosition(startPositionLeft, startPositionTop + 1); + data.Print(' ', ref forTests); + data.SetCursorPosition(startPositionLeft, startPositionTop + 1, ref forTests); + data.Print('@', ref forTests); + data.SetCursorPosition(startPositionLeft, startPositionTop + 1, ref forTests); } } diff --git a/Game/Game/Interface.cs b/Game/Game/Interface.cs new file mode 100644 index 0000000..6e30b97 --- /dev/null +++ b/Game/Game/Interface.cs @@ -0,0 +1,29 @@ +namespace Game; + +/// +/// The interface for the game, namely for tests and normal startup +/// +interface GameInterface +{ + /// + /// For a normal launch, it prints to the console for tests, it is included in a special list + /// + /// Symbol for printing + /// The list is necessary ONLY for tests + void Print(char symbol, ref List<((int, int), char)> forTests); + + /// + /// For normal work, it puts the cursor in the console at the specified coordinates, for tests it fixes cursor changes in a special list + /// + /// X coordinate + /// Y coordinates + /// The list is for tests ONLY changes are being made here + void SetCursorPosition(int positionLeft, int PositionTop, ref List<((int, int), char)> forTests); + + /// + /// Different comparison for tests and for a normal run + /// + /// List of commands for tests only + /// Returns a string: left up right down + string Comparison(List listKeys = null); +} \ No newline at end of file diff --git a/Game/Game/PrintInConsole.cs b/Game/Game/PrintInConsole.cs new file mode 100644 index 0000000..a3df434 --- /dev/null +++ b/Game/Game/PrintInConsole.cs @@ -0,0 +1,35 @@ +namespace Game; + +/// +/// Implements an interface for tests +/// +public class PrintInConsole:WorkWithConsole +{ + public override void Print(char symbol, ref List<((int, int), char)> forTests) + { + Console.Write(symbol); + } + + public override void SetCursorPosition(int positionLeft, int PositionTop, ref List<((int, int), char)> forTests) + { + Console.SetCursorPosition(positionLeft, PositionTop); + } + + public override string Comparison(List listKeys = null) + { + var key = Console.ReadKey(true); + switch (key.Key) + { + case ConsoleKey.LeftArrow: + return "left"; + case ConsoleKey.RightArrow: + return "right"; + case ConsoleKey.UpArrow: + return "up"; + case ConsoleKey.DownArrow: + return "down"; + } + return "another"; + + } +} \ No newline at end of file diff --git a/Game/Game/PrintInList.cs b/Game/Game/PrintInList.cs new file mode 100644 index 0000000..3b256cf --- /dev/null +++ b/Game/Game/PrintInList.cs @@ -0,0 +1,48 @@ +namespace Game; + +/// +/// Implements the interface for the console +/// +public class PrintInList:WorkWithConsole +{ + public override void Print(char symbol, ref List<((int, int), char)> forTests) + { + if (forTests == null) + { + throw new NullReferenceException(); + } + forTests.Add(((-1, -1), symbol)); + } + + public override void SetCursorPosition(int positionLeft, int PositionTop, ref List<((int, int), char)> forTests) + { + if (forTests == null) + { + throw new NullReferenceException(); + } + forTests.Add(((positionLeft, PositionTop), '\0')); + } + + public override string Comparison(List listKeys = null) + { + if (listKeys == null) + { + throw new NullReferenceException(); + } + var key = listKeys.First(); + listKeys.RemoveAt(0); + switch (key) + { + case (char)37: + return "left"; + case (char)38: + return "up"; + case (char)39: + return "right"; + case (char)40: + return "down"; + } + return "another"; + + } +} \ No newline at end of file diff --git a/Game/Game/Program.cs b/Game/Game/Program.cs index c155546..f060430 100644 --- a/Game/Game/Program.cs +++ b/Game/Game/Program.cs @@ -6,13 +6,29 @@ public static void Main() { var game = new Game(); var eventLoop = new EventLoop(); - var filePath = @"C:\Users\User\source\repos\HomeworksCSharp\Game\Map.txt"; - eventLoop.Run( - new ArrowHandler(game.OnLeft), - new ArrowHandler(game.OnRight), - new ArrowHandler(game.OnUp), - new ArrowHandler(game.OnDown), - filePath - ); + Console.WriteLine("Input your string with file path"); + var filePath = Console.ReadLine(); + Console.Clear(); + List<((int, int), char)> list = new List<((int, int), char)>(); + try + { + eventLoop.Run( + new ArrowHandler(game.OnLeft), + new ArrowHandler(game.OnRight), + new ArrowHandler(game.OnUp), + new ArrowHandler(game.OnDown), + filePath, + new PrintInConsole(), + ref list + ); + } + catch (InvalidMapException) + { + Console.WriteLine("Incorrect map"); + } + catch (NullReferenceException) + { + Console.WriteLine("Problems with file or reading lines in file"); + } } } \ No newline at end of file diff --git a/Game/Game/WorkWithConsole.cs b/Game/Game/WorkWithConsole.cs new file mode 100644 index 0000000..12388ca --- /dev/null +++ b/Game/Game/WorkWithConsole.cs @@ -0,0 +1,13 @@ +namespace Game; + +/// +/// Ancestor of two implementation classes one for tests the other for use +/// +abstract public class WorkWithConsole:GameInterface +{ + virtual public void Print(char symbol, ref List<((int, int), char)> forTests) { } + + virtual public void SetCursorPosition(int positionLeft, int PositionTop,ref List<((int, int), char)> forTests) { } + + virtual public string Comparison(List listKeys = null) { return null; } +} \ No newline at end of file diff --git a/Game/TestsForGame/TestsForGame.cs b/Game/TestsForGame/TestsForGame.cs new file mode 100644 index 0000000..2776588 --- /dev/null +++ b/Game/TestsForGame/TestsForGame.cs @@ -0,0 +1,216 @@ +namespace TestsForGame; + +using Game; +using System.Linq; + +public class Tests +{ + Game game; + + [SetUp] + public void Setup() + { + game = new Game(); + } + + [TestCaseSource(nameof(GameForTest))] + public void TheIncorrectMapWithIncorrectSymbolShouldThrowException(Game game) + { + EventLoop eventLoop = new EventLoop(); + var forTests = new List<((int, int), char)>(); + Assert.Throws(() => eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "IncorrectMapWithIncorrectSymbol.txt"), new PrintInList(), ref forTests)); + } + + [TestCaseSource(nameof(GameForTest))] + public void TheIncorrectMapWithTooSmallSizeShouldThrowException(Game game) + { + EventLoop eventLoop = new EventLoop(); + var forTests = new List<((int, int), char)>(); + Assert.Throws(() => eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "IncorrectMapWithToSmallSize.txt"), new PrintInList(), ref forTests)); + } + + [TestCaseSource(nameof(GameForTest))] + public void TheCharacterMustWalkCorrectlyToTheLeft(Game game) + { + EventLoop eventLoop = new EventLoop(); + var printInList = new PrintInList(); + var forTests = new List<((int, int), char)>(); + var listChar = new List(); + listChar.Add((char)37); + var listCheck = new List<((int, int), char)>(); + listCheck.Add(((8, 3), '\0')); + listCheck.Add(((-1, -1), '@')); + listCheck.Add(((8, 3), '\0')); + listCheck.Add(((-1, -1), ' ')); + listCheck.Add(((7, 3), '\0')); + listCheck.Add(((-1, -1), '@')); + listCheck.Add(((7, 3), '\0')); + eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "NormalMap.txt"), + printInList, ref forTests, listChar); + Assert.True(forTests.SequenceEqual(listCheck)); + } + + [TestCaseSource(nameof(GameForTest))] + public void TheCharacterMustWalkCorrectlyToTheUp(Game game) + { + EventLoop eventLoop = new EventLoop(); + var printInList = new PrintInList(); + var forTests = new List<((int, int), char)>(); + var listChar = new List(); + listChar.Add((char)38); + var listCheck = new List<((int, int), char)>(); + listCheck.Add(((8, 3), '\0')); + listCheck.Add(((-1, -1), '@')); + listCheck.Add(((8, 3), '\0')); + listCheck.Add(((-1, -1), ' ')); + listCheck.Add(((8, 2), '\0')); + listCheck.Add(((-1, -1), '@')); + listCheck.Add(((8, 2), '\0')); + eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "NormalMap.txt"), + printInList, ref forTests, listChar); + Assert.True(forTests.SequenceEqual(listCheck)); + } + + [TestCaseSource(nameof(GameForTest))] + public void TheCharacterMustWalkCorrectlyToTheRight(Game game) + { + EventLoop eventLoop = new EventLoop(); + var printInList = new PrintInList(); + var forTests = new List<((int, int), char)>(); + var listChar = new List(); + listChar.Add((char)39); + var listCheck = new List<((int, int), char)>(); + listCheck.Add(((8, 3), '\0')); + listCheck.Add(((-1, -1), '@')); + listCheck.Add(((8, 3), '\0')); + listCheck.Add(((-1, -1), ' ')); + listCheck.Add(((9, 3), '\0')); + listCheck.Add(((-1, -1), '@')); + listCheck.Add(((9, 3), '\0')); + eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "NormalMap.txt"), + printInList, ref forTests, listChar); + Assert.True(forTests.SequenceEqual(listCheck)); + } + + [TestCaseSource(nameof(GameForTest))] + public void TheCharacterMustWalkCorrectlyToTheDown(Game game) + { + EventLoop eventLoop = new EventLoop(); + var printInList = new PrintInList(); + var forTests = new List<((int, int), char)>(); + var listChar = new List(); + listChar.Add((char)40); + var listCheck = new List<((int, int), char)>(); + listCheck.Add(((8, 3), '\0')); + listCheck.Add(((-1, -1), '@')); + listCheck.Add(((8, 3), '\0')); + listCheck.Add(((-1, -1), ' ')); + listCheck.Add(((8, 4), '\0')); + listCheck.Add(((-1, -1), '@')); + listCheck.Add(((8, 4), '\0')); + eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "NormalMap.txt"), + printInList, ref forTests, listChar); + Assert.True(forTests.SequenceEqual(listCheck)); + } + + [TestCaseSource(nameof(GameForTest))] + public void TheCharacterMustNotWalkIfPressedIncorrectKey(Game game) + { + EventLoop eventLoop = new EventLoop(); + var printInList = new PrintInList(); + var forTests = new List<((int, int), char)>(); + var listChar = new List(); + listChar.Add('b'); + var listCheck = new List<((int, int), char)>(); + listCheck.Add(((8, 3), '\0')); + listCheck.Add(((-1, -1), '@')); + listCheck.Add(((8, 3), '\0')); + eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "NormalMap.txt"), + printInList, ref forTests, listChar); + Assert.True(forTests.SequenceEqual(listCheck)); + } + + [TestCaseSource(nameof(GameForTest))] + public void TheCharacterMustNotWalkIfItRestsAgainstTheWallWhenWalkingToTheLeft(Game game) + { + EventLoop eventLoop = new EventLoop(); + var printInList = new PrintInList(); + var forTests = new List<((int, int), char)>(); + var listChar = new List(); + listChar.Add((char)37); + var listCheck = new List<((int, int), char)>(); + listCheck.Add(((1, 1), '\0')); + listCheck.Add(((-1, -1), '@')); + listCheck.Add(((1, 1), '\0')); + eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "MapWithCloseWalls.txt"), + printInList, ref forTests, listChar); + Assert.True(forTests.SequenceEqual(listCheck)); + } + + [TestCaseSource(nameof(GameForTest))] + public void TheCharacterMustNotWalkIfItRestsAgainstTheWallWhenWalkingToTheUp(Game game) + { + EventLoop eventLoop = new EventLoop(); + var printInList = new PrintInList(); + var forTests = new List<((int, int), char)>(); + var listChar = new List(); + listChar.Add((char)38); + var listCheck = new List<((int, int), char)>(); + listCheck.Add(((1, 1), '\0')); + listCheck.Add(((-1, -1), '@')); + listCheck.Add(((1, 1), '\0')); + eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "MapWithCloseWalls.txt"), + printInList, ref forTests, listChar); + Assert.True(forTests.SequenceEqual(listCheck)); + } + + [TestCaseSource(nameof(GameForTest))] + public void TheCharacterMustNotWalkIfItRestsAgainstTheWallWhenWalkingToTheRight(Game game) + { + EventLoop eventLoop = new EventLoop(); + var printInList = new PrintInList(); + var forTests = new List<((int, int), char)>(); + var listChar = new List(); + listChar.Add((char)39); + var listCheck = new List<((int, int), char)>(); + listCheck.Add(((1, 1), '\0')); + listCheck.Add(((-1, -1), '@')); + listCheck.Add(((1, 1), '\0')); + eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "MapWithCloseWalls.txt"), + printInList, ref forTests, listChar); + Assert.True(forTests.SequenceEqual(listCheck)); + } + + + [TestCaseSource(nameof(GameForTest))] + public void TheCharacterMustNotWalkIfItRestsAgainstTheWallWhenWalkingToTheDown(Game game) + { + EventLoop eventLoop = new EventLoop(); + var printInList = new PrintInList(); + var forTests = new List<((int, int), char)>(); + var listChar = new List(); + listChar.Add((char)40); + var listCheck = new List<((int, int), char)>(); + listCheck.Add(((1, 1), '\0')); + listCheck.Add(((-1, -1), '@')); + listCheck.Add(((1, 1), '\0')); + eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "MapWithCloseWalls.txt"), + printInList, ref forTests, listChar); + Assert.True(forTests.SequenceEqual(listCheck)); + } + + private static IEnumerable GameForTest + => new TestCaseData[] + { + new TestCaseData(new Game()) + }; +} \ No newline at end of file diff --git a/Game/TestsForGame/TestsForGame.csproj b/Game/TestsForGame/TestsForGame.csproj new file mode 100644 index 0000000..98dc0cf --- /dev/null +++ b/Game/TestsForGame/TestsForGame.csproj @@ -0,0 +1,23 @@ + + + + net7.0 + enable + enable + + false + + + + + + + + + + + + + + + diff --git a/Game/TestsForGame/Usings.cs b/Game/TestsForGame/Usings.cs new file mode 100644 index 0000000..cefced4 --- /dev/null +++ b/Game/TestsForGame/Usings.cs @@ -0,0 +1 @@ +global using NUnit.Framework; \ No newline at end of file diff --git a/Game/TestsForGame/bin/Debug/net7.0/TestsForGame/IncorrectMapWithIncorrectSymbol.txt b/Game/TestsForGame/bin/Debug/net7.0/TestsForGame/IncorrectMapWithIncorrectSymbol.txt new file mode 100644 index 0000000..9e73731 --- /dev/null +++ b/Game/TestsForGame/bin/Debug/net7.0/TestsForGame/IncorrectMapWithIncorrectSymbol.txt @@ -0,0 +1,3 @@ +@@@@@ +@ d @ +@@@@@ \ No newline at end of file diff --git a/Game/TestsForGame/bin/Debug/net7.0/TestsForGame/IncorrectMapWithToSmallSize.txt b/Game/TestsForGame/bin/Debug/net7.0/TestsForGame/IncorrectMapWithToSmallSize.txt new file mode 100644 index 0000000..c13cf5f --- /dev/null +++ b/Game/TestsForGame/bin/Debug/net7.0/TestsForGame/IncorrectMapWithToSmallSize.txt @@ -0,0 +1,2 @@ +@@ +@@ \ No newline at end of file diff --git a/Game/TestsForGame/bin/Debug/net7.0/TestsForGame/MapWithCloseWalls.txt b/Game/TestsForGame/bin/Debug/net7.0/TestsForGame/MapWithCloseWalls.txt new file mode 100644 index 0000000..10af905 --- /dev/null +++ b/Game/TestsForGame/bin/Debug/net7.0/TestsForGame/MapWithCloseWalls.txt @@ -0,0 +1,3 @@ +@@@ +@ @ +@@@ \ No newline at end of file diff --git a/Game/TestsForGame/bin/Debug/net7.0/TestsForGame/NormalMap.txt b/Game/TestsForGame/bin/Debug/net7.0/TestsForGame/NormalMap.txt new file mode 100644 index 0000000..7befade --- /dev/null +++ b/Game/TestsForGame/bin/Debug/net7.0/TestsForGame/NormalMap.txt @@ -0,0 +1,7 @@ +@@@@@@@@@@@@@@@@@ +@ @ +@ @ +@ @ +@ @ +@ @ +@@@@@@@@@@@@@@@@@ \ No newline at end of file From 70940e7b5982db59c0931f620e6c19dd5707e498 Mon Sep 17 00:00:00 2001 From: Artem Date: Fri, 26 May 2023 00:40:15 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=9F=D1=80=D0=B5=D0=B4=D1=80=D0=B5=D0=B2?= =?UTF-8?q?=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Game/Game/EventLoop.cs | 40 +++++++------- Game/Game/Game.cs | 10 ++-- Game/Game/InvalidMapException.cs | 3 + Game/Game/PrintInConsole.cs | 3 +- Game/Game/PrintInList.cs | 8 +-- Game/Game/Program.cs | 13 ++--- Game/Game/WorkWithConsole.cs | 2 +- Game/TestsForGame/TestsForGame.cs | 91 +++++++++++-------------------- 8 files changed, 73 insertions(+), 97 deletions(-) diff --git a/Game/Game/EventLoop.cs b/Game/Game/EventLoop.cs index 30d3e54..18baf86 100644 --- a/Game/Game/EventLoop.cs +++ b/Game/Game/EventLoop.cs @@ -5,7 +5,7 @@ /// /// Event handler implementation class /// -public class EventLoop +public static class EventLoop { /// /// Event Handler @@ -20,58 +20,58 @@ public class EventLoop /// List of commands for tests ONLY /// Incorrectly set map /// Checking that the read card line is not empty - public void Run(ArrowHandler left, ArrowHandler right, ArrowHandler up, ArrowHandler down, + public static void Run(ArrowHandler left, ArrowHandler right, ArrowHandler up, ArrowHandler down, string fileWithMap, WorkWithConsole data, ref List<((int, int), char)> forTests, List listKeys = null) { - int sizeLong = 0; - int sizeWidth = 0; + int length = 0; + int width = 0; var file = new StreamReader(fileWithMap); - int sizeDogSymbols = 0; + int sizeAtSymbols = 0; int sizeSpaces = 0; bool isFirst = true; while (!file.EndOfStream) { if (!isFirst) { - if (sizeWidth == 1 && sizeDogSymbols != sizeLong) + if (width == 1 && sizeAtSymbols != length) { throw new InvalidMapException(); } - else if (sizeWidth != 1 && sizeDogSymbols != 2 || sizeSpaces != sizeLong - sizeDogSymbols) + else if (width != 1 && sizeAtSymbols != 2 || sizeSpaces != length - sizeAtSymbols) { throw new InvalidMapException(); } } var line = file.ReadLine(); - ++sizeWidth; - int size = line.Count(x => x == '@'); + ++width; if (line == null) { - throw new NullReferenceException(); + throw new ArgumentException(); } - if (sizeLong != 0 && sizeLong != line.Length) + int size = line.Count(x => x == '@'); + if (length != 0 && length != line.Length) { throw new InvalidMapException(); } - sizeLong = line.Length; - sizeDogSymbols = line.Count(x => x == '@'); + length = line.Length; + sizeAtSymbols = line.Count(x => x == '@'); sizeSpaces = line.Count(x => x == ' '); isFirst = false; Console.WriteLine(line); } - if (sizeDogSymbols != sizeLong) + if (sizeAtSymbols != length) { throw new InvalidMapException(); } - if (sizeWidth < 3 || sizeLong < 3) + if (width < 3 || length < 3) { throw new InvalidMapException(); } - data.SetCursorPosition(sizeLong / 2, sizeWidth / 2, ref forTests); + data.SetCursorPosition(length / 2, width / 2, ref forTests); data.Print('@', ref forTests); - int startPositionLeft = sizeLong / 2; - int startPositionTop = sizeWidth / 2; + int startPositionLeft = length / 2; + int startPositionTop = width / 2; data.SetCursorPosition(startPositionLeft, startPositionTop, ref forTests); var checkType = new PrintInList(); while (true) @@ -91,7 +91,7 @@ public void Run(ArrowHandler left, ArrowHandler right, ArrowHandler up, ArrowHan } break; case "right": - if (startPositionLeft != sizeLong - 2) + if (startPositionLeft != length - 2) { right(startPositionLeft, startPositionTop, data, ref forTests); ++startPositionLeft; @@ -105,7 +105,7 @@ public void Run(ArrowHandler left, ArrowHandler right, ArrowHandler up, ArrowHan } break; case "down": - if (startPositionTop != sizeWidth - 2) + if (startPositionTop != width - 2) { down(startPositionLeft, startPositionTop, data, ref forTests); ++startPositionTop; diff --git a/Game/Game/Game.cs b/Game/Game/Game.cs index 66b2426..e882bb7 100644 --- a/Game/Game/Game.cs +++ b/Game/Game/Game.cs @@ -3,7 +3,7 @@ /// /// A class that implements actions in the game /// -public class Game +public static class Game { /// /// Move to the Left @@ -12,7 +12,7 @@ public class Game /// Y coordinate /// Selected type: testing or normal launch /// The list of entering results for tests ONLY - public void OnLeft(int startPositionLeft, int startPositionTop, WorkWithConsole data, ref List<((int, int), char)> forTests) + public static void OnLeft(int startPositionLeft, int startPositionTop, WorkWithConsole data, ref List<((int, int), char)> forTests) { data.Print(' ', ref forTests); data.SetCursorPosition(startPositionLeft - 1, startPositionTop, ref forTests); @@ -27,7 +27,7 @@ public void OnLeft(int startPositionLeft, int startPositionTop, WorkWithConsole /// Y coordinate /// Selected type: testing or normal launch /// The list of entering results for tests ONLY - public void OnRight(int startPositionLeft, int startPositionTop, WorkWithConsole data, ref List<((int, int), char)> forTests) + public static void OnRight(int startPositionLeft, int startPositionTop, WorkWithConsole data, ref List<((int, int), char)> forTests) { data.Print(' ', ref forTests); data.SetCursorPosition(startPositionLeft + 1, startPositionTop, ref forTests); @@ -42,7 +42,7 @@ public void OnRight(int startPositionLeft, int startPositionTop, WorkWithConsole /// Y coordinate /// Selected type: testing or normal launch /// The list of entering results for tests ONLY - public void OnUp(int startPositionLeft, int startPositionTop, WorkWithConsole data, ref List<((int, int), char)> forTests) + public static void OnUp(int startPositionLeft, int startPositionTop, WorkWithConsole data, ref List<((int, int), char)> forTests) { data.Print(' ', ref forTests); data.SetCursorPosition(startPositionLeft, startPositionTop - 1, ref forTests); @@ -57,7 +57,7 @@ public void OnUp(int startPositionLeft, int startPositionTop, WorkWithConsole da /// Y coordinate /// Selected type: testing or normal launch /// The list of entering results for tests ONLY - public void OnDown(int startPositionLeft, int startPositionTop, WorkWithConsole data, ref List<((int, int), char)> forTests) + public static void OnDown(int startPositionLeft, int startPositionTop, WorkWithConsole data, ref List<((int, int), char)> forTests) { data.Print(' ', ref forTests); data.SetCursorPosition(startPositionLeft, startPositionTop + 1, ref forTests); diff --git a/Game/Game/InvalidMapException.cs b/Game/Game/InvalidMapException.cs index 7e79dfa..bd07809 100644 --- a/Game/Game/InvalidMapException.cs +++ b/Game/Game/InvalidMapException.cs @@ -1,3 +1,6 @@ namespace Game; +/// +/// Throws exception then incorrect input map +/// public class InvalidMapException : Exception {} \ No newline at end of file diff --git a/Game/Game/PrintInConsole.cs b/Game/Game/PrintInConsole.cs index a3df434..77ec662 100644 --- a/Game/Game/PrintInConsole.cs +++ b/Game/Game/PrintInConsole.cs @@ -3,7 +3,7 @@ /// /// Implements an interface for tests /// -public class PrintInConsole:WorkWithConsole +public class PrintInConsole : WorkWithConsole { public override void Print(char symbol, ref List<((int, int), char)> forTests) { @@ -30,6 +30,5 @@ public override string Comparison(List listKeys = null) return "down"; } return "another"; - } } \ No newline at end of file diff --git a/Game/Game/PrintInList.cs b/Game/Game/PrintInList.cs index 3b256cf..886eafd 100644 --- a/Game/Game/PrintInList.cs +++ b/Game/Game/PrintInList.cs @@ -33,13 +33,13 @@ public override string Comparison(List listKeys = null) listKeys.RemoveAt(0); switch (key) { - case (char)37: + case '%': return "left"; - case (char)38: + case '&': return "up"; - case (char)39: + case '\'': return "right"; - case (char)40: + case '(': return "down"; } return "another"; diff --git a/Game/Game/Program.cs b/Game/Game/Program.cs index f060430..99bfd94 100644 --- a/Game/Game/Program.cs +++ b/Game/Game/Program.cs @@ -4,19 +4,18 @@ public class Program { public static void Main() { - var game = new Game(); - var eventLoop = new EventLoop(); + char symbol = (char)38; Console.WriteLine("Input your string with file path"); var filePath = Console.ReadLine(); Console.Clear(); List<((int, int), char)> list = new List<((int, int), char)>(); try { - eventLoop.Run( - new ArrowHandler(game.OnLeft), - new ArrowHandler(game.OnRight), - new ArrowHandler(game.OnUp), - new ArrowHandler(game.OnDown), + EventLoop.Run( + new ArrowHandler(Game.OnLeft), + new ArrowHandler(Game.OnRight), + new ArrowHandler(Game.OnUp), + new ArrowHandler(Game.OnDown), filePath, new PrintInConsole(), ref list diff --git a/Game/Game/WorkWithConsole.cs b/Game/Game/WorkWithConsole.cs index 12388ca..82b9703 100644 --- a/Game/Game/WorkWithConsole.cs +++ b/Game/Game/WorkWithConsole.cs @@ -3,7 +3,7 @@ /// /// Ancestor of two implementation classes one for tests the other for use /// -abstract public class WorkWithConsole:GameInterface +abstract public class WorkWithConsole : GameInterface { virtual public void Print(char symbol, ref List<((int, int), char)> forTests) { } diff --git a/Game/TestsForGame/TestsForGame.cs b/Game/TestsForGame/TestsForGame.cs index 2776588..67df676 100644 --- a/Game/TestsForGame/TestsForGame.cs +++ b/Game/TestsForGame/TestsForGame.cs @@ -5,34 +5,23 @@ namespace TestsForGame; public class Tests { - Game game; - - [SetUp] - public void Setup() - { - game = new Game(); - } - - [TestCaseSource(nameof(GameForTest))] - public void TheIncorrectMapWithIncorrectSymbolShouldThrowException(Game game) + [Test] + public void TheIncorrectMapWithIncorrectSymbolShouldThrowException() { - EventLoop eventLoop = new EventLoop(); var forTests = new List<((int, int), char)>(); - Assert.Throws(() => eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "IncorrectMapWithIncorrectSymbol.txt"), new PrintInList(), ref forTests)); + Assert.Throws(() => EventLoop.Run(Game.OnLeft, Game.OnRight, Game.OnUp, Game.OnDown, Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "IncorrectMapWithIncorrectSymbol.txt"), new PrintInList(), ref forTests)); } - [TestCaseSource(nameof(GameForTest))] - public void TheIncorrectMapWithTooSmallSizeShouldThrowException(Game game) + [Test] + public void TheIncorrectMapWithTooSmallSizeShouldThrowException() { - EventLoop eventLoop = new EventLoop(); var forTests = new List<((int, int), char)>(); - Assert.Throws(() => eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "IncorrectMapWithToSmallSize.txt"), new PrintInList(), ref forTests)); + Assert.Throws(() => EventLoop.Run(Game.OnLeft, Game.OnRight, Game.OnUp, Game.OnDown, Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "IncorrectMapWithToSmallSize.txt"), new PrintInList(), ref forTests)); } - [TestCaseSource(nameof(GameForTest))] - public void TheCharacterMustWalkCorrectlyToTheLeft(Game game) + [Test] + public void TheCharacterMustWalkCorrectlyToTheLeft() { - EventLoop eventLoop = new EventLoop(); var printInList = new PrintInList(); var forTests = new List<((int, int), char)>(); var listChar = new List(); @@ -45,16 +34,15 @@ public void TheCharacterMustWalkCorrectlyToTheLeft(Game game) listCheck.Add(((7, 3), '\0')); listCheck.Add(((-1, -1), '@')); listCheck.Add(((7, 3), '\0')); - eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + EventLoop.Run(Game.OnLeft, Game.OnRight, Game.OnUp, Game.OnDown, Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "NormalMap.txt"), printInList, ref forTests, listChar); Assert.True(forTests.SequenceEqual(listCheck)); } - [TestCaseSource(nameof(GameForTest))] - public void TheCharacterMustWalkCorrectlyToTheUp(Game game) + [Test] + public void TheCharacterMustWalkCorrectlyToTheUp() { - EventLoop eventLoop = new EventLoop(); var printInList = new PrintInList(); var forTests = new List<((int, int), char)>(); var listChar = new List(); @@ -67,16 +55,15 @@ public void TheCharacterMustWalkCorrectlyToTheUp(Game game) listCheck.Add(((8, 2), '\0')); listCheck.Add(((-1, -1), '@')); listCheck.Add(((8, 2), '\0')); - eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + EventLoop.Run(Game.OnLeft, Game.OnRight, Game.OnUp, Game.OnDown, Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "NormalMap.txt"), printInList, ref forTests, listChar); Assert.True(forTests.SequenceEqual(listCheck)); } - [TestCaseSource(nameof(GameForTest))] - public void TheCharacterMustWalkCorrectlyToTheRight(Game game) + [Test] + public void TheCharacterMustWalkCorrectlyToTheRight() { - EventLoop eventLoop = new EventLoop(); var printInList = new PrintInList(); var forTests = new List<((int, int), char)>(); var listChar = new List(); @@ -89,16 +76,15 @@ public void TheCharacterMustWalkCorrectlyToTheRight(Game game) listCheck.Add(((9, 3), '\0')); listCheck.Add(((-1, -1), '@')); listCheck.Add(((9, 3), '\0')); - eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + EventLoop.Run(Game.OnLeft, Game.OnRight, Game.OnUp, Game.OnDown, Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "NormalMap.txt"), printInList, ref forTests, listChar); Assert.True(forTests.SequenceEqual(listCheck)); } - [TestCaseSource(nameof(GameForTest))] - public void TheCharacterMustWalkCorrectlyToTheDown(Game game) + [Test] + public void TheCharacterMustWalkCorrectlyToTheDown() { - EventLoop eventLoop = new EventLoop(); var printInList = new PrintInList(); var forTests = new List<((int, int), char)>(); var listChar = new List(); @@ -111,16 +97,15 @@ public void TheCharacterMustWalkCorrectlyToTheDown(Game game) listCheck.Add(((8, 4), '\0')); listCheck.Add(((-1, -1), '@')); listCheck.Add(((8, 4), '\0')); - eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + EventLoop.Run(Game.OnLeft, Game.OnRight, Game.OnUp, Game.OnDown, Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "NormalMap.txt"), printInList, ref forTests, listChar); Assert.True(forTests.SequenceEqual(listCheck)); } - [TestCaseSource(nameof(GameForTest))] - public void TheCharacterMustNotWalkIfPressedIncorrectKey(Game game) + [Test] + public void TheCharacterMustNotWalkIfPressedIncorrectKey() { - EventLoop eventLoop = new EventLoop(); var printInList = new PrintInList(); var forTests = new List<((int, int), char)>(); var listChar = new List(); @@ -129,16 +114,15 @@ public void TheCharacterMustNotWalkIfPressedIncorrectKey(Game game) listCheck.Add(((8, 3), '\0')); listCheck.Add(((-1, -1), '@')); listCheck.Add(((8, 3), '\0')); - eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + EventLoop.Run(Game.OnLeft, Game.OnRight, Game.OnUp, Game.OnDown, Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "NormalMap.txt"), printInList, ref forTests, listChar); Assert.True(forTests.SequenceEqual(listCheck)); } - [TestCaseSource(nameof(GameForTest))] - public void TheCharacterMustNotWalkIfItRestsAgainstTheWallWhenWalkingToTheLeft(Game game) + [Test] + public void TheCharacterMustNotWalkIfItRestsAgainstTheWallWhenWalkingToTheLeft() { - EventLoop eventLoop = new EventLoop(); var printInList = new PrintInList(); var forTests = new List<((int, int), char)>(); var listChar = new List(); @@ -147,16 +131,15 @@ public void TheCharacterMustNotWalkIfItRestsAgainstTheWallWhenWalkingToTheLeft(G listCheck.Add(((1, 1), '\0')); listCheck.Add(((-1, -1), '@')); listCheck.Add(((1, 1), '\0')); - eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + EventLoop.Run(Game.OnLeft, Game.OnRight, Game.OnUp, Game.OnDown, Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "MapWithCloseWalls.txt"), printInList, ref forTests, listChar); Assert.True(forTests.SequenceEqual(listCheck)); } - [TestCaseSource(nameof(GameForTest))] - public void TheCharacterMustNotWalkIfItRestsAgainstTheWallWhenWalkingToTheUp(Game game) + [Test] + public void TheCharacterMustNotWalkIfItRestsAgainstTheWallWhenWalkingToTheUp() { - EventLoop eventLoop = new EventLoop(); var printInList = new PrintInList(); var forTests = new List<((int, int), char)>(); var listChar = new List(); @@ -165,16 +148,15 @@ public void TheCharacterMustNotWalkIfItRestsAgainstTheWallWhenWalkingToTheUp(Gam listCheck.Add(((1, 1), '\0')); listCheck.Add(((-1, -1), '@')); listCheck.Add(((1, 1), '\0')); - eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + EventLoop.Run(Game.OnLeft, Game.OnRight, Game.OnUp, Game.OnDown, Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "MapWithCloseWalls.txt"), printInList, ref forTests, listChar); Assert.True(forTests.SequenceEqual(listCheck)); } - [TestCaseSource(nameof(GameForTest))] - public void TheCharacterMustNotWalkIfItRestsAgainstTheWallWhenWalkingToTheRight(Game game) + [Test] + public void TheCharacterMustNotWalkIfItRestsAgainstTheWallWhenWalkingToTheRight() { - EventLoop eventLoop = new EventLoop(); var printInList = new PrintInList(); var forTests = new List<((int, int), char)>(); var listChar = new List(); @@ -183,17 +165,16 @@ public void TheCharacterMustNotWalkIfItRestsAgainstTheWallWhenWalkingToTheRight( listCheck.Add(((1, 1), '\0')); listCheck.Add(((-1, -1), '@')); listCheck.Add(((1, 1), '\0')); - eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + EventLoop.Run(Game.OnLeft, Game.OnRight, Game.OnUp, Game.OnDown, Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "MapWithCloseWalls.txt"), printInList, ref forTests, listChar); Assert.True(forTests.SequenceEqual(listCheck)); } - [TestCaseSource(nameof(GameForTest))] - public void TheCharacterMustNotWalkIfItRestsAgainstTheWallWhenWalkingToTheDown(Game game) + [Test] + public void TheCharacterMustNotWalkIfItRestsAgainstTheWallWhenWalkingToTheDown() { - EventLoop eventLoop = new EventLoop(); var printInList = new PrintInList(); var forTests = new List<((int, int), char)>(); var listChar = new List(); @@ -202,15 +183,9 @@ public void TheCharacterMustNotWalkIfItRestsAgainstTheWallWhenWalkingToTheDown(G listCheck.Add(((1, 1), '\0')); listCheck.Add(((-1, -1), '@')); listCheck.Add(((1, 1), '\0')); - eventLoop.Run(game.OnLeft, game.OnRight, game.OnUp, game.OnDown, + EventLoop.Run(Game.OnLeft, Game.OnRight, Game.OnUp, Game.OnDown, Path.Combine(TestContext.CurrentContext.TestDirectory, "TestsForGame", "MapWithCloseWalls.txt"), printInList, ref forTests, listChar); Assert.True(forTests.SequenceEqual(listCheck)); } - - private static IEnumerable GameForTest - => new TestCaseData[] - { - new TestCaseData(new Game()) - }; } \ No newline at end of file