From 73679803dcef922b1b7e0b7f2dc21a6dd2ec3704 Mon Sep 17 00:00:00 2001 From: nrlutken Date: Thu, 3 Sep 2026 11:20:00 -0400 Subject: [PATCH] submission for review --- MathGame.lucidest/MathGame.lucidest.slnx | 3 + MathGame.lucidest/MathGame.lucidest/Engine.cs | 110 +++++++++++++++++ .../MathGame.lucidest.csproj | 10 ++ .../MathGame.lucidest/Program.cs | 4 + MathGame.lucidest/MathGame.lucidest/UI.cs | 111 ++++++++++++++++++ .../MathGame.lucidest/Validation.cs | 20 ++++ 6 files changed, 258 insertions(+) create mode 100644 MathGame.lucidest/MathGame.lucidest.slnx create mode 100644 MathGame.lucidest/MathGame.lucidest/Engine.cs create mode 100644 MathGame.lucidest/MathGame.lucidest/MathGame.lucidest.csproj create mode 100644 MathGame.lucidest/MathGame.lucidest/Program.cs create mode 100644 MathGame.lucidest/MathGame.lucidest/UI.cs create mode 100644 MathGame.lucidest/MathGame.lucidest/Validation.cs diff --git a/MathGame.lucidest/MathGame.lucidest.slnx b/MathGame.lucidest/MathGame.lucidest.slnx new file mode 100644 index 00000000..63af0c9e --- /dev/null +++ b/MathGame.lucidest/MathGame.lucidest.slnx @@ -0,0 +1,3 @@ + + + diff --git a/MathGame.lucidest/MathGame.lucidest/Engine.cs b/MathGame.lucidest/MathGame.lucidest/Engine.cs new file mode 100644 index 00000000..b7593f78 --- /dev/null +++ b/MathGame.lucidest/MathGame.lucidest/Engine.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathGame +{ + public class Engine + { + public static bool Addition() + { + int num1 = Random.Shared.Next(0, 13); + int num2 = Random.Shared.Next(0, 13); + + Console.WriteLine($"{num1} + {num2} = ?"); + Console.Write("\nAnswer: "); + + string input = Console.ReadLine(); + + int answer = Validation.Validate(input); + int corrAns = num1 + num2; + + if (corrAns == answer) + { + Console.WriteLine("That's correct, good job!"); + return true; + } + else + { + Console.WriteLine($"Incorrect, correct answer: {corrAns}"); + return false; + } + } + + public static bool Subtraction() + { + int num1 = Random.Shared.Next(0, 13); + int num2 = Random.Shared.Next(0, 13); + + Console.WriteLine($"{num1} - {num2} = ?"); + Console.Write("\nAnswer: "); + + string input = Console.ReadLine(); + + int answer = Validation.Validate(input); + int corrAns = num1 - num2; + + if (corrAns == answer) + { + Console.WriteLine("That's correct, good job!"); + return true; + } + else + { + Console.WriteLine($"Incorrect, correct answer: {corrAns}"); + return false; + } + } + + public static bool Multiplication() + { + int num1 = Random.Shared.Next(0, 13); + int num2 = Random.Shared.Next(0, 13); + + Console.WriteLine($"{num1} * {num2} = ?"); + Console.Write("\nAnswer: "); + + string input = Console.ReadLine(); + + int answer = Validation.Validate(input); + int corrAns = num1 * num2; + + if (corrAns == answer) + { + Console.WriteLine("That's correct, good job!"); + return true; + } + else + { + Console.WriteLine($"Incorrect, correct answer: {corrAns}"); + return false; + } + } + + public static bool Division() + { + int num1 = Random.Shared.Next(1, 13); + int maxQuot = 100 / num1; + int corrQuot = Random.Shared.Next(0, maxQuot + 1); + int num2 = num1 * corrQuot; + + Console.WriteLine($"{num2} / {num1} = ?"); + Console.Write("\nAnswer: "); + + string input = Console.ReadLine(); + + int answer = Validation.Validate(input); + + if (corrQuot == answer) + { + Console.WriteLine("That's correct, good job!"); + return true; + } + else + { + Console.WriteLine($"Incorrect, correct answer: {corrQuot}"); + return false; + } + } + } +} \ No newline at end of file diff --git a/MathGame.lucidest/MathGame.lucidest/MathGame.lucidest.csproj b/MathGame.lucidest/MathGame.lucidest/MathGame.lucidest.csproj new file mode 100644 index 00000000..ed9781c2 --- /dev/null +++ b/MathGame.lucidest/MathGame.lucidest/MathGame.lucidest.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/MathGame.lucidest/MathGame.lucidest/Program.cs b/MathGame.lucidest/MathGame.lucidest/Program.cs new file mode 100644 index 00000000..635d31bb --- /dev/null +++ b/MathGame.lucidest/MathGame.lucidest/Program.cs @@ -0,0 +1,4 @@ +using MathGame; + +UI menu = new UI(); +menu.StartGame(); \ No newline at end of file diff --git a/MathGame.lucidest/MathGame.lucidest/UI.cs b/MathGame.lucidest/MathGame.lucidest/UI.cs new file mode 100644 index 00000000..b44ffeb6 --- /dev/null +++ b/MathGame.lucidest/MathGame.lucidest/UI.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathGame; + +public class UI +{ + List hist = new(); + public int totalCount = 0; + public int winCount = 0; + public bool contPlaying = true; + private void DisplayMenu() + { + Console.WriteLine("-----------\tWelcome to the math game!\t-----------"); + } + private int DisplayOptions() + { + Console.WriteLine("Please select from the options below for your challenge."); + Console.WriteLine("\n1. Addition"); + Console.WriteLine("2. Subtraction"); + Console.WriteLine("3. Multiplication"); + Console.WriteLine("4. Division"); + Console.WriteLine("5. History"); + Console.WriteLine("6. Quit"); + + Console.Write("\nSelection: "); + string input = Console.ReadLine(); + + while (!int.TryParse(input, out int result) || result < 1 || result > 6) + { + Console.WriteLine("\nPlease select from the options below for your challenge."); + Console.WriteLine("\n1. Addition"); + Console.WriteLine("2. Subtraction"); + Console.WriteLine("3. Multiplication"); + Console.WriteLine("4. Division"); + Console.WriteLine("5. History"); + Console.WriteLine("6. Quit"); + + Console.WriteLine("\nInvalid input. Please try again:"); + Console.Write("\nSelection: "); + input = Console.ReadLine(); + } + return int.Parse(input); + } + + public void StartGame() + { + DisplayMenu(); + do + { + + int input = DisplayOptions(); + switch (input) + { + case 1: + bool resultAdd = Engine.Addition(); + if (resultAdd) + winCount++; + totalCount++; + if (resultAdd) + hist.Add("Addition - WIN"); + else hist.Add("Addition - LOSS"); + Console.WriteLine($"Score: {winCount}"); + break; + case 2: + bool resultSub = Engine.Subtraction(); + if (resultSub) + winCount++; + totalCount++; + if (resultSub) + hist.Add("Subtraction - WIN"); + else hist.Add("Subtraction - LOSS"); + Console.WriteLine($"Score: {winCount}"); + break; + case 3: + bool resultMul = Engine.Multiplication(); + if (resultMul) + winCount++; + totalCount++; + if (resultMul) + hist.Add("Multiplication - WIN"); + else hist.Add("Multiplication - LOSS"); + Console.WriteLine($"Score: {winCount}"); + break; + case 4: + bool resultDiv = Engine.Division(); + if (resultDiv) + winCount++; + totalCount++; + if (resultDiv) + hist.Add("Division - WIN"); + else hist.Add("Division - LOSS"); + Console.WriteLine($"Score: {winCount}"); + break; + case 5: + Console.WriteLine(); + foreach (string history in hist) + { + Console.WriteLine(history); + Console.WriteLine("-----------\t ------- \t-----------"); + } + break; + case 6: + contPlaying = false; + break; + } + Console.WriteLine(); + } while (contPlaying); + } +} \ No newline at end of file diff --git a/MathGame.lucidest/MathGame.lucidest/Validation.cs b/MathGame.lucidest/MathGame.lucidest/Validation.cs new file mode 100644 index 00000000..a8ccccc1 --- /dev/null +++ b/MathGame.lucidest/MathGame.lucidest/Validation.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathGame +{ + public class Validation + { + public static int Validate(string? input) + { + while (!int.TryParse(input, out int result) || string.IsNullOrWhiteSpace(input)) + { + Console.WriteLine("Invalid input. Please try again."); + Console.Write("\nAnswer: "); + input = Console.ReadLine(); + } + return int.Parse(input); + } + } +} \ No newline at end of file