From cc3dbfed00daa960af34a7cf3fe562b07acc8fc8 Mon Sep 17 00:00:00 2001 From: Ryan Craig <8675007+rcraig14@users.noreply.github.com> Date: Sun, 15 Feb 2026 13:13:09 -0600 Subject: [PATCH 01/11] Init console app --- .vscode/settings.json | 3 ++ MathGame.rcraig14/MathGame.rcraig14.csproj | 10 +++++++ MathGame.rcraig14/Program.cs | 2 ++ MathGame.sln | 34 ++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 MathGame.rcraig14/MathGame.rcraig14.csproj create mode 100644 MathGame.rcraig14/Program.cs create mode 100644 MathGame.sln diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..2efc0762 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "dotnet.defaultSolution": "MathGame.sln" +} \ No newline at end of file diff --git a/MathGame.rcraig14/MathGame.rcraig14.csproj b/MathGame.rcraig14/MathGame.rcraig14.csproj new file mode 100644 index 00000000..ed9781c2 --- /dev/null +++ b/MathGame.rcraig14/MathGame.rcraig14.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/MathGame.rcraig14/Program.cs b/MathGame.rcraig14/Program.cs new file mode 100644 index 00000000..3751555c --- /dev/null +++ b/MathGame.rcraig14/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/MathGame.sln b/MathGame.sln new file mode 100644 index 00000000..375a7642 --- /dev/null +++ b/MathGame.sln @@ -0,0 +1,34 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MathGame.rcraig14", "MathGame.rcraig14\MathGame.rcraig14.csproj", "{1178E02F-3FDD-4B87-8996-A1EC3AD6BFD7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1178E02F-3FDD-4B87-8996-A1EC3AD6BFD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1178E02F-3FDD-4B87-8996-A1EC3AD6BFD7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1178E02F-3FDD-4B87-8996-A1EC3AD6BFD7}.Debug|x64.ActiveCfg = Debug|Any CPU + {1178E02F-3FDD-4B87-8996-A1EC3AD6BFD7}.Debug|x64.Build.0 = Debug|Any CPU + {1178E02F-3FDD-4B87-8996-A1EC3AD6BFD7}.Debug|x86.ActiveCfg = Debug|Any CPU + {1178E02F-3FDD-4B87-8996-A1EC3AD6BFD7}.Debug|x86.Build.0 = Debug|Any CPU + {1178E02F-3FDD-4B87-8996-A1EC3AD6BFD7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1178E02F-3FDD-4B87-8996-A1EC3AD6BFD7}.Release|Any CPU.Build.0 = Release|Any CPU + {1178E02F-3FDD-4B87-8996-A1EC3AD6BFD7}.Release|x64.ActiveCfg = Release|Any CPU + {1178E02F-3FDD-4B87-8996-A1EC3AD6BFD7}.Release|x64.Build.0 = Release|Any CPU + {1178E02F-3FDD-4B87-8996-A1EC3AD6BFD7}.Release|x86.ActiveCfg = Release|Any CPU + {1178E02F-3FDD-4B87-8996-A1EC3AD6BFD7}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal From 355d2fea22d0899b89607cb04a7b941647760af1 Mon Sep 17 00:00:00 2001 From: Ryan Craig <8675007+rcraig14@users.noreply.github.com> Date: Sun, 15 Feb 2026 21:46:30 -0600 Subject: [PATCH 02/11] Base game logic and data types added --- MathGame.rcraig14/Controlers/GameControler.cs | 57 +++++++++++++++++ .../Controlers/IGameController.cs | 11 ++++ MathGame.rcraig14/Models/Addition.cs | 10 +++ MathGame.rcraig14/Models/Division.cs | 9 +++ MathGame.rcraig14/Models/Multiplication.cs | 9 +++ MathGame.rcraig14/Models/Problem.cs | 23 +++++++ MathGame.rcraig14/Models/SubmittedAnswer.cs | 23 +++++++ MathGame.rcraig14/Models/Subtraction.cs | 9 +++ MathGame.rcraig14/Operation.cs | 47 ++++++++++++++ MathGame.rcraig14/Program.cs | 61 ++++++++++++++++++- 10 files changed, 257 insertions(+), 2 deletions(-) create mode 100644 MathGame.rcraig14/Controlers/GameControler.cs create mode 100644 MathGame.rcraig14/Controlers/IGameController.cs create mode 100644 MathGame.rcraig14/Models/Addition.cs create mode 100644 MathGame.rcraig14/Models/Division.cs create mode 100644 MathGame.rcraig14/Models/Multiplication.cs create mode 100644 MathGame.rcraig14/Models/Problem.cs create mode 100644 MathGame.rcraig14/Models/SubmittedAnswer.cs create mode 100644 MathGame.rcraig14/Models/Subtraction.cs create mode 100644 MathGame.rcraig14/Operation.cs diff --git a/MathGame.rcraig14/Controlers/GameControler.cs b/MathGame.rcraig14/Controlers/GameControler.cs new file mode 100644 index 00000000..f44bc41e --- /dev/null +++ b/MathGame.rcraig14/Controlers/GameControler.cs @@ -0,0 +1,57 @@ +using MathGame.rcraig14.Models; + +namespace MathGame.rcraig14.Controllers; + +public class GameControler : IGameController +{ + + private Problem? CurrentProblem {get; set;} + private List AnswerHistory {get; set;} + private Random _random { + get => _random ?? new Random(); + set => _random = value; + } + + public GameControler(Random random) + { + _random = random; + AnswerHistory = new List(); + } + + public GameControler() + { + AnswerHistory = new List(); + } + + public Problem GenerateProblem(Operation operation) { + CurrentProblem = operation switch + { + Operation.Addition => new Addition(1, 2), + Operation.Subtraction => new Subtraction(2, 1), + Operation.Multiplication => new Multiplication(2, 5), + Operation.Division => new Division(4, 2), + _ => throw new ArgumentOutOfRangeException(nameof(operation), $"Unexpected operation value: {operation}") + }; + + return CurrentProblem; + } + + + public SubmittedAnswer SubmitAnswer(int answer) + { + if(CurrentProblem is null) + { + throw new ArgumentNullException("Problem must be generated before submitting answer"); + } + + var submittedAnswer = new SubmittedAnswer(CurrentProblem, answer); + AnswerHistory.Append(submittedAnswer); + + return submittedAnswer; + } + + public void DisplayProblem() + { + Console.WriteLine(CurrentProblem?.ToString() ?? "Problem needs to be generated"); + } +} diff --git a/MathGame.rcraig14/Controlers/IGameController.cs b/MathGame.rcraig14/Controlers/IGameController.cs new file mode 100644 index 00000000..9ca651b8 --- /dev/null +++ b/MathGame.rcraig14/Controlers/IGameController.cs @@ -0,0 +1,11 @@ +using MathGame.rcraig14.Models; + +namespace MathGame.rcraig14.Controllers; + +public interface IGameController +{ + public Problem GenerateProblem(Operation operation); + public void DisplayProblem(); + public SubmittedAnswer SubmitAnswer(int answer); + +} diff --git a/MathGame.rcraig14/Models/Addition.cs b/MathGame.rcraig14/Models/Addition.cs new file mode 100644 index 00000000..ae806033 --- /dev/null +++ b/MathGame.rcraig14/Models/Addition.cs @@ -0,0 +1,10 @@ +namespace MathGame.rcraig14.Models; + +public class Addition(int pLeft, int pRight) : Problem(pLeft, pRight, Operation.Addition, "+") +{ + + public override int Answer() + { + return Left + Right; + } +} diff --git a/MathGame.rcraig14/Models/Division.cs b/MathGame.rcraig14/Models/Division.cs new file mode 100644 index 00000000..bcc964f7 --- /dev/null +++ b/MathGame.rcraig14/Models/Division.cs @@ -0,0 +1,9 @@ +namespace MathGame.rcraig14.Models; + +public class Division(int pLeft, int pRight) : Problem(pLeft, pRight, Operation.Division, "/") +{ + public override int Answer() + { + return Left / Right; + } +} diff --git a/MathGame.rcraig14/Models/Multiplication.cs b/MathGame.rcraig14/Models/Multiplication.cs new file mode 100644 index 00000000..94b63daa --- /dev/null +++ b/MathGame.rcraig14/Models/Multiplication.cs @@ -0,0 +1,9 @@ +namespace MathGame.rcraig14.Models; + +public class Multiplication(int pLeft, int pRight) : Problem(pLeft, pRight, Operation.Multiplication, "*") +{ + public override int Answer() + { + return Left * Right; + } +} diff --git a/MathGame.rcraig14/Models/Problem.cs b/MathGame.rcraig14/Models/Problem.cs new file mode 100644 index 00000000..ebcf6a73 --- /dev/null +++ b/MathGame.rcraig14/Models/Problem.cs @@ -0,0 +1,23 @@ +namespace MathGame.rcraig14.Models; +public abstract class Problem +{ + protected int Left {get;} + protected int Right {get;} + public Operation Operation {get;} + string OperationString {get;} + + public Problem(int pLeft, int pRight, Operation pOperation, string pOperationString) + { + Left = pLeft; + Right = pRight; + Operation = pOperation; + OperationString = pOperationString; + } + + public abstract int Answer(); + + public override string ToString() + { + return $"{Left} {OperationString} {Right} ="; + } +} diff --git a/MathGame.rcraig14/Models/SubmittedAnswer.cs b/MathGame.rcraig14/Models/SubmittedAnswer.cs new file mode 100644 index 00000000..af8cedcc --- /dev/null +++ b/MathGame.rcraig14/Models/SubmittedAnswer.cs @@ -0,0 +1,23 @@ +using System.Runtime.CompilerServices; + +namespace MathGame.rcraig14.Models; + +public class SubmittedAnswer +{ + public Problem Problem{ get; } + public int Answer { get; } + + + public SubmittedAnswer(Problem problem, int answer) + { + Problem = problem; + Answer = answer; + } + + public bool isCorrect() => Problem.Answer() == Answer; + + public override string ToString() + { + return isCorrect() ? "Answer was correct" : "Answer is incorrect"; + } +} diff --git a/MathGame.rcraig14/Models/Subtraction.cs b/MathGame.rcraig14/Models/Subtraction.cs new file mode 100644 index 00000000..9e487c7b --- /dev/null +++ b/MathGame.rcraig14/Models/Subtraction.cs @@ -0,0 +1,9 @@ +namespace MathGame.rcraig14.Models; + +public class Subtraction(int pLeft, int pRight) : Problem(pLeft, pRight, Operation.Subtraction, "-") +{ + public override int Answer() + { + return Left - Right; + } +} diff --git a/MathGame.rcraig14/Operation.cs b/MathGame.rcraig14/Operation.cs new file mode 100644 index 00000000..637cc9f4 --- /dev/null +++ b/MathGame.rcraig14/Operation.cs @@ -0,0 +1,47 @@ +using System.Collections; + +namespace MathGame.rcraig14; + +public enum Operation +{ + Addition, + Subtraction, + Multiplication, + Division +} + + + +public static class OperationConverter { + + public static Operation StringToOperation(string input) + { + switch(input.ToLower()) { + case "a": + return Operation.Addition; + case "s": + return Operation.Subtraction; + case "m": + return Operation.Multiplication; + case "d": + return Operation.Division; + default: + throw new InvalidOperationException(); + }; + } + +} + +public class InvalidOperationString: Exception +{ + public InvalidOperationString() + { + + } + + public InvalidOperationString(string message) : base(message) + { + + } + +} \ No newline at end of file diff --git a/MathGame.rcraig14/Program.cs b/MathGame.rcraig14/Program.cs index 3751555c..81d8a8bb 100644 --- a/MathGame.rcraig14/Program.cs +++ b/MathGame.rcraig14/Program.cs @@ -1,2 +1,59 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using MathGame.rcraig14; +using MathGame.rcraig14.Controllers; + +Console.WriteLine(@"Welcome to the Math Game! + +Objective: + - Solve as many math problems correctly as you can +"); + +var newProblem = true; +var controller = new GameControler(); + +while(newProblem) +{ + Console.WriteLine(@" + Select a type of problem + - Additon (a) + - Subtraction (s) + - Multipication (m) + - Division (d) + To quit type q" + ); + + var problemType = Console.ReadLine(); + + if(problemType.ToLower() == "q" || problemType.ToLower() == "quit") + { + newProblem = false; + continue; + } + + try + { + var op = OperationConverter.StringToOperation(problemType); + + controller.GenerateProblem(op); + controller.DisplayProblem(); + + Console.Write($"Answer: "); + var strAnswer = Console.ReadLine(); + + if(int.TryParse(strAnswer, out int intOut)) + { + var answer = controller.SubmitAnswer(intOut); + Console.WriteLine(answer.ToString()); + } else + { + Console.WriteLine("Only integers can be submitted for answers"); + continue; + } + + } catch(InvalidOperationException) + { + Console.WriteLine("Please enter a valid value"); + } catch (Exception e) + { + Console.WriteLine($"{e}"); + } +} \ No newline at end of file From 81f75d564dac899d1ed774ecdfee456ce57b0c7e Mon Sep 17 00:00:00 2001 From: Ryan Craig <8675007+rcraig14@users.noreply.github.com> Date: Sun, 15 Feb 2026 22:11:55 -0600 Subject: [PATCH 03/11] Add random problem generator --- MathGame.rcraig14/Controlers/GameControler.cs | 8 ++++---- MathGame.rcraig14/Models/Addition.cs | 6 ++++++ MathGame.rcraig14/Models/Division.cs | 14 ++++++++++++++ MathGame.rcraig14/Models/Multiplication.cs | 6 ++++++ MathGame.rcraig14/Models/SubmittedAnswer.cs | 8 ++++---- MathGame.rcraig14/Models/Subtraction.cs | 14 ++++++++++++++ 6 files changed, 48 insertions(+), 8 deletions(-) diff --git a/MathGame.rcraig14/Controlers/GameControler.cs b/MathGame.rcraig14/Controlers/GameControler.cs index f44bc41e..29757ff3 100644 --- a/MathGame.rcraig14/Controlers/GameControler.cs +++ b/MathGame.rcraig14/Controlers/GameControler.cs @@ -26,10 +26,10 @@ public GameControler() public Problem GenerateProblem(Operation operation) { CurrentProblem = operation switch { - Operation.Addition => new Addition(1, 2), - Operation.Subtraction => new Subtraction(2, 1), - Operation.Multiplication => new Multiplication(2, 5), - Operation.Division => new Division(4, 2), + Operation.Addition => Addition.GenerateRandom(), + Operation.Subtraction => Subtraction.GenerateRandom(), + Operation.Multiplication => Multiplication.GenerateRandom(), + Operation.Division => Division.GenerateRandom(), _ => throw new ArgumentOutOfRangeException(nameof(operation), $"Unexpected operation value: {operation}") }; diff --git a/MathGame.rcraig14/Models/Addition.cs b/MathGame.rcraig14/Models/Addition.cs index ae806033..6c687ec7 100644 --- a/MathGame.rcraig14/Models/Addition.cs +++ b/MathGame.rcraig14/Models/Addition.cs @@ -3,6 +3,12 @@ namespace MathGame.rcraig14.Models; public class Addition(int pLeft, int pRight) : Problem(pLeft, pRight, Operation.Addition, "+") { + public static Addition GenerateRandom() + { + var random = new Random(); + return new Addition(random.Next(0,100), random.Next(0,100)); + } + public override int Answer() { return Left + Right; diff --git a/MathGame.rcraig14/Models/Division.cs b/MathGame.rcraig14/Models/Division.cs index bcc964f7..65e0e6d9 100644 --- a/MathGame.rcraig14/Models/Division.cs +++ b/MathGame.rcraig14/Models/Division.cs @@ -2,6 +2,20 @@ namespace MathGame.rcraig14.Models; public class Division(int pLeft, int pRight) : Problem(pLeft, pRight, Operation.Division, "/") { + + public static Division GenerateRandom() + { + var random = new Random(); + int left = 0, right = 0; + + while(left <= right && (left % right) != 0) + { + left = random.Next(1,100); + right = random.Next(1,99); + } + + return new Division(left, right); + } public override int Answer() { return Left / Right; diff --git a/MathGame.rcraig14/Models/Multiplication.cs b/MathGame.rcraig14/Models/Multiplication.cs index 94b63daa..1c464a3d 100644 --- a/MathGame.rcraig14/Models/Multiplication.cs +++ b/MathGame.rcraig14/Models/Multiplication.cs @@ -6,4 +6,10 @@ public override int Answer() { return Left * Right; } + + public static Multiplication GenerateRandom() + { + var random = new Random(); + return new Multiplication(random.Next(0,100), random.Next(0,100)); + } } diff --git a/MathGame.rcraig14/Models/SubmittedAnswer.cs b/MathGame.rcraig14/Models/SubmittedAnswer.cs index af8cedcc..744698cc 100644 --- a/MathGame.rcraig14/Models/SubmittedAnswer.cs +++ b/MathGame.rcraig14/Models/SubmittedAnswer.cs @@ -5,19 +5,19 @@ namespace MathGame.rcraig14.Models; public class SubmittedAnswer { public Problem Problem{ get; } - public int Answer { get; } + public int UserAnswer { get; } public SubmittedAnswer(Problem problem, int answer) { Problem = problem; - Answer = answer; + UserAnswer = answer; } - public bool isCorrect() => Problem.Answer() == Answer; + public bool isCorrect() => Problem.Answer() == UserAnswer; public override string ToString() { - return isCorrect() ? "Answer was correct" : "Answer is incorrect"; + return isCorrect() ? $"Correct the answer is {Problem.Answer()}" : $"Incorrect the answer is {Problem.Answer()}"; } } diff --git a/MathGame.rcraig14/Models/Subtraction.cs b/MathGame.rcraig14/Models/Subtraction.cs index 9e487c7b..2c36e01f 100644 --- a/MathGame.rcraig14/Models/Subtraction.cs +++ b/MathGame.rcraig14/Models/Subtraction.cs @@ -6,4 +6,18 @@ public override int Answer() { return Left - Right; } + + public static Subtraction GenerateRandom() + { + var random = new Random(); + int left = 0, right = 0; + + while(left <= right) + { + left = random.Next(1,100); + right = random.Next(0,100); + } + + return new Subtraction(left, right); + } } From 570022ec816b08b995b5a1ac7f0a0b06ef7e41f7 Mon Sep 17 00:00:00 2001 From: Ryan Craig <8675007+rcraig14@users.noreply.github.com> Date: Sun, 15 Feb 2026 22:52:08 -0600 Subject: [PATCH 04/11] Add user interaction interface --- .../GameController.cs} | 6 +- .../IGameController.cs | 0 .../IUserInteractionsController.cs | 22 ++++++ .../Controllers/UserInteractionsController.cs | 71 +++++++++++++++++++ MathGame.rcraig14/NextStep.cs | 7 ++ MathGame.rcraig14/Program.cs | 67 +++++------------ 6 files changed, 122 insertions(+), 51 deletions(-) rename MathGame.rcraig14/{Controlers/GameControler.cs => Controllers/GameController.cs} (92%) rename MathGame.rcraig14/{Controlers => Controllers}/IGameController.cs (100%) create mode 100644 MathGame.rcraig14/Controllers/IUserInteractionsController.cs create mode 100644 MathGame.rcraig14/Controllers/UserInteractionsController.cs create mode 100644 MathGame.rcraig14/NextStep.cs diff --git a/MathGame.rcraig14/Controlers/GameControler.cs b/MathGame.rcraig14/Controllers/GameController.cs similarity index 92% rename from MathGame.rcraig14/Controlers/GameControler.cs rename to MathGame.rcraig14/Controllers/GameController.cs index 29757ff3..f9295f21 100644 --- a/MathGame.rcraig14/Controlers/GameControler.cs +++ b/MathGame.rcraig14/Controllers/GameController.cs @@ -2,7 +2,7 @@ namespace MathGame.rcraig14.Controllers; -public class GameControler : IGameController +public class GameController : IGameController { private Problem? CurrentProblem {get; set;} @@ -12,13 +12,13 @@ private Random _random { set => _random = value; } - public GameControler(Random random) + public GameController(Random random) { _random = random; AnswerHistory = new List(); } - public GameControler() + public GameController() { AnswerHistory = new List(); } diff --git a/MathGame.rcraig14/Controlers/IGameController.cs b/MathGame.rcraig14/Controllers/IGameController.cs similarity index 100% rename from MathGame.rcraig14/Controlers/IGameController.cs rename to MathGame.rcraig14/Controllers/IGameController.cs diff --git a/MathGame.rcraig14/Controllers/IUserInteractionsController.cs b/MathGame.rcraig14/Controllers/IUserInteractionsController.cs new file mode 100644 index 00000000..561b504f --- /dev/null +++ b/MathGame.rcraig14/Controllers/IUserInteractionsController.cs @@ -0,0 +1,22 @@ +using System; +using System.Runtime.CompilerServices; +using MathGame.rcraig14.Models; + +namespace MathGame.rcraig14.Controllers; + + +// User interations + // Welcome screen -> void + // Next Problem or Quit -> state + // Select Problem Type -> Operation + // Get Answer(Problem) -> int + // Display results(SubmittedProblem) -> void +public interface IUserInteractionsController +{ + public void DisplayWelcome(); + public NextStep GetNextStep(); + public Operation GetNextOperationType(); + public int GetAnswer(Problem problem); + public void DisplayResults(SubmittedAnswer submittedAnswer); + +} diff --git a/MathGame.rcraig14/Controllers/UserInteractionsController.cs b/MathGame.rcraig14/Controllers/UserInteractionsController.cs new file mode 100644 index 00000000..dffc37d0 --- /dev/null +++ b/MathGame.rcraig14/Controllers/UserInteractionsController.cs @@ -0,0 +1,71 @@ +using System; +using System.Reflection.Metadata.Ecma335; +using MathGame.rcraig14.Models; + +namespace MathGame.rcraig14.Controllers; + +public class UserInteractionsController : IUserInteractionsController +{ + public void DisplayResults(SubmittedAnswer submittedAnswer) + { + Console.WriteLine(submittedAnswer.ToString()); + } + + public void DisplayWelcome() + { + Console.WriteLine("Welcome to the new math game"); + } + + public int GetAnswer(Problem problem) + { + Console.WriteLine(problem.ToString()); + Console.Write("Answer: "); + string? strAnswer = Console.ReadLine(); + + if(int.TryParse(strAnswer, out int intOut)) + { + return intOut; + } else + { + Console.WriteLine("Only integers can be submitted for answers"); + return GetAnswer(problem); + } + } + + public NextStep GetNextStep() + { + while(true) + { + Console.WriteLine("Get next problem (n) or quit (q)"); + string? input = Console.ReadLine(); + + switch(input?.ToLower() ?? "" ) + { + case "q": + return NextStep.Quit; + case "n": + return NextStep.NewProblem; + default: + continue; + } + } + + } + + public Operation GetNextOperationType() + { + Console.WriteLine(@" + Select a type of problem + - Additon (a) + - Subtraction (s) + - Multipication (m) + - Division (d)"); + + string? problemType = Console.ReadLine(); + + if(problemType is null) + return GetNextOperationType(); + + return OperationConverter.StringToOperation(problemType); + } +} diff --git a/MathGame.rcraig14/NextStep.cs b/MathGame.rcraig14/NextStep.cs new file mode 100644 index 00000000..1caeb26c --- /dev/null +++ b/MathGame.rcraig14/NextStep.cs @@ -0,0 +1,7 @@ +namespace MathGame.rcraig14; + +public enum NextStep +{ + Quit, + NewProblem +} diff --git a/MathGame.rcraig14/Program.cs b/MathGame.rcraig14/Program.cs index 81d8a8bb..bcdb88e8 100644 --- a/MathGame.rcraig14/Program.cs +++ b/MathGame.rcraig14/Program.cs @@ -1,59 +1,30 @@ using MathGame.rcraig14; using MathGame.rcraig14.Controllers; - -Console.WriteLine(@"Welcome to the Math Game! - -Objective: - - Solve as many math problems correctly as you can -"); +using MathGame.rcraig14.Models; var newProblem = true; -var controller = new GameControler(); +var controller = new GameController(); +var userInteraction = new UserInteractionsController(); + +userInteraction.DisplayWelcome(); while(newProblem) { - Console.WriteLine(@" - Select a type of problem - - Additon (a) - - Subtraction (s) - - Multipication (m) - - Division (d) - To quit type q" - ); - - var problemType = Console.ReadLine(); - - if(problemType.ToLower() == "q" || problemType.ToLower() == "quit") + NextStep next = userInteraction.GetNextStep(); + + if(next == NextStep.Quit) { newProblem = false; - continue; + break; } - try - { - var op = OperationConverter.StringToOperation(problemType); - - controller.GenerateProblem(op); - controller.DisplayProblem(); - - Console.Write($"Answer: "); - var strAnswer = Console.ReadLine(); - - if(int.TryParse(strAnswer, out int intOut)) - { - var answer = controller.SubmitAnswer(intOut); - Console.WriteLine(answer.ToString()); - } else - { - Console.WriteLine("Only integers can be submitted for answers"); - continue; - } - - } catch(InvalidOperationException) - { - Console.WriteLine("Please enter a valid value"); - } catch (Exception e) - { - Console.WriteLine($"{e}"); - } -} \ No newline at end of file + Operation op = userInteraction.GetNextOperationType(); + Problem problem = controller.GenerateProblem(op); + int userAnswer = userInteraction.GetAnswer(problem); + SubmittedAnswer submittedAnswer = controller.SubmitAnswer(userAnswer); + userInteraction.DisplayResults(submittedAnswer); +} + + + + \ No newline at end of file From 2645c9b25f4ccd56db88649ed673ecc489fed94f Mon Sep 17 00:00:00 2001 From: Ryan Craig <8675007+rcraig14@users.noreply.github.com> Date: Sun, 15 Feb 2026 23:11:13 -0600 Subject: [PATCH 05/11] Add new game runner and fixed division bug --- MathGame.rcraig14/MathGameRunner.cs | 50 ++++++++++++++++++++++++++++ MathGame.rcraig14/Models/Division.cs | 4 +-- MathGame.rcraig14/Program.cs | 25 ++------------ 3 files changed, 54 insertions(+), 25 deletions(-) create mode 100644 MathGame.rcraig14/MathGameRunner.cs diff --git a/MathGame.rcraig14/MathGameRunner.cs b/MathGame.rcraig14/MathGameRunner.cs new file mode 100644 index 00000000..8bb89a35 --- /dev/null +++ b/MathGame.rcraig14/MathGameRunner.cs @@ -0,0 +1,50 @@ +using MathGame.rcraig14.Controllers; +using MathGame.rcraig14.Models; + +namespace MathGame.rcraig14; + +public class MathGameRunner +{ + private UserInteractionsController _userInteractionController { get; } + private GameController _gameController { get; } + private bool _newProblem {get; set;} + + public MathGameRunner( + UserInteractionsController userInteractionsController, + GameController gameController) + { + _userInteractionController = userInteractionsController; + _gameController = gameController; + _newProblem = true; + } + + private void NextProblem() + { + Operation op = _userInteractionController.GetNextOperationType(); + Problem problem = _gameController.GenerateProblem(op); + int userAnswer = _userInteractionController.GetAnswer(problem); + SubmittedAnswer submittedAnswer = _gameController.SubmitAnswer(userAnswer); + _userInteractionController.DisplayResults(submittedAnswer); + } + + public void start() + { + _userInteractionController.DisplayWelcome(); + + while (_newProblem) + { + NextStep next = _userInteractionController.GetNextStep(); + + switch(next) + { + case NextStep.Quit: + _newProblem = false; + break; + default: + this.NextProblem(); + break; + } + + } + } +} diff --git a/MathGame.rcraig14/Models/Division.cs b/MathGame.rcraig14/Models/Division.cs index 65e0e6d9..ce55c2ee 100644 --- a/MathGame.rcraig14/Models/Division.cs +++ b/MathGame.rcraig14/Models/Division.cs @@ -6,9 +6,9 @@ public class Division(int pLeft, int pRight) : Problem(pLeft, pRight, Operation. public static Division GenerateRandom() { var random = new Random(); - int left = 0, right = 0; + int left = 1, right = 1; - while(left <= right && (left % right) != 0) + while(left <= right || (left % right) != 0) { left = random.Next(1,100); right = random.Next(1,99); diff --git a/MathGame.rcraig14/Program.cs b/MathGame.rcraig14/Program.cs index bcdb88e8..a3e9b1a9 100644 --- a/MathGame.rcraig14/Program.cs +++ b/MathGame.rcraig14/Program.cs @@ -1,30 +1,9 @@ using MathGame.rcraig14; using MathGame.rcraig14.Controllers; -using MathGame.rcraig14.Models; -var newProblem = true; -var controller = new GameController(); -var userInteraction = new UserInteractionsController(); - -userInteraction.DisplayWelcome(); - -while(newProblem) -{ - NextStep next = userInteraction.GetNextStep(); - - if(next == NextStep.Quit) - { - newProblem = false; - break; - } - - Operation op = userInteraction.GetNextOperationType(); - Problem problem = controller.GenerateProblem(op); - int userAnswer = userInteraction.GetAnswer(problem); - SubmittedAnswer submittedAnswer = controller.SubmitAnswer(userAnswer); - userInteraction.DisplayResults(submittedAnswer); -} +var game = new MathGameRunner(new UserInteractionsController(), new GameController()); +game.start(); \ No newline at end of file From 1f45b851452b5ee223d73a4e444c3e5c2e6a81d3 Mon Sep 17 00:00:00 2001 From: Ryan Craig <8675007+rcraig14@users.noreply.github.com> Date: Sun, 15 Feb 2026 23:14:59 -0600 Subject: [PATCH 06/11] Run code formater --- MathGame.rcraig14/Controllers/GameController.cs | 16 +++++++++------- .../Controllers/IUserInteractionsController.cs | 9 +-------- .../Controllers/UserInteractionsController.cs | 15 ++++++++------- MathGame.rcraig14/MathGameRunner.cs | 6 +++--- MathGame.rcraig14/Models/Addition.cs | 6 +++--- MathGame.rcraig14/Models/Division.cs | 6 +++--- MathGame.rcraig14/Models/Multiplication.cs | 4 ++-- MathGame.rcraig14/Models/Problem.cs | 9 +++++---- MathGame.rcraig14/Models/SubmittedAnswer.cs | 2 +- MathGame.rcraig14/Models/Subtraction.cs | 8 ++++---- MathGame.rcraig14/Operation.cs | 17 ++++++++++------- MathGame.rcraig14/Program.cs | 3 --- 12 files changed, 49 insertions(+), 52 deletions(-) diff --git a/MathGame.rcraig14/Controllers/GameController.cs b/MathGame.rcraig14/Controllers/GameController.cs index f9295f21..d9e4b2c6 100644 --- a/MathGame.rcraig14/Controllers/GameController.cs +++ b/MathGame.rcraig14/Controllers/GameController.cs @@ -5,9 +5,10 @@ namespace MathGame.rcraig14.Controllers; public class GameController : IGameController { - private Problem? CurrentProblem {get; set;} - private List AnswerHistory {get; set;} - private Random _random { + private Problem? CurrentProblem { get; set; } + private List AnswerHistory { get; set; } + private Random _random + { get => _random ?? new Random(); set => _random = value; } @@ -23,7 +24,8 @@ public GameController() AnswerHistory = new List(); } - public Problem GenerateProblem(Operation operation) { + public Problem GenerateProblem(Operation operation) + { CurrentProblem = operation switch { Operation.Addition => Addition.GenerateRandom(), @@ -35,15 +37,15 @@ public Problem GenerateProblem(Operation operation) { return CurrentProblem; } - + public SubmittedAnswer SubmitAnswer(int answer) { - if(CurrentProblem is null) + if (CurrentProblem is null) { throw new ArgumentNullException("Problem must be generated before submitting answer"); } - + var submittedAnswer = new SubmittedAnswer(CurrentProblem, answer); AnswerHistory.Append(submittedAnswer); diff --git a/MathGame.rcraig14/Controllers/IUserInteractionsController.cs b/MathGame.rcraig14/Controllers/IUserInteractionsController.cs index 561b504f..058867a1 100644 --- a/MathGame.rcraig14/Controllers/IUserInteractionsController.cs +++ b/MathGame.rcraig14/Controllers/IUserInteractionsController.cs @@ -4,19 +4,12 @@ namespace MathGame.rcraig14.Controllers; - -// User interations - // Welcome screen -> void - // Next Problem or Quit -> state - // Select Problem Type -> Operation - // Get Answer(Problem) -> int - // Display results(SubmittedProblem) -> void public interface IUserInteractionsController { public void DisplayWelcome(); public NextStep GetNextStep(); public Operation GetNextOperationType(); public int GetAnswer(Problem problem); - public void DisplayResults(SubmittedAnswer submittedAnswer); + public void DisplayResults(SubmittedAnswer submittedAnswer); } diff --git a/MathGame.rcraig14/Controllers/UserInteractionsController.cs b/MathGame.rcraig14/Controllers/UserInteractionsController.cs index dffc37d0..f0e6a991 100644 --- a/MathGame.rcraig14/Controllers/UserInteractionsController.cs +++ b/MathGame.rcraig14/Controllers/UserInteractionsController.cs @@ -22,10 +22,11 @@ public int GetAnswer(Problem problem) Console.Write("Answer: "); string? strAnswer = Console.ReadLine(); - if(int.TryParse(strAnswer, out int intOut)) + if (int.TryParse(strAnswer, out int intOut)) { return intOut; - } else + } + else { Console.WriteLine("Only integers can be submitted for answers"); return GetAnswer(problem); @@ -34,12 +35,12 @@ public int GetAnswer(Problem problem) public NextStep GetNextStep() { - while(true) + while (true) { Console.WriteLine("Get next problem (n) or quit (q)"); string? input = Console.ReadLine(); - switch(input?.ToLower() ?? "" ) + switch (input?.ToLower() ?? "") { case "q": return NextStep.Quit; @@ -49,7 +50,7 @@ public NextStep GetNextStep() continue; } } - + } public Operation GetNextOperationType() @@ -61,9 +62,9 @@ Select a type of problem - Multipication (m) - Division (d)"); - string? problemType = Console.ReadLine(); + string? problemType = Console.ReadLine(); - if(problemType is null) + if (problemType is null) return GetNextOperationType(); return OperationConverter.StringToOperation(problemType); diff --git a/MathGame.rcraig14/MathGameRunner.cs b/MathGame.rcraig14/MathGameRunner.cs index 8bb89a35..e3c418e2 100644 --- a/MathGame.rcraig14/MathGameRunner.cs +++ b/MathGame.rcraig14/MathGameRunner.cs @@ -7,7 +7,7 @@ public class MathGameRunner { private UserInteractionsController _userInteractionController { get; } private GameController _gameController { get; } - private bool _newProblem {get; set;} + private bool _newProblem { get; set; } public MathGameRunner( UserInteractionsController userInteractionsController, @@ -35,7 +35,7 @@ public void start() { NextStep next = _userInteractionController.GetNextStep(); - switch(next) + switch (next) { case NextStep.Quit: _newProblem = false; @@ -44,7 +44,7 @@ public void start() this.NextProblem(); break; } - + } } } diff --git a/MathGame.rcraig14/Models/Addition.cs b/MathGame.rcraig14/Models/Addition.cs index 6c687ec7..883f8439 100644 --- a/MathGame.rcraig14/Models/Addition.cs +++ b/MathGame.rcraig14/Models/Addition.cs @@ -3,14 +3,14 @@ namespace MathGame.rcraig14.Models; public class Addition(int pLeft, int pRight) : Problem(pLeft, pRight, Operation.Addition, "+") { - public static Addition GenerateRandom() + public static Addition GenerateRandom() { var random = new Random(); - return new Addition(random.Next(0,100), random.Next(0,100)); + return new Addition(random.Next(0, 100), random.Next(0, 100)); } public override int Answer() { - return Left + Right; + return Left + Right; } } diff --git a/MathGame.rcraig14/Models/Division.cs b/MathGame.rcraig14/Models/Division.cs index ce55c2ee..7155b335 100644 --- a/MathGame.rcraig14/Models/Division.cs +++ b/MathGame.rcraig14/Models/Division.cs @@ -8,10 +8,10 @@ public static Division GenerateRandom() var random = new Random(); int left = 1, right = 1; - while(left <= right || (left % right) != 0) + while (left <= right || (left % right) != 0) { - left = random.Next(1,100); - right = random.Next(1,99); + left = random.Next(1, 100); + right = random.Next(1, 99); } return new Division(left, right); diff --git a/MathGame.rcraig14/Models/Multiplication.cs b/MathGame.rcraig14/Models/Multiplication.cs index 1c464a3d..670d3df1 100644 --- a/MathGame.rcraig14/Models/Multiplication.cs +++ b/MathGame.rcraig14/Models/Multiplication.cs @@ -7,9 +7,9 @@ public override int Answer() return Left * Right; } - public static Multiplication GenerateRandom() + public static Multiplication GenerateRandom() { var random = new Random(); - return new Multiplication(random.Next(0,100), random.Next(0,100)); + return new Multiplication(random.Next(0, 100), random.Next(0, 100)); } } diff --git a/MathGame.rcraig14/Models/Problem.cs b/MathGame.rcraig14/Models/Problem.cs index ebcf6a73..69ee3ac4 100644 --- a/MathGame.rcraig14/Models/Problem.cs +++ b/MathGame.rcraig14/Models/Problem.cs @@ -1,10 +1,11 @@ namespace MathGame.rcraig14.Models; + public abstract class Problem { - protected int Left {get;} - protected int Right {get;} - public Operation Operation {get;} - string OperationString {get;} + protected int Left { get; } + protected int Right { get; } + public Operation Operation { get; } + string OperationString { get; } public Problem(int pLeft, int pRight, Operation pOperation, string pOperationString) { diff --git a/MathGame.rcraig14/Models/SubmittedAnswer.cs b/MathGame.rcraig14/Models/SubmittedAnswer.cs index 744698cc..faab18fd 100644 --- a/MathGame.rcraig14/Models/SubmittedAnswer.cs +++ b/MathGame.rcraig14/Models/SubmittedAnswer.cs @@ -4,7 +4,7 @@ namespace MathGame.rcraig14.Models; public class SubmittedAnswer { - public Problem Problem{ get; } + public Problem Problem { get; } public int UserAnswer { get; } diff --git a/MathGame.rcraig14/Models/Subtraction.cs b/MathGame.rcraig14/Models/Subtraction.cs index 2c36e01f..e55d6098 100644 --- a/MathGame.rcraig14/Models/Subtraction.cs +++ b/MathGame.rcraig14/Models/Subtraction.cs @@ -7,15 +7,15 @@ public override int Answer() return Left - Right; } - public static Subtraction GenerateRandom() + public static Subtraction GenerateRandom() { var random = new Random(); int left = 0, right = 0; - while(left <= right) + while (left <= right) { - left = random.Next(1,100); - right = random.Next(0,100); + left = random.Next(1, 100); + right = random.Next(0, 100); } return new Subtraction(left, right); diff --git a/MathGame.rcraig14/Operation.cs b/MathGame.rcraig14/Operation.cs index 637cc9f4..54843d50 100644 --- a/MathGame.rcraig14/Operation.cs +++ b/MathGame.rcraig14/Operation.cs @@ -12,11 +12,13 @@ public enum Operation -public static class OperationConverter { +public static class OperationConverter +{ public static Operation StringToOperation(string input) { - switch(input.ToLower()) { + switch (input.ToLower()) + { case "a": return Operation.Addition; case "s": @@ -27,21 +29,22 @@ public static Operation StringToOperation(string input) return Operation.Division; default: throw new InvalidOperationException(); - }; + } + ; } - + } -public class InvalidOperationString: Exception +public class InvalidOperationString : Exception { public InvalidOperationString() { - + } public InvalidOperationString(string message) : base(message) { - + } } \ No newline at end of file diff --git a/MathGame.rcraig14/Program.cs b/MathGame.rcraig14/Program.cs index a3e9b1a9..d2eb8364 100644 --- a/MathGame.rcraig14/Program.cs +++ b/MathGame.rcraig14/Program.cs @@ -3,7 +3,4 @@ var game = new MathGameRunner(new UserInteractionsController(), new GameController()); - - game.start(); - \ No newline at end of file From 0fb6d0847f611e7c7011b98ec63d99b62d475c76 Mon Sep 17 00:00:00 2001 From: Ryan Craig <8675007+rcraig14@users.noreply.github.com> Date: Sun, 15 Feb 2026 23:34:37 -0600 Subject: [PATCH 07/11] Add new history option --- .../Controllers/GameController.cs | 18 ++++++------------ .../Controllers/IGameController.cs | 1 + .../Controllers/IUserInteractionsController.cs | 1 + .../Controllers/UserInteractionsController.cs | 16 +++++++++++++++- MathGame.rcraig14/MathGameRunner.cs | 9 +++++++++ MathGame.rcraig14/NextStep.cs | 3 ++- 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/MathGame.rcraig14/Controllers/GameController.cs b/MathGame.rcraig14/Controllers/GameController.cs index d9e4b2c6..ab5ab56a 100644 --- a/MathGame.rcraig14/Controllers/GameController.cs +++ b/MathGame.rcraig14/Controllers/GameController.cs @@ -7,17 +7,6 @@ public class GameController : IGameController private Problem? CurrentProblem { get; set; } private List AnswerHistory { get; set; } - private Random _random - { - get => _random ?? new Random(); - set => _random = value; - } - - public GameController(Random random) - { - _random = random; - AnswerHistory = new List(); - } public GameController() { @@ -47,7 +36,7 @@ public SubmittedAnswer SubmitAnswer(int answer) } var submittedAnswer = new SubmittedAnswer(CurrentProblem, answer); - AnswerHistory.Append(submittedAnswer); + AnswerHistory.Add(submittedAnswer); return submittedAnswer; } @@ -56,4 +45,9 @@ public void DisplayProblem() { Console.WriteLine(CurrentProblem?.ToString() ?? "Problem needs to be generated"); } + + public List GetAnswerHistory() + { + return AnswerHistory; + } } diff --git a/MathGame.rcraig14/Controllers/IGameController.cs b/MathGame.rcraig14/Controllers/IGameController.cs index 9ca651b8..52b982b3 100644 --- a/MathGame.rcraig14/Controllers/IGameController.cs +++ b/MathGame.rcraig14/Controllers/IGameController.cs @@ -7,5 +7,6 @@ public interface IGameController public Problem GenerateProblem(Operation operation); public void DisplayProblem(); public SubmittedAnswer SubmitAnswer(int answer); + public List GetAnswerHistory(); } diff --git a/MathGame.rcraig14/Controllers/IUserInteractionsController.cs b/MathGame.rcraig14/Controllers/IUserInteractionsController.cs index 058867a1..0a4824a1 100644 --- a/MathGame.rcraig14/Controllers/IUserInteractionsController.cs +++ b/MathGame.rcraig14/Controllers/IUserInteractionsController.cs @@ -11,5 +11,6 @@ public interface IUserInteractionsController public Operation GetNextOperationType(); public int GetAnswer(Problem problem); public void DisplayResults(SubmittedAnswer submittedAnswer); + public void DisplayAnswerHistory(List submittedAnswers); } diff --git a/MathGame.rcraig14/Controllers/UserInteractionsController.cs b/MathGame.rcraig14/Controllers/UserInteractionsController.cs index f0e6a991..6e5e3511 100644 --- a/MathGame.rcraig14/Controllers/UserInteractionsController.cs +++ b/MathGame.rcraig14/Controllers/UserInteractionsController.cs @@ -37,7 +37,7 @@ public NextStep GetNextStep() { while (true) { - Console.WriteLine("Get next problem (n) or quit (q)"); + Console.WriteLine("Get next problem (n), history of problems (h), or quit (q)"); string? input = Console.ReadLine(); switch (input?.ToLower() ?? "") @@ -46,6 +46,8 @@ public NextStep GetNextStep() return NextStep.Quit; case "n": return NextStep.NewProblem; + case "h": + return NextStep.History; default: continue; } @@ -69,4 +71,16 @@ Select a type of problem return OperationConverter.StringToOperation(problemType); } + + public void DisplayAnswerHistory(List submittedAnswers) + { + int correct = 0; + submittedAnswers.ForEach(answer => + { + Console.WriteLine($"{answer.Problem} {answer.UserAnswer} Correct: {answer.isCorrect()}"); + correct += answer.isCorrect() ? 1 : 0; + }); + + Console.WriteLine($"Total Correct {correct} / {submittedAnswers.Count()}"); + } } diff --git a/MathGame.rcraig14/MathGameRunner.cs b/MathGame.rcraig14/MathGameRunner.cs index e3c418e2..e836033a 100644 --- a/MathGame.rcraig14/MathGameRunner.cs +++ b/MathGame.rcraig14/MathGameRunner.cs @@ -27,6 +27,12 @@ private void NextProblem() _userInteractionController.DisplayResults(submittedAnswer); } + private void History() + { + var history = _gameController.GetAnswerHistory(); + _userInteractionController.DisplayAnswerHistory(history); + } + public void start() { _userInteractionController.DisplayWelcome(); @@ -40,6 +46,9 @@ public void start() case NextStep.Quit: _newProblem = false; break; + case NextStep.History: + this.History(); + break; default: this.NextProblem(); break; diff --git a/MathGame.rcraig14/NextStep.cs b/MathGame.rcraig14/NextStep.cs index 1caeb26c..5addbc83 100644 --- a/MathGame.rcraig14/NextStep.cs +++ b/MathGame.rcraig14/NextStep.cs @@ -3,5 +3,6 @@ namespace MathGame.rcraig14; public enum NextStep { Quit, - NewProblem + NewProblem, + History } From 2417bc4b83b5b8d2e7147bb670579a493bf6e9e3 Mon Sep 17 00:00:00 2001 From: Ryan Craig <8675007+rcraig14@users.noreply.github.com> Date: Sun, 15 Feb 2026 23:37:14 -0600 Subject: [PATCH 08/11] Minor ui clean up --- .../Controllers/UserInteractionsController.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MathGame.rcraig14/Controllers/UserInteractionsController.cs b/MathGame.rcraig14/Controllers/UserInteractionsController.cs index 6e5e3511..ba1f4c4c 100644 --- a/MathGame.rcraig14/Controllers/UserInteractionsController.cs +++ b/MathGame.rcraig14/Controllers/UserInteractionsController.cs @@ -58,11 +58,11 @@ public NextStep GetNextStep() public Operation GetNextOperationType() { Console.WriteLine(@" - Select a type of problem - - Additon (a) - - Subtraction (s) - - Multipication (m) - - Division (d)"); +Select a type of problem + - Additon (a) + - Subtraction (s) + - Multipication (m) + - Division (d)"); string? problemType = Console.ReadLine(); From 7ceb7969689934e7545e86de3ee05166b785aa19 Mon Sep 17 00:00:00 2001 From: Ryan Craig <8675007+rcraig14@users.noreply.github.com> Date: Sun, 15 Feb 2026 23:45:23 -0600 Subject: [PATCH 09/11] Add time to solve --- MathGame.rcraig14/Controllers/GameController.cs | 4 ++-- MathGame.rcraig14/Controllers/IGameController.cs | 2 +- MathGame.rcraig14/Controllers/UserInteractionsController.cs | 3 ++- MathGame.rcraig14/MathGameRunner.cs | 6 +++++- MathGame.rcraig14/Models/SubmittedAnswer.cs | 4 +++- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/MathGame.rcraig14/Controllers/GameController.cs b/MathGame.rcraig14/Controllers/GameController.cs index ab5ab56a..1ef0ab5b 100644 --- a/MathGame.rcraig14/Controllers/GameController.cs +++ b/MathGame.rcraig14/Controllers/GameController.cs @@ -28,14 +28,14 @@ public Problem GenerateProblem(Operation operation) } - public SubmittedAnswer SubmitAnswer(int answer) + public SubmittedAnswer SubmitAnswer(int answer, TimeSpan timeToComplete) { if (CurrentProblem is null) { throw new ArgumentNullException("Problem must be generated before submitting answer"); } - var submittedAnswer = new SubmittedAnswer(CurrentProblem, answer); + var submittedAnswer = new SubmittedAnswer(CurrentProblem, answer, timeToComplete); AnswerHistory.Add(submittedAnswer); return submittedAnswer; diff --git a/MathGame.rcraig14/Controllers/IGameController.cs b/MathGame.rcraig14/Controllers/IGameController.cs index 52b982b3..e92ff0c0 100644 --- a/MathGame.rcraig14/Controllers/IGameController.cs +++ b/MathGame.rcraig14/Controllers/IGameController.cs @@ -6,7 +6,7 @@ public interface IGameController { public Problem GenerateProblem(Operation operation); public void DisplayProblem(); - public SubmittedAnswer SubmitAnswer(int answer); + public SubmittedAnswer SubmitAnswer(int answer, TimeSpan timeToComplete); public List GetAnswerHistory(); } diff --git a/MathGame.rcraig14/Controllers/UserInteractionsController.cs b/MathGame.rcraig14/Controllers/UserInteractionsController.cs index ba1f4c4c..53f59dbb 100644 --- a/MathGame.rcraig14/Controllers/UserInteractionsController.cs +++ b/MathGame.rcraig14/Controllers/UserInteractionsController.cs @@ -9,6 +9,7 @@ public class UserInteractionsController : IUserInteractionsController public void DisplayResults(SubmittedAnswer submittedAnswer) { Console.WriteLine(submittedAnswer.ToString()); + Console.WriteLine($"It took {submittedAnswer.TimeToComplete} to complete"); } public void DisplayWelcome() @@ -62,7 +63,7 @@ Select a type of problem - Additon (a) - Subtraction (s) - Multipication (m) - - Division (d)"); + - Division (d)"); string? problemType = Console.ReadLine(); diff --git a/MathGame.rcraig14/MathGameRunner.cs b/MathGame.rcraig14/MathGameRunner.cs index e836033a..26d51d42 100644 --- a/MathGame.rcraig14/MathGameRunner.cs +++ b/MathGame.rcraig14/MathGameRunner.cs @@ -22,8 +22,12 @@ private void NextProblem() { Operation op = _userInteractionController.GetNextOperationType(); Problem problem = _gameController.GenerateProblem(op); + + DateTime startTime = DateTime.UtcNow; int userAnswer = _userInteractionController.GetAnswer(problem); - SubmittedAnswer submittedAnswer = _gameController.SubmitAnswer(userAnswer); + DateTime endTime = DateTime.UtcNow; + + SubmittedAnswer submittedAnswer = _gameController.SubmitAnswer(userAnswer, endTime - startTime); _userInteractionController.DisplayResults(submittedAnswer); } diff --git a/MathGame.rcraig14/Models/SubmittedAnswer.cs b/MathGame.rcraig14/Models/SubmittedAnswer.cs index faab18fd..cc478060 100644 --- a/MathGame.rcraig14/Models/SubmittedAnswer.cs +++ b/MathGame.rcraig14/Models/SubmittedAnswer.cs @@ -6,12 +6,14 @@ public class SubmittedAnswer { public Problem Problem { get; } public int UserAnswer { get; } + public TimeSpan TimeToComplete { get; } - public SubmittedAnswer(Problem problem, int answer) + public SubmittedAnswer(Problem problem, int answer, TimeSpan timeToComplete) { Problem = problem; UserAnswer = answer; + TimeToComplete = timeToComplete; } public bool isCorrect() => Problem.Answer() == UserAnswer; From 5692e1f8e3c9b01e674981857c1bd55cd5efabde Mon Sep 17 00:00:00 2001 From: Ryan Craig <8675007+rcraig14@users.noreply.github.com> Date: Mon, 16 Feb 2026 19:19:11 -0600 Subject: [PATCH 10/11] Address PR feedback --- .../IUserInteractionsController.cs | 2 -- .../Controllers/UserInteractionsController.cs | 6 ++-- MathGame.rcraig14/MathGameRunner.cs | 36 +++++++++---------- MathGame.rcraig14/Models/SubmittedAnswer.cs | 6 ++-- MathGame.rcraig14/Operation.cs | 2 -- MathGame.rcraig14/Program.cs | 2 +- 6 files changed, 23 insertions(+), 31 deletions(-) diff --git a/MathGame.rcraig14/Controllers/IUserInteractionsController.cs b/MathGame.rcraig14/Controllers/IUserInteractionsController.cs index 0a4824a1..39769cc3 100644 --- a/MathGame.rcraig14/Controllers/IUserInteractionsController.cs +++ b/MathGame.rcraig14/Controllers/IUserInteractionsController.cs @@ -1,5 +1,3 @@ -using System; -using System.Runtime.CompilerServices; using MathGame.rcraig14.Models; namespace MathGame.rcraig14.Controllers; diff --git a/MathGame.rcraig14/Controllers/UserInteractionsController.cs b/MathGame.rcraig14/Controllers/UserInteractionsController.cs index 53f59dbb..1fab73d9 100644 --- a/MathGame.rcraig14/Controllers/UserInteractionsController.cs +++ b/MathGame.rcraig14/Controllers/UserInteractionsController.cs @@ -1,5 +1,3 @@ -using System; -using System.Reflection.Metadata.Ecma335; using MathGame.rcraig14.Models; namespace MathGame.rcraig14.Controllers; @@ -78,8 +76,8 @@ public void DisplayAnswerHistory(List submittedAnswers) int correct = 0; submittedAnswers.ForEach(answer => { - Console.WriteLine($"{answer.Problem} {answer.UserAnswer} Correct: {answer.isCorrect()}"); - correct += answer.isCorrect() ? 1 : 0; + Console.WriteLine($"{answer.Problem} {answer.UserAnswer} Correct: {answer.IsCorrect()}"); + correct += answer.IsCorrect() ? 1 : 0; }); Console.WriteLine($"Total Correct {correct} / {submittedAnswers.Count()}"); diff --git a/MathGame.rcraig14/MathGameRunner.cs b/MathGame.rcraig14/MathGameRunner.cs index 26d51d42..dd02bfb6 100644 --- a/MathGame.rcraig14/MathGameRunner.cs +++ b/MathGame.rcraig14/MathGameRunner.cs @@ -5,50 +5,50 @@ namespace MathGame.rcraig14; public class MathGameRunner { - private UserInteractionsController _userInteractionController { get; } - private GameController _gameController { get; } - private bool _newProblem { get; set; } + private UserInteractionsController UserInteractionController { get; } + private GameController GameController { get; } + private bool NewProblem { get; set; } public MathGameRunner( UserInteractionsController userInteractionsController, GameController gameController) { - _userInteractionController = userInteractionsController; - _gameController = gameController; - _newProblem = true; + UserInteractionController = userInteractionsController; + GameController = gameController; + NewProblem = true; } private void NextProblem() { - Operation op = _userInteractionController.GetNextOperationType(); - Problem problem = _gameController.GenerateProblem(op); + Operation op = UserInteractionController.GetNextOperationType(); + Problem problem = GameController.GenerateProblem(op); DateTime startTime = DateTime.UtcNow; - int userAnswer = _userInteractionController.GetAnswer(problem); + int userAnswer = UserInteractionController.GetAnswer(problem); DateTime endTime = DateTime.UtcNow; - SubmittedAnswer submittedAnswer = _gameController.SubmitAnswer(userAnswer, endTime - startTime); - _userInteractionController.DisplayResults(submittedAnswer); + SubmittedAnswer submittedAnswer = GameController.SubmitAnswer(userAnswer, endTime - startTime); + UserInteractionController.DisplayResults(submittedAnswer); } private void History() { - var history = _gameController.GetAnswerHistory(); - _userInteractionController.DisplayAnswerHistory(history); + var history = GameController.GetAnswerHistory(); + UserInteractionController.DisplayAnswerHistory(history); } - public void start() + public void Start() { - _userInteractionController.DisplayWelcome(); + UserInteractionController.DisplayWelcome(); - while (_newProblem) + while (NewProblem) { - NextStep next = _userInteractionController.GetNextStep(); + NextStep next = UserInteractionController.GetNextStep(); switch (next) { case NextStep.Quit: - _newProblem = false; + NewProblem = false; break; case NextStep.History: this.History(); diff --git a/MathGame.rcraig14/Models/SubmittedAnswer.cs b/MathGame.rcraig14/Models/SubmittedAnswer.cs index cc478060..c2cb744c 100644 --- a/MathGame.rcraig14/Models/SubmittedAnswer.cs +++ b/MathGame.rcraig14/Models/SubmittedAnswer.cs @@ -1,5 +1,3 @@ -using System.Runtime.CompilerServices; - namespace MathGame.rcraig14.Models; public class SubmittedAnswer @@ -16,10 +14,10 @@ public SubmittedAnswer(Problem problem, int answer, TimeSpan timeToComplete) TimeToComplete = timeToComplete; } - public bool isCorrect() => Problem.Answer() == UserAnswer; + public bool IsCorrect() => Problem.Answer() == UserAnswer; public override string ToString() { - return isCorrect() ? $"Correct the answer is {Problem.Answer()}" : $"Incorrect the answer is {Problem.Answer()}"; + return IsCorrect() ? $"Correct the answer is {Problem.Answer()}" : $"Incorrect the answer is {Problem.Answer()}"; } } diff --git a/MathGame.rcraig14/Operation.cs b/MathGame.rcraig14/Operation.cs index 54843d50..f87c64dd 100644 --- a/MathGame.rcraig14/Operation.cs +++ b/MathGame.rcraig14/Operation.cs @@ -1,5 +1,3 @@ -using System.Collections; - namespace MathGame.rcraig14; public enum Operation diff --git a/MathGame.rcraig14/Program.cs b/MathGame.rcraig14/Program.cs index d2eb8364..4a3426e5 100644 --- a/MathGame.rcraig14/Program.cs +++ b/MathGame.rcraig14/Program.cs @@ -3,4 +3,4 @@ var game = new MathGameRunner(new UserInteractionsController(), new GameController()); -game.start(); +game.Start(); From f43effeb8f1202ac0592a41aa006c24f9dc22426 Mon Sep 17 00:00:00 2001 From: Ryan Craig <8675007+rcraig14@users.noreply.github.com> Date: Mon, 16 Feb 2026 19:24:59 -0600 Subject: [PATCH 11/11] Address PR feedback --- MathGame.rcraig14/Operation.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/MathGame.rcraig14/Operation.cs b/MathGame.rcraig14/Operation.cs index f87c64dd..2e10c705 100644 --- a/MathGame.rcraig14/Operation.cs +++ b/MathGame.rcraig14/Operation.cs @@ -9,7 +9,6 @@ public enum Operation } - public static class OperationConverter { @@ -28,9 +27,7 @@ public static Operation StringToOperation(string input) default: throw new InvalidOperationException(); } - ; } - } public class InvalidOperationString : Exception