From 3a7099ed154c47e8f9588f25a7e20c421809e29d Mon Sep 17 00:00:00 2001 From: Sam Richardson Date: Mon, 2 Mar 2026 23:23:08 -0600 Subject: [PATCH] project creation --- MathGame.sln | 25 +++++++ MathGame/GameEngine.cs | 140 +++++++++++++++++++++++++++++++++++++++ MathGame/Helpers.cs | 48 ++++++++++++++ MathGame/MathGame.csproj | 10 +++ MathGame/Menu.cs | 56 ++++++++++++++++ MathGame/Program.cs | 12 ++++ 6 files changed, 291 insertions(+) create mode 100644 MathGame.sln create mode 100644 MathGame/GameEngine.cs create mode 100644 MathGame/Helpers.cs create mode 100644 MathGame/MathGame.csproj create mode 100644 MathGame/Menu.cs create mode 100644 MathGame/Program.cs diff --git a/MathGame.sln b/MathGame.sln new file mode 100644 index 00000000..4e6a32ac --- /dev/null +++ b/MathGame.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.37012.4 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MathGame", "MathGame\MathGame.csproj", "{56B2D4C6-5A4B-42AF-854E-DFE8408D6FBF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {56B2D4C6-5A4B-42AF-854E-DFE8408D6FBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {56B2D4C6-5A4B-42AF-854E-DFE8408D6FBF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {56B2D4C6-5A4B-42AF-854E-DFE8408D6FBF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {56B2D4C6-5A4B-42AF-854E-DFE8408D6FBF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CAE59982-AA83-4BC0-9C83-A06C89A2C97C} + EndGlobalSection +EndGlobal diff --git a/MathGame/GameEngine.cs b/MathGame/GameEngine.cs new file mode 100644 index 00000000..6e2164d3 --- /dev/null +++ b/MathGame/GameEngine.cs @@ -0,0 +1,140 @@ +namespace MathGame +{ + internal class GameEngine + { + internal void AdditionGame(string message) + { + Console.WriteLine(message); + var random = new Random(); + var score = 0; + int firstNumber; + int secondNumber; + + for (int i = 0; i < 5; i++) + { + firstNumber = random.Next(1, 9); + secondNumber = random.Next(1, 9); + + Console.WriteLine($"{firstNumber} + {secondNumber} = ?"); + var result = Console.ReadLine(); + + if (int.Parse(result) == firstNumber + secondNumber) + { + Console.WriteLine("That is correct! Type any key to continue..."); + score++; + Console.ReadLine(); + } + else + { + Console.WriteLine("That is incorrect Type any key to continue..."); + Console.ReadLine(); + } + } + + Helpers.AddToHistory(score, "Addition"); + + Console.WriteLine($"Your final score: {score}. Press any key to continue..."); + Console.ReadLine(); + + } + + internal void SubtractionGame(string message) + { + Console.WriteLine(message); + var random = new Random(); + var score = 0; + int firstNumber; + int secondNumber; + + for (int i = 0; i < 5; i++) + { + firstNumber = random.Next(1, 9); + secondNumber = random.Next(1, 9); + + Console.WriteLine($"{firstNumber} - {secondNumber} = ?"); + var result = Console.ReadLine(); + + if (int.Parse(result) == firstNumber - secondNumber) + { + Console.WriteLine("That is correct! Type any key to continue..."); + score++; + Console.ReadLine(); + } + else + { + Console.WriteLine("That is incorrect Type any key to continue..."); + Console.ReadLine(); + } + } + + Helpers.AddToHistory(score, "Subtraction"); + + Console.WriteLine($"Your final score: {score}. Press any key to continue..."); + Console.ReadLine(); + } + + internal void MultiplicationGame(string message) + { + Console.WriteLine(message); + var random = new Random(); + var score = 0; + int firstNumber; + int secondNumber; + + for (int i = 0; i < 5; i++) + { + firstNumber = random.Next(1, 9); + secondNumber = random.Next(1, 9); + + Console.WriteLine($"{firstNumber} * {secondNumber} = ?"); + var result = Console.ReadLine(); + + if (int.Parse(result) == firstNumber * secondNumber) + { + Console.WriteLine("That is correct! Type any key to continue..."); + score++; + Console.ReadLine(); + } + else + { + Console.WriteLine("That is incorrect Type any key to continue..."); + Console.ReadLine(); + } + } + + Helpers.AddToHistory(score, "Multiplication"); + + Console.WriteLine($"Your final score: {score}. Press any key to continue..."); + Console.ReadLine(); + } + + internal void DivisionGame(string message) + { + Console.WriteLine(message); + var score = 0; + for (int i = 0; i < 5; i++) + { + var divisionNumbers = Helpers.GetDivisionNumbers(); + Console.WriteLine($"{divisionNumbers[0]} / {divisionNumbers[1]} = ?"); + var result = Console.ReadLine(); + + if (int.Parse(result) == divisionNumbers[0] / divisionNumbers[1]) + { + Console.WriteLine("That is correct! Type any key to continue..."); + score++; + Console.ReadLine(); + } + else + { + Console.WriteLine("That is incorrect Type any key to continue..."); + Console.ReadLine(); + } + } + + Helpers.AddToHistory(score, "Division"); + + Console.WriteLine($"Your final score: {score}. Press any key to continue..."); + Console.ReadLine(); + } + } +} diff --git a/MathGame/Helpers.cs b/MathGame/Helpers.cs new file mode 100644 index 00000000..d78a65da --- /dev/null +++ b/MathGame/Helpers.cs @@ -0,0 +1,48 @@ +namespace MathGame +{ + internal class Helpers + { + static List games = new(); + internal static void GetGames() + { + Console.Clear(); + Console.WriteLine("Games History"); + Console.WriteLine("---------------------------------"); + foreach (var game in games) + { + Console.WriteLine(game); + } + Console.WriteLine("---------------------------------\n"); + Console.WriteLine("Press any key to continue..."); + Console.ReadLine(); + } + + + internal static void AddToHistory(int gameScore, string gameType) + { + games.Add($"{DateTime.Now} - {gameType}: Score= {gameScore} pts"); + } + + + + internal static int[] GetDivisionNumbers() + { + var random = new Random(); + int firstNumber; + int secondNumber; + var result = new int[2]; + do + { + firstNumber = random.Next(1, 99); + secondNumber = random.Next(1, 99); + } + while (firstNumber % secondNumber != 0); + + result[0] = firstNumber; + result[1] = secondNumber; + return result; + } + + + } +} diff --git a/MathGame/MathGame.csproj b/MathGame/MathGame.csproj new file mode 100644 index 00000000..2150e379 --- /dev/null +++ b/MathGame/MathGame.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/MathGame/Menu.cs b/MathGame/Menu.cs new file mode 100644 index 00000000..4380764a --- /dev/null +++ b/MathGame/Menu.cs @@ -0,0 +1,56 @@ +namespace MathGame +{ + internal class Menu + { + GameEngine engine = new(); + internal void ShowMenu(string? name, DateTime date) + { + Console.Clear(); + Console.WriteLine($"Hello {name} it is {date}"); + var isGameActive = true; + do + { + Console.WriteLine("---------------------------------"); + Console.WriteLine(@"Please choose a game option: +V - View Previous Games +A - Addition +S - Subtraction +M - Multiplication +D - Division +Q - Quit"); + Console.WriteLine("---------------------------------"); + + var gameSelected = Console.ReadLine(); + + switch (gameSelected.Trim().ToLower()) + { + case "v": + Helpers.GetGames(); + break; + case "a": + engine.AdditionGame("Addition selected"); + break; + case "s": + engine.SubtractionGame("Subtraction selected"); + break; + case "m": + engine.MultiplicationGame("Multiplication selected"); + break; + case "d": + engine.DivisionGame("Division selected"); + break; + case "q": + Console.WriteLine("Quit selected"); + isGameActive = false; + break; + default: + Console.WriteLine("Invalid selection"); + break; + } + } while (isGameActive); + } + + + public Menu() { } + } +} diff --git a/MathGame/Program.cs b/MathGame/Program.cs new file mode 100644 index 00000000..627fb4fa --- /dev/null +++ b/MathGame/Program.cs @@ -0,0 +1,12 @@ +// See https://aka.ms/new-console-template for more information +using MathGame; + +Console.WriteLine("Please provide your name"); + +var menu = new Menu(); + +var name = Console.ReadLine(); +var date = DateTime.UtcNow; + +menu.ShowMenu(name, date); +