From f42ac7dc1de088c627b4ee72119d562fd707610a Mon Sep 17 00:00:00 2001 From: purdyz Date: Sat, 17 Oct 2026 10:35:08 -0400 Subject: [PATCH 01/10] First commit --- MathGame.purdyz/MathGame.purdyz.slnx | 3 +++ MathGame.purdyz/MathGame.purdyz/MathGame.purdyz.csproj | 10 ++++++++++ MathGame.purdyz/MathGame.purdyz/Program.cs | 1 + 3 files changed, 14 insertions(+) create mode 100644 MathGame.purdyz/MathGame.purdyz.slnx create mode 100644 MathGame.purdyz/MathGame.purdyz/MathGame.purdyz.csproj create mode 100644 MathGame.purdyz/MathGame.purdyz/Program.cs diff --git a/MathGame.purdyz/MathGame.purdyz.slnx b/MathGame.purdyz/MathGame.purdyz.slnx new file mode 100644 index 00000000..ea51e18a --- /dev/null +++ b/MathGame.purdyz/MathGame.purdyz.slnx @@ -0,0 +1,3 @@ + + + diff --git a/MathGame.purdyz/MathGame.purdyz/MathGame.purdyz.csproj b/MathGame.purdyz/MathGame.purdyz/MathGame.purdyz.csproj new file mode 100644 index 00000000..ed9781c2 --- /dev/null +++ b/MathGame.purdyz/MathGame.purdyz/MathGame.purdyz.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/MathGame.purdyz/MathGame.purdyz/Program.cs b/MathGame.purdyz/MathGame.purdyz/Program.cs new file mode 100644 index 00000000..0fd4ddaf --- /dev/null +++ b/MathGame.purdyz/MathGame.purdyz/Program.cs @@ -0,0 +1 @@ +Console.WriteLine("Hello, CSharp Academy!"); From 4d3dca3e1987d09b78524d4e75734038ddddead5 Mon Sep 17 00:00:00 2001 From: purdyz Date: Sat, 17 Oct 2026 10:51:17 -0400 Subject: [PATCH 02/10] Added welcome prompt --- MathGame.purdyz/MathGame.purdyz/Program.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MathGame.purdyz/MathGame.purdyz/Program.cs b/MathGame.purdyz/MathGame.purdyz/Program.cs index 0fd4ddaf..69dc4725 100644 --- a/MathGame.purdyz/MathGame.purdyz/Program.cs +++ b/MathGame.purdyz/MathGame.purdyz/Program.cs @@ -1 +1,4 @@ -Console.WriteLine("Hello, CSharp Academy!"); +Console.WriteLine("Welcome to the Math Game!"); +Console.Write("What's your name? "); +string playerName = Console.ReadLine(); +Console.WriteLine($"Nice to meet you, {playerName}!"); \ No newline at end of file From ff283e8d077efea8daf6ff2928be897ad7695655 Mon Sep 17 00:00:00 2001 From: purdyz Date: Sat, 17 Oct 2026 12:33:40 -0400 Subject: [PATCH 03/10] Implemented welcome, main menu, and basic game --- MathGame.purdyz/MathGame.purdyz/Program.cs | 117 ++++++++++++++++++++- 1 file changed, 115 insertions(+), 2 deletions(-) diff --git a/MathGame.purdyz/MathGame.purdyz/Program.cs b/MathGame.purdyz/MathGame.purdyz/Program.cs index 69dc4725..fa9265ae 100644 --- a/MathGame.purdyz/MathGame.purdyz/Program.cs +++ b/MathGame.purdyz/MathGame.purdyz/Program.cs @@ -1,4 +1,117 @@ -Console.WriteLine("Welcome to the Math Game!"); +// Welcome Message +Console.WriteLine("Welcome to the Math Game!"); Console.Write("What's your name? "); string playerName = Console.ReadLine(); -Console.WriteLine($"Nice to meet you, {playerName}!"); \ No newline at end of file +Console.WriteLine($"Nice to meet you, {playerName}!"); + +// Main Menu +Console.WriteLine("Main Menu"); +Console.WriteLine("1. Play a game"); +Console.WriteLine("2. View History"); +Console.WriteLine("3. Exit"); +while (int.TryParse(Console.ReadLine(), out int menuChoice)) +{ + switch (menuChoice) + { + case 1: + GameSelection(); + break; + case 2: + Console.WriteLine("History available in a future update!"); + break; + case 3: + Console.WriteLine("Thanks for playing!"); + break; + default: + Console.WriteLine("The choice you selected was invalid. Please enter 1 through 3 only."); + break; + } +} + +// Choose a game +static void GameSelection() +{ + Console.WriteLine("Enter the number of a game to play:"); + Console.WriteLine("1. Addition"); + Console.WriteLine("2. Subtraction"); + Console.WriteLine("3. Multiplication"); + Console.WriteLine("4. Division"); + if (int.TryParse(Console.ReadLine(), out int gameChoice)) + { + switch (gameChoice) + { + case 1: + Console.WriteLine("Addition selected!"); + AskQuestions('+'); + break; + case 2: + Console.WriteLine("Subtraction selected!"); + AskQuestions('-'); + break; + case 3: + Console.WriteLine("Multiplication selected!"); + AskQuestions('*'); + break; + case 4: + Console.WriteLine("Division selected!"); + AskQuestions('/'); + break; + default: + Console.WriteLine("Invalid choice"); + break; + } + } + else + Console.WriteLine("The choice you selected was invalid. Please enter 1 through 4 only."); +} + +// Ask questions +static void AskQuestions(char operation) +{ + Random random = new Random(); + int count = 1; + int score = 0; + int randomNum = random.Next(1, 11); + int randomNum2 = random.Next(1, 11); + int result = 0; + int product = 0; + + while (count < 6) + { + if (operation == '+') + result = randomNum + randomNum2; + if (operation == '-') + result = randomNum - randomNum2; + if (operation == '*') + result = randomNum * randomNum2; + if (operation == '/') + { + product = randomNum * randomNum2; + result = product / randomNum2; + randomNum = product; + } + + Console.WriteLine($"Question {count}! What is {randomNum} {operation} {randomNum2}?"); + string answer = Console.ReadLine(); + Console.WriteLine($"Your answer is {answer}"); + + if (int.TryParse(answer, out int validAnswer)) + { + if (validAnswer == result) + { + score++; + Console.WriteLine("Correct!"); + } + else + Console.WriteLine("That's the wrong answer."); + } + else + Console.WriteLine("The answer you entered was invalid. Please enter a whole number only."); + + count++; + randomNum = random.Next(1, 11); + randomNum2 = random.Next(1, 11); + } + + Console.WriteLine($"Your final score is {score}!"); +} \ No newline at end of file From 39e1c40513c2603032efee81d772a242b291275c Mon Sep 17 00:00:00 2001 From: purdyz Date: Sat, 17 Oct 2026 13:42:11 -0400 Subject: [PATCH 04/10] Added main game menu and loop --- MathGame.purdyz/MathGame.purdyz/Program.cs | 191 +++++++++++---------- 1 file changed, 100 insertions(+), 91 deletions(-) diff --git a/MathGame.purdyz/MathGame.purdyz/Program.cs b/MathGame.purdyz/MathGame.purdyz/Program.cs index fa9265ae..cff3ec91 100644 --- a/MathGame.purdyz/MathGame.purdyz/Program.cs +++ b/MathGame.purdyz/MathGame.purdyz/Program.cs @@ -4,114 +4,123 @@ string playerName = Console.ReadLine(); Console.WriteLine($"Nice to meet you, {playerName}!"); -// Main Menu -Console.WriteLine("Main Menu"); -Console.WriteLine("1. Play a game"); -Console.WriteLine("2. View History"); -Console.WriteLine("3. Exit"); -while (int.TryParse(Console.ReadLine(), out int menuChoice)) +// Main Menu + Game Loop +bool gameRunning = true; + +while (gameRunning) { + Console.WriteLine("Main Menu"); + Console.WriteLine("1. Play a game"); + Console.WriteLine("2. View History"); + Console.WriteLine("3. Exit"); + string menuChoice = Console.ReadLine(); + switch (menuChoice) - { - case 1: - GameSelection(); - break; - case 2: - Console.WriteLine("History available in a future update!"); - break; - case 3: - Console.WriteLine("Thanks for playing!"); - break; - default: - Console.WriteLine("The choice you selected was invalid. Please enter 1 through 3 only."); - break; - } -} + { + case "1": + GameSelection(); + break; + case "2": + Console.WriteLine("History available in a future update!"); + break; + case "3": + Console.WriteLine("Thanks for playing!"); + gameRunning = false; + break; + default: + Console.WriteLine("The choice you selected was invalid. Please enter 1 through 3 only."); + break; + } -// Choose a game -static void GameSelection() -{ - Console.WriteLine("Enter the number of a game to play:"); - Console.WriteLine("1. Addition"); - Console.WriteLine("2. Subtraction"); - Console.WriteLine("3. Multiplication"); - Console.WriteLine("4. Division"); - if (int.TryParse(Console.ReadLine(), out int gameChoice)) + // Choose a game + static void GameSelection() { - switch (gameChoice) + Console.WriteLine("Enter the number of a game to play:"); + Console.WriteLine("1. Addition"); + Console.WriteLine("2. Subtraction"); + Console.WriteLine("3. Multiplication"); + Console.WriteLine("4. Division"); + if (int.TryParse(Console.ReadLine(), out int gameChoice)) { - case 1: - Console.WriteLine("Addition selected!"); - AskQuestions('+'); - break; - case 2: - Console.WriteLine("Subtraction selected!"); - AskQuestions('-'); - break; - case 3: - Console.WriteLine("Multiplication selected!"); - AskQuestions('*'); - break; - case 4: - Console.WriteLine("Division selected!"); - AskQuestions('/'); - break; - default: - Console.WriteLine("Invalid choice"); - break; + switch (gameChoice) + { + case 1: + Console.WriteLine("Addition selected!"); + AskQuestions('+'); + break; + case 2: + Console.WriteLine("Subtraction selected!"); + AskQuestions('-'); + break; + case 3: + Console.WriteLine("Multiplication selected!"); + AskQuestions('*'); + break; + case 4: + Console.WriteLine("Division selected!"); + AskQuestions('/'); + break; + default: + Console.WriteLine("Invalid choice"); + break; + } } + else + Console.WriteLine("The choice you selected was invalid. Please enter 1 through 4 only."); } - else - Console.WriteLine("The choice you selected was invalid. Please enter 1 through 4 only."); -} -// Ask questions -static void AskQuestions(char operation) -{ - Random random = new Random(); - int count = 1; - int score = 0; - int randomNum = random.Next(1, 11); - int randomNum2 = random.Next(1, 11); - int result = 0; - int product = 0; - - while (count < 6) + // Ask questions + static void AskQuestions(char operation) { - if (operation == '+') - result = randomNum + randomNum2; - if (operation == '-') - result = randomNum - randomNum2; - if (operation == '*') - result = randomNum * randomNum2; - if (operation == '/') + Random random = new Random(); + int count = 1; + int score = 0; + int randomNum = random.Next(1, 11); + int randomNum2 = random.Next(1, 11); + int result = 0; + int product = 0; + + while (count < 6) { - product = randomNum * randomNum2; - result = product / randomNum2; - randomNum = product; - } + if (operation == '+') + result = randomNum + randomNum2; + if (operation == '-') + result = randomNum - randomNum2; + if (operation == '*') + result = randomNum * randomNum2; + if (operation == '/') + { + product = randomNum * randomNum2; + result = product / randomNum2; + randomNum = product; + } - Console.WriteLine($"Question {count}! What is {randomNum} {operation} {randomNum2}?"); - string answer = Console.ReadLine(); - Console.WriteLine($"Your answer is {answer}"); + Console.WriteLine($"Question {count}! What is {randomNum} {operation} {randomNum2}?"); + string answer = Console.ReadLine(); + Console.WriteLine($"Your answer is {answer}"); - if (int.TryParse(answer, out int validAnswer)) - { - if (validAnswer == result) + if (int.TryParse(answer, out int validAnswer)) { - score++; - Console.WriteLine("Correct!"); + if (validAnswer == result) + { + score++; + Console.WriteLine("Correct!"); + } + else + Console.WriteLine("That's the wrong answer."); } else - Console.WriteLine("That's the wrong answer."); + Console.WriteLine("The answer you entered was invalid. Please enter a whole number only."); + + count++; + randomNum = random.Next(1, 11); + randomNum2 = random.Next(1, 11); } - else - Console.WriteLine("The answer you entered was invalid. Please enter a whole number only."); - count++; - randomNum = random.Next(1, 11); - randomNum2 = random.Next(1, 11); + Console.WriteLine($"Your final score is {score}!"); } - Console.WriteLine($"Your final score is {score}!"); + Console.WriteLine("Press any key to continue"); + Console.ReadLine(); + Console.Clear(); } \ No newline at end of file From 40311d60ab29145d2df9c0264ef6cbd28b77a000 Mon Sep 17 00:00:00 2001 From: purdyz Date: Sat, 17 Oct 2026 16:52:37 -0400 Subject: [PATCH 05/10] Completed basic requirements --- MathGame.purdyz/MathGame.purdyz/Program.cs | 35 ++++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/MathGame.purdyz/MathGame.purdyz/Program.cs b/MathGame.purdyz/MathGame.purdyz/Program.cs index cff3ec91..753fbbe0 100644 --- a/MathGame.purdyz/MathGame.purdyz/Program.cs +++ b/MathGame.purdyz/MathGame.purdyz/Program.cs @@ -6,6 +6,7 @@ // Main Menu + Game Loop bool gameRunning = true; +List history = new List(); while (gameRunning) { @@ -21,7 +22,8 @@ GameSelection(); break; case "2": - Console.WriteLine("History available in a future update!"); + foreach (GameResult result in history) + Console.WriteLine($"{result.GameType} - {result.Score}"); break; case "3": Console.WriteLine("Thanks for playing!"); @@ -33,7 +35,7 @@ } // Choose a game - static void GameSelection() + void GameSelection() { Console.WriteLine("Enter the number of a game to play:"); Console.WriteLine("1. Addition"); @@ -70,11 +72,12 @@ static void GameSelection() } // Ask questions - static void AskQuestions(char operation) + void AskQuestions(char operation) { Random random = new Random(); int count = 1; int score = 0; + string gameType = string.Empty; int randomNum = random.Next(1, 11); int randomNum2 = random.Next(1, 11); int result = 0; @@ -83,16 +86,26 @@ static void AskQuestions(char operation) while (count < 6) { if (operation == '+') + { result = randomNum + randomNum2; - if (operation == '-') + gameType = "Addition"; + } + else if (operation == '-') + { result = randomNum - randomNum2; - if (operation == '*') + gameType = "Subtraction"; + } + else if (operation == '*') + { result = randomNum * randomNum2; - if (operation == '/') + gameType = "Multiplication"; + } + else if (operation == '/') { product = randomNum * randomNum2; result = product / randomNum2; randomNum = product; + gameType = "Division"; } Console.WriteLine($"Question {count}! What is {randomNum} {operation} {randomNum2}?"); @@ -117,10 +130,20 @@ static void AskQuestions(char operation) randomNum2 = random.Next(1, 11); } + GameResult currentResult = new GameResult(); + currentResult.GameType = gameType; + currentResult.Score = score; + history.Add(currentResult); Console.WriteLine($"Your final score is {score}!"); } Console.WriteLine("Press any key to continue"); Console.ReadLine(); Console.Clear(); +} + +class GameResult +{ + public string GameType { get; set; } + public int Score { get; set; } } \ No newline at end of file From 823e88e11325f83ff44eb6588288185dc452bd18 Mon Sep 17 00:00:00 2001 From: purdyz Date: Sat, 17 Oct 2026 18:20:42 -0400 Subject: [PATCH 06/10] Refactored basic game --- MathGame.purdyz/MathGame.purdyz/Program.cs | 193 +++++++++++---------- 1 file changed, 97 insertions(+), 96 deletions(-) diff --git a/MathGame.purdyz/MathGame.purdyz/Program.cs b/MathGame.purdyz/MathGame.purdyz/Program.cs index 753fbbe0..d9141dee 100644 --- a/MathGame.purdyz/MathGame.purdyz/Program.cs +++ b/MathGame.purdyz/MathGame.purdyz/Program.cs @@ -1,10 +1,8 @@ -// Welcome Message -Console.WriteLine("Welcome to the Math Game!"); +Console.WriteLine("Welcome to the Math Game!"); Console.Write("What's your name? "); string playerName = Console.ReadLine(); Console.WriteLine($"Nice to meet you, {playerName}!"); -// Main Menu + Game Loop bool gameRunning = true; List history = new List(); @@ -22,8 +20,7 @@ GameSelection(); break; case "2": - foreach (GameResult result in history) - Console.WriteLine($"{result.GameType} - {result.Score}"); + ViewHistory(); break; case "3": Console.WriteLine("Thanks for playing!"); @@ -34,112 +31,116 @@ break; } - // Choose a game - void GameSelection() + Console.WriteLine("Press any key to continue"); + Console.ReadLine(); + Console.Clear(); +} + +void GameSelection() +{ + Console.WriteLine("Enter the number of a game to play:"); + Console.WriteLine("1. Addition"); + Console.WriteLine("2. Subtraction"); + Console.WriteLine("3. Multiplication"); + Console.WriteLine("4. Division"); + + if (int.TryParse(Console.ReadLine(), out int gameChoice)) { - Console.WriteLine("Enter the number of a game to play:"); - Console.WriteLine("1. Addition"); - Console.WriteLine("2. Subtraction"); - Console.WriteLine("3. Multiplication"); - Console.WriteLine("4. Division"); - if (int.TryParse(Console.ReadLine(), out int gameChoice)) + switch (gameChoice) { - switch (gameChoice) - { - case 1: - Console.WriteLine("Addition selected!"); - AskQuestions('+'); - break; - case 2: - Console.WriteLine("Subtraction selected!"); - AskQuestions('-'); - break; - case 3: - Console.WriteLine("Multiplication selected!"); - AskQuestions('*'); - break; - case 4: - Console.WriteLine("Division selected!"); - AskQuestions('/'); - break; - default: - Console.WriteLine("Invalid choice"); - break; - } + case 1: + Console.WriteLine("Addition selected!"); + PlayRound("Addition", '+'); + break; + case 2: + Console.WriteLine("Subtraction selected!"); + PlayRound("Subtraction", '-'); + break; + case 3: + Console.WriteLine("Multiplication selected!"); + PlayRound("Multiplication", '*'); + break; + case 4: + Console.WriteLine("Division selected!"); + PlayRound("Division", '/'); + break; + default: + Console.WriteLine("Invalid choice"); + break; } - else - Console.WriteLine("The choice you selected was invalid. Please enter 1 through 4 only."); } + else + Console.WriteLine("The choice you selected was invalid. Please enter 1 through 4 only."); +} + +void PlayRound(string operation, char operand) +{ + Random random = new Random(); + int count = 1; + int score = 0; + int randomNum; + int randomNum2; + int product; + int result; - // Ask questions - void AskQuestions(char operation) + while (count < 6) { - Random random = new Random(); - int count = 1; - int score = 0; - string gameType = string.Empty; - int randomNum = random.Next(1, 11); - int randomNum2 = random.Next(1, 11); - int result = 0; - int product = 0; - - while (count < 6) - { - if (operation == '+') - { - result = randomNum + randomNum2; - gameType = "Addition"; - } - else if (operation == '-') - { - result = randomNum - randomNum2; - gameType = "Subtraction"; - } - else if (operation == '*') - { - result = randomNum * randomNum2; - gameType = "Multiplication"; - } - else if (operation == '/') - { - product = randomNum * randomNum2; - result = product / randomNum2; - randomNum = product; - gameType = "Division"; - } + randomNum = random.Next(1, 11); + randomNum2 = random.Next(1, 11); + + if (operation == "Division") + randomNum = randomNum * randomNum2; + + result = CalculateResult(operation, randomNum, randomNum2); - Console.WriteLine($"Question {count}! What is {randomNum} {operation} {randomNum2}?"); - string answer = Console.ReadLine(); - Console.WriteLine($"Your answer is {answer}"); + Console.WriteLine($"Question {count}! What is {randomNum} {operand} {randomNum2}?"); + string answer = Console.ReadLine(); + Console.WriteLine($"Your answer is {answer}"); - if (int.TryParse(answer, out int validAnswer)) + if (int.TryParse(answer, out int validAnswer)) + { + if (validAnswer == result) { - if (validAnswer == result) - { - score++; - Console.WriteLine("Correct!"); - } - else - Console.WriteLine("That's the wrong answer."); + score++; + Console.WriteLine("Correct!"); } else - Console.WriteLine("The answer you entered was invalid. Please enter a whole number only."); - - count++; - randomNum = random.Next(1, 11); - randomNum2 = random.Next(1, 11); + Console.WriteLine("That's the wrong answer."); } + else + Console.WriteLine("The answer you entered was invalid. Please enter a whole number only."); - GameResult currentResult = new GameResult(); - currentResult.GameType = gameType; - currentResult.Score = score; - history.Add(currentResult); - Console.WriteLine($"Your final score is {score}!"); + count++; } - Console.WriteLine("Press any key to continue"); - Console.ReadLine(); - Console.Clear(); + GameResult currentResult = new GameResult(); + currentResult.GameType = operation; + currentResult.Score = score; + history.Add(currentResult); + Console.WriteLine($"Your final score is {score}!"); +} + +static int CalculateResult(string operation, int randomNum, int randomNum2) +{ + if (operation == "Addition") + return randomNum + randomNum2; + else if (operation == "Subtraction") + return randomNum - randomNum2; + else if (operation == "Multiplication") + return randomNum * randomNum2; + else + return randomNum / randomNum2; +} + +void ViewHistory() +{ + if (history.Count > 0) + { + foreach (GameResult result in history) + Console.WriteLine($"{result.GameType} - {result.Score}"); + } + else + Console.WriteLine("No scores to display"); } class GameResult From dc29ff5e04430fb3c96892e314056fd0be65c62c Mon Sep 17 00:00:00 2001 From: purdyz Date: Sat, 17 Oct 2026 18:53:30 -0400 Subject: [PATCH 07/10] Added difficulty and timer --- MathGame.purdyz/MathGame.purdyz/Program.cs | 65 +++++++++++++++++++--- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/MathGame.purdyz/MathGame.purdyz/Program.cs b/MathGame.purdyz/MathGame.purdyz/Program.cs index d9141dee..af3ff134 100644 --- a/MathGame.purdyz/MathGame.purdyz/Program.cs +++ b/MathGame.purdyz/MathGame.purdyz/Program.cs @@ -1,4 +1,6 @@ -Console.WriteLine("Welcome to the Math Game!"); +using System.Diagnostics; + +Console.WriteLine("Welcome to the Math Game!"); Console.Write("What's your name? "); string playerName = Console.ReadLine(); Console.WriteLine($"Nice to meet you, {playerName}!"); @@ -75,25 +77,27 @@ void GameSelection() void PlayRound(string operation, char operand) { - Random random = new Random(); + int difficulty = ChooseDifficulty(); int count = 1; int score = 0; int randomNum; int randomNum2; int product; int result; + Stopwatch timer = new Stopwatch(); while (count < 6) { - randomNum = random.Next(1, 11); - randomNum2 = random.Next(1, 11); + randomNum = GenerateRandomNumber(difficulty); + randomNum2 = GenerateRandomNumber(difficulty); if (operation == "Division") - randomNum = randomNum * randomNum2; + randomNum = CalculateResult("Multiplication", randomNum, randomNum2); result = CalculateResult(operation, randomNum, randomNum2); Console.WriteLine($"Question {count}! What is {randomNum} {operand} {randomNum2}?"); + timer.Start(); string answer = Console.ReadLine(); Console.WriteLine($"Your answer is {answer}"); @@ -113,11 +117,56 @@ void PlayRound(string operation, char operand) count++; } + timer.Stop(); + GameResult currentResult = new GameResult(); currentResult.GameType = operation; currentResult.Score = score; + currentResult.Difficulty = difficulty; + currentResult.Time = timer.Elapsed; history.Add(currentResult); - Console.WriteLine($"Your final score is {score}!"); + Console.WriteLine($"Your final score is {score}! It took you {currentResult.Time}!"); +} + +static int ChooseDifficulty() +{ + Console.WriteLine("Choose a difficulty level"); + Console.WriteLine("1. Easy"); + Console.WriteLine("2. Medium"); + Console.WriteLine("3. Hard"); + + if (int.TryParse(Console.ReadLine(), out int difficultyChoice)) + { + switch (difficultyChoice) + { + case 1: + return 1; + case 2: + return 2; + case 3: + return 3; + default: + Console.WriteLine("Invalid choice. Defaulting to easy mode."); + return 1; + } + } + else + { + Console.WriteLine("The choice you selected was invalid. Defaulting to easy mode."); + return 1; + } +} + +static int GenerateRandomNumber(int difficulty) +{ + Random random = new Random(); + + if (difficulty == 3) + return random.Next(1, 1001); + if (difficulty == 2) + return random.Next(1, 101); + + return random.Next(1, 11); } static int CalculateResult(string operation, int randomNum, int randomNum2) @@ -137,7 +186,7 @@ void ViewHistory() if (history.Count > 0) { foreach (GameResult result in history) - Console.WriteLine($"{result.GameType} - {result.Score}"); + Console.WriteLine($"{result.GameType} - {result.Score} - {result.Difficulty} - {result.Time}"); } else Console.WriteLine("No scores to display"); @@ -147,4 +196,6 @@ class GameResult { public string GameType { get; set; } public int Score { get; set; } + public int Difficulty { get; set; } + public TimeSpan Time { get; set; } } \ No newline at end of file From adf8248181a57ae35df8f0e70a97106d04198193 Mon Sep 17 00:00:00 2001 From: purdyz Date: Sat, 17 Oct 2026 20:12:06 -0400 Subject: [PATCH 08/10] Implemented random game --- MathGame.purdyz/MathGame.purdyz/Program.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/MathGame.purdyz/MathGame.purdyz/Program.cs b/MathGame.purdyz/MathGame.purdyz/Program.cs index af3ff134..d37a22e1 100644 --- a/MathGame.purdyz/MathGame.purdyz/Program.cs +++ b/MathGame.purdyz/MathGame.purdyz/Program.cs @@ -45,6 +45,7 @@ void GameSelection() Console.WriteLine("2. Subtraction"); Console.WriteLine("3. Multiplication"); Console.WriteLine("4. Division"); + Console.WriteLine("5. Random"); if (int.TryParse(Console.ReadLine(), out int gameChoice)) { @@ -66,6 +67,10 @@ void GameSelection() Console.WriteLine("Division selected!"); PlayRound("Division", '/'); break; + case 5: + Console.WriteLine("Random selected!"); + PlayRound("Random", ' '); + break; default: Console.WriteLine("Invalid choice"); break; @@ -84,6 +89,7 @@ void PlayRound(string operation, char operand) int randomNum2; int product; int result; + bool randomGame = operation == "Random" ? true : false; Stopwatch timer = new Stopwatch(); while (count < 6) @@ -91,6 +97,16 @@ void PlayRound(string operation, char operand) randomNum = GenerateRandomNumber(difficulty); randomNum2 = GenerateRandomNumber(difficulty); + if (randomGame) + { + string[] operationArray = new string[] { "Addition", "Subtraction", "Multiplication", "Division" }; + char[] operandArray = new char[] { '+', '-', '*', '/' }; + Random random = new Random(); + int randomOperation = random.Next(0, 4); + operation = operationArray[randomOperation]; + operand = operandArray[randomOperation]; + } + if (operation == "Division") randomNum = CalculateResult("Multiplication", randomNum, randomNum2); @@ -120,7 +136,7 @@ void PlayRound(string operation, char operand) timer.Stop(); GameResult currentResult = new GameResult(); - currentResult.GameType = operation; + currentResult.GameType = randomGame ? "Random" : operation; currentResult.Score = score; currentResult.Difficulty = difficulty; currentResult.Time = timer.Elapsed; From 1ef0ed9e307efd5c044fd3795297c04373e9202b Mon Sep 17 00:00:00 2001 From: purdyz Date: Sat, 17 Oct 2026 20:45:28 -0400 Subject: [PATCH 09/10] Beginning refactoring --- MathGame.purdyz/MathGame.purdyz/Program.cs | 27 ++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/MathGame.purdyz/MathGame.purdyz/Program.cs b/MathGame.purdyz/MathGame.purdyz/Program.cs index d37a22e1..c77b285e 100644 --- a/MathGame.purdyz/MathGame.purdyz/Program.cs +++ b/MathGame.purdyz/MathGame.purdyz/Program.cs @@ -4,9 +4,11 @@ Console.Write("What's your name? "); string playerName = Console.ReadLine(); Console.WriteLine($"Nice to meet you, {playerName}!"); +Console.WriteLine(); bool gameRunning = true; List history = new List(); +Random random = new Random(); while (gameRunning) { @@ -33,7 +35,7 @@ break; } - Console.WriteLine("Press any key to continue"); + Console.WriteLine("Press any key to return to main menu."); Console.ReadLine(); Console.Clear(); } @@ -72,18 +74,22 @@ void GameSelection() PlayRound("Random", ' '); break; default: - Console.WriteLine("Invalid choice"); + Console.WriteLine("Invalid choice."); break; } } else - Console.WriteLine("The choice you selected was invalid. Please enter 1 through 4 only."); + { + Console.WriteLine("The choice you selected was invalid. Defaulting to random mode."); + PlayRound("Random", ' '); + } } void PlayRound(string operation, char operand) { int difficulty = ChooseDifficulty(); - int count = 1; + int roundNumber = 1; + int maxRounds = 5; int score = 0; int randomNum; int randomNum2; @@ -92,7 +98,7 @@ void PlayRound(string operation, char operand) bool randomGame = operation == "Random" ? true : false; Stopwatch timer = new Stopwatch(); - while (count < 6) + while (roundNumber <= maxRounds) { randomNum = GenerateRandomNumber(difficulty); randomNum2 = GenerateRandomNumber(difficulty); @@ -101,7 +107,6 @@ void PlayRound(string operation, char operand) { string[] operationArray = new string[] { "Addition", "Subtraction", "Multiplication", "Division" }; char[] operandArray = new char[] { '+', '-', '*', '/' }; - Random random = new Random(); int randomOperation = random.Next(0, 4); operation = operationArray[randomOperation]; operand = operandArray[randomOperation]; @@ -112,7 +117,7 @@ void PlayRound(string operation, char operand) result = CalculateResult(operation, randomNum, randomNum2); - Console.WriteLine($"Question {count}! What is {randomNum} {operand} {randomNum2}?"); + Console.WriteLine($"Question {roundNumber}! What is {randomNum} {operand} {randomNum2}?"); timer.Start(); string answer = Console.ReadLine(); Console.WriteLine($"Your answer is {answer}"); @@ -128,9 +133,9 @@ void PlayRound(string operation, char operand) Console.WriteLine("That's the wrong answer."); } else - Console.WriteLine("The answer you entered was invalid. Please enter a whole number only."); + Console.WriteLine("The answer you entered was invalid. Please enter a whole number only. Marking as incorrect!"); - count++; + roundNumber++; } timer.Stop(); @@ -173,10 +178,8 @@ static int ChooseDifficulty() } } -static int GenerateRandomNumber(int difficulty) +int GenerateRandomNumber(int difficulty) { - Random random = new Random(); - if (difficulty == 3) return random.Next(1, 1001); if (difficulty == 2) From f43797efe54136bde156f960245d9f15e544d3c8 Mon Sep 17 00:00:00 2001 From: purdyz Date: Sun, 18 Oct 2026 17:44:32 -0400 Subject: [PATCH 10/10] Final refactoring --- MathGame.purdyz/MathGame.purdyz/GameResult.cs | 9 ++ MathGame.purdyz/MathGame.purdyz/Program.cs | 130 +++++++++--------- 2 files changed, 77 insertions(+), 62 deletions(-) create mode 100644 MathGame.purdyz/MathGame.purdyz/GameResult.cs diff --git a/MathGame.purdyz/MathGame.purdyz/GameResult.cs b/MathGame.purdyz/MathGame.purdyz/GameResult.cs new file mode 100644 index 00000000..35882e10 --- /dev/null +++ b/MathGame.purdyz/MathGame.purdyz/GameResult.cs @@ -0,0 +1,9 @@ +namespace MathGame.purdyz; + +internal class GameResult +{ + public string? GameType { get; set; } + public int Score { get; set; } + public string? Difficulty { get; set; } + public string? Time { get; set; } +} \ No newline at end of file diff --git a/MathGame.purdyz/MathGame.purdyz/Program.cs b/MathGame.purdyz/MathGame.purdyz/Program.cs index c77b285e..e522e855 100644 --- a/MathGame.purdyz/MathGame.purdyz/Program.cs +++ b/MathGame.purdyz/MathGame.purdyz/Program.cs @@ -1,43 +1,53 @@ using System.Diagnostics; +using MathGame.purdyz; -Console.WriteLine("Welcome to the Math Game!"); -Console.Write("What's your name? "); -string playerName = Console.ReadLine(); -Console.WriteLine($"Nice to meet you, {playerName}!"); -Console.WriteLine(); - +WelcomePlayer(); bool gameRunning = true; List history = new List(); Random random = new Random(); -while (gameRunning) +MainGame(); + +void WelcomePlayer() { - Console.WriteLine("Main Menu"); - Console.WriteLine("1. Play a game"); - Console.WriteLine("2. View History"); - Console.WriteLine("3. Exit"); - string menuChoice = Console.ReadLine(); + Console.WriteLine("Welcome to the Math Game!"); + Console.Write("What's your name? "); + string? playerName = Console.ReadLine(); + Console.WriteLine($"Nice to meet you, {playerName}!"); + Console.WriteLine(); +} - switch (menuChoice) +void MainGame() +{ + while (gameRunning) { - case "1": - GameSelection(); - break; - case "2": - ViewHistory(); - break; - case "3": - Console.WriteLine("Thanks for playing!"); - gameRunning = false; - break; - default: - Console.WriteLine("The choice you selected was invalid. Please enter 1 through 3 only."); - break; - } + Console.WriteLine("Main Menu"); + Console.WriteLine("1. Play a game"); + Console.WriteLine("2. View History"); + Console.WriteLine("3. Exit"); + string? menuChoice = Console.ReadLine(); + + switch (menuChoice) + { + case "1": + GameSelection(); + break; + case "2": + ViewHistory(); + break; + case "3": + Console.WriteLine("Thanks for playing!"); + gameRunning = false; + break; + default: + Console.WriteLine("The choice you selected was invalid. Please enter 1 through 3 only."); + break; + } - Console.WriteLine("Press any key to return to main menu."); - Console.ReadLine(); - Console.Clear(); + Console.WriteLine("Press any key to return to main menu."); + Console.ReadLine(); + Console.Clear(); + } } void GameSelection() @@ -87,13 +97,12 @@ void GameSelection() void PlayRound(string operation, char operand) { - int difficulty = ChooseDifficulty(); + string difficulty = ChooseDifficulty(); int roundNumber = 1; int maxRounds = 5; int score = 0; int randomNum; int randomNum2; - int product; int result; bool randomGame = operation == "Random" ? true : false; Stopwatch timer = new Stopwatch(); @@ -113,13 +122,13 @@ void PlayRound(string operation, char operand) } if (operation == "Division") - randomNum = CalculateResult("Multiplication", randomNum, randomNum2); + randomNum = Calculate("Multiplication", randomNum, randomNum2); - result = CalculateResult(operation, randomNum, randomNum2); + result = Calculate(operation, randomNum, randomNum2); Console.WriteLine($"Question {roundNumber}! What is {randomNum} {operand} {randomNum2}?"); timer.Start(); - string answer = Console.ReadLine(); + string? answer = Console.ReadLine(); Console.WriteLine($"Your answer is {answer}"); if (int.TryParse(answer, out int validAnswer)) @@ -139,17 +148,11 @@ void PlayRound(string operation, char operand) } timer.Stop(); - - GameResult currentResult = new GameResult(); - currentResult.GameType = randomGame ? "Random" : operation; - currentResult.Score = score; - currentResult.Difficulty = difficulty; - currentResult.Time = timer.Elapsed; - history.Add(currentResult); - Console.WriteLine($"Your final score is {score}! It took you {currentResult.Time}!"); + RecordResults(randomGame, operation, score, difficulty, timer); + Console.WriteLine($"Your final score is {score}! It took you {timer.Elapsed.ToString(@"mm\:ss")}!"); } -static int ChooseDifficulty() +static string ChooseDifficulty() { Console.WriteLine("Choose a difficulty level"); Console.WriteLine("1. Easy"); @@ -161,34 +164,44 @@ static int ChooseDifficulty() switch (difficultyChoice) { case 1: - return 1; + return "Easy"; case 2: - return 2; + return "Medium"; case 3: - return 3; + return "Hard"; default: Console.WriteLine("Invalid choice. Defaulting to easy mode."); - return 1; + return "Easy"; } } else { Console.WriteLine("The choice you selected was invalid. Defaulting to easy mode."); - return 1; + return "Easy"; } } -int GenerateRandomNumber(int difficulty) +int GenerateRandomNumber(string difficulty) { - if (difficulty == 3) + if (difficulty.Equals("Hard")) return random.Next(1, 1001); - if (difficulty == 2) + if (difficulty.Equals("Medium")) return random.Next(1, 101); return random.Next(1, 11); } -static int CalculateResult(string operation, int randomNum, int randomNum2) +void RecordResults(bool randomGame, string operation, int score, string difficulty, Stopwatch timer) +{ + GameResult currentResult = new GameResult(); + currentResult.GameType = randomGame ? "Random" : operation; + currentResult.Score = score; + currentResult.Difficulty = difficulty; + currentResult.Time = timer.Elapsed.ToString(@"mm\:ss"); + history.Add(currentResult); +} + +static int Calculate(string operation, int randomNum, int randomNum2) { if (operation == "Addition") return randomNum + randomNum2; @@ -204,17 +217,10 @@ void ViewHistory() { if (history.Count > 0) { + Console.WriteLine($"{"Game Type", -15} {"Score", -6} {"Difficulty", -12} {"Time Elapsed", -12}"); foreach (GameResult result in history) - Console.WriteLine($"{result.GameType} - {result.Score} - {result.Difficulty} - {result.Time}"); + Console.WriteLine($"{result.GameType, -15} {result.Score, -6} {result.Difficulty, -12} {result.Time, -12}"); } else Console.WriteLine("No scores to display"); -} - -class GameResult -{ - public string GameType { get; set; } - public int Score { get; set; } - public int Difficulty { get; set; } - public TimeSpan Time { get; set; } } \ No newline at end of file