From b3e7f8a07a95e74313b2dc573cca4910e6e69b52 Mon Sep 17 00:00:00 2001 From: shannon Date: Fri, 9 Jan 2026 21:26:31 +0200 Subject: [PATCH 1/4] inital commit --- MathGame.ShPet1304/MathGame.ShPet1304.csproj | 10 ++++++++++ MathGame.ShPet1304/Program.cs | 2 ++ 2 files changed, 12 insertions(+) create mode 100644 MathGame.ShPet1304/MathGame.ShPet1304.csproj create mode 100644 MathGame.ShPet1304/Program.cs diff --git a/MathGame.ShPet1304/MathGame.ShPet1304.csproj b/MathGame.ShPet1304/MathGame.ShPet1304.csproj new file mode 100644 index 00000000..ed9781c2 --- /dev/null +++ b/MathGame.ShPet1304/MathGame.ShPet1304.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/MathGame.ShPet1304/Program.cs b/MathGame.ShPet1304/Program.cs new file mode 100644 index 00000000..3751555c --- /dev/null +++ b/MathGame.ShPet1304/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); From c9a66bdef56ccf0cc4f85019252b6a3f61b900b9 Mon Sep 17 00:00:00 2001 From: shannon Date: Fri, 9 Jan 2026 21:27:06 +0200 Subject: [PATCH 2/4] Added math game logic to project --- CodeReviews.Console.MathGame.sln | 24 +++ MathGame.ShPet1304/Program.cs | 297 ++++++++++++++++++++++++++++++- 2 files changed, 319 insertions(+), 2 deletions(-) create mode 100644 CodeReviews.Console.MathGame.sln diff --git a/CodeReviews.Console.MathGame.sln b/CodeReviews.Console.MathGame.sln new file mode 100644 index 00000000..5be8b8ec --- /dev/null +++ b/CodeReviews.Console.MathGame.sln @@ -0,0 +1,24 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.2.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MathGame.ShPet1304", "MathGame.ShPet1304\MathGame.ShPet1304.csproj", "{15C8DC8B-F936-B8DF-56C1-F8BA4440B52A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {15C8DC8B-F936-B8DF-56C1-F8BA4440B52A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {15C8DC8B-F936-B8DF-56C1-F8BA4440B52A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {15C8DC8B-F936-B8DF-56C1-F8BA4440B52A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {15C8DC8B-F936-B8DF-56C1-F8BA4440B52A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5069FF79-FE94-4672-A1FB-8AB6472E82B0} + EndGlobalSection +EndGlobal diff --git a/MathGame.ShPet1304/Program.cs b/MathGame.ShPet1304/Program.cs index 3751555c..1f475c6a 100644 --- a/MathGame.ShPet1304/Program.cs +++ b/MathGame.ShPet1304/Program.cs @@ -1,2 +1,295 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +// **Global Variables** +Random numbers = new Random(); +int leftHandOperand = numbers.Next(1, 101); +int rightHandOperand = numbers.Next(1,101); +int answer; +int newUserAnswer; +int userScore = 0; +int maxRounds = 5; +string? userAnswer; +string result; +bool gameRunning = true; +List gameHistory = new List(); + + + +//--Initialize Game-- +while (gameRunning) +{ +Menu(); +} + + +//--Methods-- + +void Menu( int choice = default) +{ + Console.WriteLine("Choose an option:\n1) Addition Math Questions\n2) Subtraction Math Questions\n3) Multiplication Math Questions\n4) Division Math Questions\n5) Random Operator Math Questions\n6) Game History\n7) Exit"); + + string? menuSelection = Console.ReadLine(); + + if (menuSelection != null) + { + int.TryParse(menuSelection, out choice); + + switch (choice) + { + case 1: + GameMode("addition"); + break; + + case 2: + GameMode("subtraction"); + + break; + + case 3: + GameMode("multiplication"); + + break; + + case 4: + GameMode("division"); + + break; + + case 5: + Console.Clear(); + Random option = new Random(); + Console.WriteLine("Random Math Game:"); + for(int i = 0; i < maxRounds; i++){ + int randomOperation = option.Next(1,5); + switch (randomOperation) + { + case 1: + GameMode("addition"); + break; + + case 2: + GameMode("subtraction"); + break; + + case 3: + GameMode("multiplication"); + break; + + case 4: + GameMode("division"); + break; + + default: + ReturnToMenu(); + break; + } + } + break; + + case 6: + GameRecords(); + ReturnToMenu(); + break; + + case 7: + gameRunning = false; + Console.WriteLine("Goodbye :)"); + break; + + default: + Console.WriteLine("Enter a number option"); + ReturnToMenu(); + break; + + + } + } +} + +void GameMode(string mode) +{ + switch(mode){ + + case "addition": + Console.WriteLine("Addition Math Game:"); + for(int i = 0; i < maxRounds; i++){ + + leftHandOperand = numbers.Next(1, 101); + rightHandOperand = numbers.Next(1,101); + + answer = leftHandOperand + rightHandOperand; + + Console.WriteLine( $"{leftHandOperand} + {rightHandOperand} = ??" ); + + userAnswer = Console.ReadLine(); + int.TryParse(userAnswer, out newUserAnswer); + if (newUserAnswer == answer) + { + userScore += 1; + Console.WriteLine($"Correct {leftHandOperand} + {rightHandOperand} = {answer}"); + result = "Win"; + } + + else + {Console.WriteLine($"Wrong. The Answer is {answer}"); + result = "Lose"; + } + + + gameHistory.Add(new object[] { + $"{leftHandOperand} + {rightHandOperand}", + answer, + result }); + } + + Console.WriteLine($"Game Over\nYour Final score is: {userScore}/5"); + ReturnToMenu(); + userScore = 0; + break; + + case "subtraction": + Console.WriteLine("Subtraction Math Game:"); + for(int i = 0; i < maxRounds; i++){ + + leftHandOperand = numbers.Next(1, 101); + rightHandOperand = numbers.Next(1,101); + + if (rightHandOperand > leftHandOperand) + { + (leftHandOperand, rightHandOperand) = (rightHandOperand, leftHandOperand); + } + answer = leftHandOperand - rightHandOperand; + Console.WriteLine( $"{leftHandOperand} - {rightHandOperand} = ??" ); + + userAnswer = Console.ReadLine(); + int.TryParse(userAnswer, out newUserAnswer); + + if (newUserAnswer == answer) + { + userScore += 1; + Console.WriteLine($"Correct {leftHandOperand} - {rightHandOperand} = {answer}"); + result = "Win"; + } + + else + { + Console.WriteLine($"Wrong. The Answer is {answer}"); + result = "Lose"; + } + + + gameHistory.Add(new object[] { + $"{leftHandOperand} - {rightHandOperand}", + answer, + result }); + } + Console.WriteLine($"Game Over\nYour Final score is: {userScore}/5"); + userScore = 0; + ReturnToMenu(); + + break; + + case "multiplication": + + for(int i = 0; i < maxRounds; i++) + { + int multiplyLeftHandOperands = numbers.Next(1, 101); + int multiplyRightHandOperands = numbers.Next(1, 101); + answer = multiplyLeftHandOperands * multiplyRightHandOperands; + Console.WriteLine( $"{multiplyLeftHandOperands} * {multiplyRightHandOperands} = ??" ); + userAnswer = Console.ReadLine(); + int.TryParse(userAnswer, out newUserAnswer); + if (newUserAnswer == answer) + { + userScore += 1; + Console.WriteLine($"Correct {multiplyLeftHandOperands} * {multiplyRightHandOperands} = {answer}"); + result = "Win"; + } + + else { + Console.WriteLine($"Wrong. The Answer is {answer}"); + result = "Lose"; + } + gameHistory.Add(new object[] { + $"{multiplyLeftHandOperands} * {multiplyRightHandOperands}", + answer, + result }); + + + } + + + Console.WriteLine($"Game Over\nYour Final score is: {userScore}/5"); + ReturnToMenu(); + userScore = 0; + break; + + case "division": + + for(int i = 0; i < maxRounds; i++) + { + int dividend; + int divisor; + + + do{ + dividend = numbers.Next(1, 101); + divisor = numbers.Next(1, 101); + + } while(dividend % divisor != 0 || dividend < divisor); + + answer = dividend / divisor; + + Console.WriteLine( $"{dividend} / {divisor} = ??" ); + userAnswer = Console.ReadLine(); + int.TryParse(userAnswer, out newUserAnswer); + if (newUserAnswer == answer) + { + userScore += 1; + Console.WriteLine($"Correct {dividend} / {divisor} = {answer}"); + result = "Win"; + } + + else { + Console.WriteLine($"Wrong. The Answer is {answer}"); + result = "Lose"; + } + + gameHistory.Add(new object[] { + $"{dividend} / {divisor}", + answer, + result }); + + } + + + Console.WriteLine($"Game Over\nYour Final score is: {userScore}/5"); + ReturnToMenu(); + userScore = 0; + break; + } + } + + +void ReturnToMenu() +{ + Console.WriteLine("Press Enter to return to the Main Menu."); + Console.ReadLine(); + Console.Clear(); + Console.Write("\x1b[3J"); + Console.Clear(); + Menu(); +} + + + + +void GameRecords() +{ + Console.WriteLine("\n\tHistory Table:\n"); + Console.WriteLine("Problem\t\tAnswer\t\tResult"); + foreach (object[] game in gameHistory) +{ + Console.WriteLine($"{game[0]}\t\t{game[1]}\t\t{game[2]}"); +} +Console.WriteLine(); + +} From a8cddce9cec28e7c65bd0e979514fdcc3b5aa9b3 Mon Sep 17 00:00:00 2001 From: shannon Date: Fri, 9 Jan 2026 21:40:17 +0200 Subject: [PATCH 3/4] fix recomended issues --- MathGame.ShPet1304/Program.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MathGame.ShPet1304/Program.cs b/MathGame.ShPet1304/Program.cs index 1f475c6a..5340b92c 100644 --- a/MathGame.ShPet1304/Program.cs +++ b/MathGame.ShPet1304/Program.cs @@ -6,6 +6,7 @@ int newUserAnswer; int userScore = 0; int maxRounds = 5; + int choice; string? userAnswer; string result; bool gameRunning = true; @@ -22,7 +23,7 @@ //--Methods-- -void Menu( int choice = default) +void Menu() { Console.WriteLine("Choose an option:\n1) Addition Math Questions\n2) Subtraction Math Questions\n3) Multiplication Math Questions\n4) Division Math Questions\n5) Random Operator Math Questions\n6) Game History\n7) Exit"); From 1a97f0ded7403689c9bc7f01342241a05c3cf883 Mon Sep 17 00:00:00 2001 From: shannon Date: Fri, 9 Jan 2026 21:44:31 +0200 Subject: [PATCH 4/4] fix issues --- MathGame.ShPet1304/Program.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MathGame.ShPet1304/Program.cs b/MathGame.ShPet1304/Program.cs index 5340b92c..1f475c6a 100644 --- a/MathGame.ShPet1304/Program.cs +++ b/MathGame.ShPet1304/Program.cs @@ -6,7 +6,6 @@ int newUserAnswer; int userScore = 0; int maxRounds = 5; - int choice; string? userAnswer; string result; bool gameRunning = true; @@ -23,7 +22,7 @@ //--Methods-- -void Menu() +void Menu( int choice = default) { Console.WriteLine("Choose an option:\n1) Addition Math Questions\n2) Subtraction Math Questions\n3) Multiplication Math Questions\n4) Division Math Questions\n5) Random Operator Math Questions\n6) Game History\n7) Exit");