From 8f613a02374dbf2b400b9512ad3f823625c9113f Mon Sep 17 00:00:00 2001 From: epvanhouten Date: Sat, 27 Feb 2021 19:19:32 -0600 Subject: [PATCH] Introduce domain object for ponts Game is centered around comparing an X,Y point to another X,Y point. Introduced a domain object to represent that pairing. --- 51 Hurkle/csharp/src/hurkle/HurkleGame.cs | 34 +++++++++++++++-------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/51 Hurkle/csharp/src/hurkle/HurkleGame.cs b/51 Hurkle/csharp/src/hurkle/HurkleGame.cs index 7abeaad5..38d1a158 100644 --- a/51 Hurkle/csharp/src/hurkle/HurkleGame.cs +++ b/51 Hurkle/csharp/src/hurkle/HurkleGame.cs @@ -19,8 +19,10 @@ namespace hurkle // BASIC program was generating a float between 0 and 1 // then multiplying by the size of the grid to to a number // between 1 and 10. C# allows you to do that directly. - var A = _random.Next(0,gridSize); - var B = _random.Next(0,gridSize); + var hurklePoint = new GamePoint{ + X = _random.Next(0, gridSize), + Y = _random.Next(0, gridSize) + }; /* 310 FOR K=1 TO N @@ -37,9 +39,11 @@ namespace hurkle Console.WriteLine($"GUESS #{K}"); var inputLine = Console.ReadLine(); var seperateStrings = inputLine.Split(',', 2, StringSplitOptions.TrimEntries); - var X = int.Parse(seperateStrings[0]); - var Y = int.Parse(seperateStrings[1]); - if(Math.Abs(X-A) + Math.Abs(Y-B) == 0) + var guessPoint = new GamePoint{ + X = int.Parse(seperateStrings[0]), + Y = int.Parse(seperateStrings[1]) + }; + if(Math.Abs(guessPoint.X-hurklePoint.X) + Math.Abs(guessPoint.Y-hurklePoint.Y) == 0) { /* 500 REM @@ -52,7 +56,7 @@ namespace hurkle return; } - PrintInfo(X,Y,A,B); + PrintInfo(guessPoint,hurklePoint); } /* @@ -62,10 +66,10 @@ namespace hurkle */ Console.WriteLine(); Console.WriteLine($"SORRY, THAT'S {guesses} GUESSES"); - Console.WriteLine($"THE HURKLE IS AT {A},{B}"); + Console.WriteLine($"THE HURKLE IS AT {hurklePoint.X},{hurklePoint.Y}"); } - private static void PrintInfo(int X, int Y, int A, int B) + private static void PrintInfo(GamePoint guess, GamePoint target) { /* @@ -79,10 +83,10 @@ namespace hurkle 650 GO TO 670 660 PRINT "NORTH"; */ - if(Y>B) + if(guess.Y>target.Y) { Console.Write("SOUTH"); - }else if(YA) + }else if(guess.X>target.X) { Console.Write("WEST"); } @@ -107,5 +111,11 @@ namespace hurkle 730 RETURN */ } + + private class GamePoint + { + public int X {get;init;} + public int Y {get;init;} + } } } \ No newline at end of file