From e2e8d78faae1e2b230772d8a8d116af4c3db367a Mon Sep 17 00:00:00 2001
From: hacc-ount <214715279+hacc-ount@users.noreply.github.com>
Date: Fri, 24 Jul 2026 15:36:58 +0100
Subject: [PATCH 1/4] Moving project files from other repository
Moved files from my other repository to this
forked repository. The link to my other
repository is here:
https://github.com/hacc-ount/CSharpAcademy_MathsGame
---
MathsGame/MathsGame.slnx | 3 +
MathsGame/MathsGame/GameFunctions.cs | 113 +++++++++++++++++
MathsGame/MathsGame/Games.cs | 175 +++++++++++++++++++++++++++
MathsGame/MathsGame/Helpers.cs | 25 ++++
MathsGame/MathsGame/MathsGame.csproj | 10 ++
MathsGame/MathsGame/Operations.cs | 11 ++
MathsGame/MathsGame/Program.cs | 92 ++++++++++++++
7 files changed, 429 insertions(+)
create mode 100644 MathsGame/MathsGame.slnx
create mode 100644 MathsGame/MathsGame/GameFunctions.cs
create mode 100644 MathsGame/MathsGame/Games.cs
create mode 100644 MathsGame/MathsGame/Helpers.cs
create mode 100644 MathsGame/MathsGame/MathsGame.csproj
create mode 100644 MathsGame/MathsGame/Operations.cs
create mode 100644 MathsGame/MathsGame/Program.cs
diff --git a/MathsGame/MathsGame.slnx b/MathsGame/MathsGame.slnx
new file mode 100644
index 00000000..17475ec7
--- /dev/null
+++ b/MathsGame/MathsGame.slnx
@@ -0,0 +1,3 @@
+
+
+
diff --git a/MathsGame/MathsGame/GameFunctions.cs b/MathsGame/MathsGame/GameFunctions.cs
new file mode 100644
index 00000000..aef7ba1c
--- /dev/null
+++ b/MathsGame/MathsGame/GameFunctions.cs
@@ -0,0 +1,113 @@
+using System.Timers;
+
+namespace MathsGame;
+
+public class GameFunctions
+{
+ const int EASY = 1;
+ const int MEDIUM = 2;
+ const int HARD = 3;
+
+ internal static System.Timers.Timer newTimer;
+ internal static int seconds;
+
+ internal static int[] SetDifficulty(int[] difficulty)
+ {
+ // Set up initial variables
+ string? result;
+ bool validInput = false;
+ int userChoice = 0;
+
+ do
+ {
+ Helpers.ConsoleClear();
+ Console.WriteLine($"Choose your difficulty:\n");
+ Console.WriteLine("1. Easy");
+ Console.WriteLine("2. Medium");
+ Console.WriteLine("3. Hard\n");
+ Console.WriteLine("Enter a valid number from the list.");
+
+ result = Console.ReadLine();
+
+ if (result == null)
+ {
+ Console.WriteLine("Input is null. Exiting the program");
+ Environment.Exit(1);
+ return difficulty;
+ }
+
+ try
+ {
+ int.Parse(result);
+
+ }
+ catch (ArgumentNullException)
+ {
+ Console.WriteLine("No input detected. Please choose an option from the menu.\n");
+ continue;
+ }
+ catch (FormatException)
+ {
+ Console.WriteLine($"{result} is not a valid number. Please choose an option from the menu.\n");
+ continue;
+ }
+
+ userChoice = int.Parse(result);
+ if (Helpers.isInRange(userChoice, 1, 3))
+ {
+ validInput = true;
+ }
+ else
+ {
+ Console.WriteLine($"{userChoice} is not a menu option. Please choose again.\n");
+ }
+
+ } while (validInput == false);
+
+ switch (userChoice)
+ {
+ case EASY:
+ difficulty[0] = 0;
+ difficulty[1] = 9;
+ return difficulty;
+ case MEDIUM:
+ difficulty[0] = 0;
+ difficulty[1] = 100;
+ return difficulty;
+ case HARD:
+ difficulty[0] = -100;
+ difficulty[1] = 100;
+ return difficulty;
+ default:
+ difficulty[0] = 0;
+ difficulty[1] = 9;
+ return difficulty;
+ }
+ }
+
+ internal static void ViewLog(List log)
+ {
+ Console.WriteLine("---------- Past Games Log ----------\n");
+
+ foreach (string line in log)
+ {
+ Console.WriteLine(line);
+ }
+ Console.WriteLine();
+ Console.WriteLine("Press any key to return to the main menu.");
+ Console.ReadLine();
+ }
+
+ internal static bool DividesIntoInt(int firstNumber, int secondNumber)
+ {
+ if (firstNumber % secondNumber == 0)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+}
+
diff --git a/MathsGame/MathsGame/Games.cs b/MathsGame/MathsGame/Games.cs
new file mode 100644
index 00000000..994b566e
--- /dev/null
+++ b/MathsGame/MathsGame/Games.cs
@@ -0,0 +1,175 @@
+using System.Timers;
+
+namespace MathsGame;
+
+internal class Games
+{
+
+ internal static System.Timers.Timer aTimer;
+ internal static int seconds;
+
+ /* Function to run the game rounds. Picks a game based on the game choice
+ * which is found in the main Program.cs.*/
+ internal static void Game(string gameChoice, int[] difficulty, int MAX_ROUNDS, List gameLog)
+ {
+
+ // Initial variables
+ Random random = new Random();
+ int firstNumber;
+ int secondNumber;
+ int score = 0;
+ int userAnswer;
+ seconds = 0;
+
+ Console.Clear();
+ Console.WriteLine($"{gameChoice} game started...\n");
+
+ startTimer();
+
+ // Run rounds
+ for (int round = 0; round < MAX_ROUNDS; round++)
+ {
+ // Temporarily set the answer back to zero within the loop
+ userAnswer = 0;
+
+ //
+ firstNumber = random.Next(difficulty[0], difficulty[1]);
+ secondNumber = random.Next(difficulty[0], difficulty[1]);
+
+ // Handle division game option
+ if (gameChoice == "Division")
+ {
+ if (firstNumber == 0)
+ firstNumber += 1;
+ if (secondNumber == 0)
+ secondNumber += 1;
+ while (!GameFunctions.DividesIntoInt(firstNumber, secondNumber))
+ {
+ firstNumber = random.Next(difficulty[0], difficulty[1]);
+ secondNumber = random.Next(difficulty[0], difficulty[1]);
+ if (firstNumber == 0)
+ firstNumber += 1;
+ if (secondNumber == 0)
+ secondNumber += 1;
+ }
+ }
+
+ // List of Operation objects with different game operations
+ List operations = new List()
+ {
+ new Operations(firstNumber, secondNumber)
+ {
+ Result = firstNumber + secondNumber,
+ Question = $"What is {firstNumber} + {secondNumber}?\n"
+ },
+ new Operations(firstNumber, secondNumber)
+ {
+ Result = firstNumber - secondNumber,
+ Question = $"What is {firstNumber} - {secondNumber}?\n"
+ }
+ };
+
+
+ // Set a random game (or operation) from operations
+ Operations randomChoice = operations[random.Next(2)];
+
+ // Ask the question based on the game choice and get the answer
+ int correctAnswer = GetAnswer(gameChoice, firstNumber, secondNumber, randomChoice);
+
+ // Get user input
+ string? result = Console.ReadLine();
+ if (result == null)
+ {
+ Console.WriteLine("Result was null.");
+ Environment.Exit(1);
+ }
+
+ // Check the user input
+ try
+ {
+ userAnswer = int.Parse(result);
+ }
+ catch (FormatException)
+ {
+ Console.WriteLine("Invalid number.");
+ }
+
+ // Check the users answer and display messages
+ score += CheckAnswers(round, MAX_ROUNDS, userAnswer, correctAnswer);
+
+ Helpers.ConsoleClear();
+ }
+
+ // Remove the timer
+ aTimer.Stop();
+ aTimer.Dispose();
+
+ Console.WriteLine("Game Over. Press any key to return to the main menu.\n");
+ Console.ReadLine();
+
+ string log = $"{gameChoice}: Total Score: {score}, Total Seconds: {seconds} --- {DateTime.Now}";
+ gameLog.Add(log);
+ }
+
+ // Function for asking the appropriate game question and getting the result.
+ private static int GetAnswer(string gameChoice, int firstNumber, int secondNumber, Operations randomChoice)
+ {
+ switch (gameChoice)
+ {
+ case "Addition":
+ Console.WriteLine($"What is {firstNumber} + {secondNumber}?\n");
+ return firstNumber + secondNumber;
+ case "Division":
+ Console.WriteLine($"What is {firstNumber} / {secondNumber}?\n");
+ return firstNumber / secondNumber;
+ case "Random":
+ Console.WriteLine(randomChoice.Question);
+ return randomChoice.Result;
+ default:
+ Console.WriteLine("Error, no gamemode selected.");
+ return -10000; // This number will never be reached, so it equals an error.
+ }
+ }
+
+ // Function for checking the user answer against the correct answer.
+ private static int CheckAnswers(int round, int MAX_ROUNDS, int userAnswer, int correctAnswer)
+ {
+ int score = 0;
+ if (userAnswer == correctAnswer && round == MAX_ROUNDS - 1)
+ {
+ Console.WriteLine("Correct answer.");
+ score++;
+ return score;
+ }
+ else if (userAnswer == correctAnswer && round <= MAX_ROUNDS - 1)
+ {
+ Console.WriteLine("Correct answer.\n");
+ score++;
+ return score;
+ }
+ else if (userAnswer != correctAnswer && round == MAX_ROUNDS - 1)
+ {
+ Console.WriteLine($"Incorrect. The answer was {correctAnswer}.");
+ return score;
+ }
+ else
+ {
+ Console.WriteLine($"Incorrect. The answer was {correctAnswer}.\n");
+ return score;
+ }
+ }
+
+ private static void startTimer()
+ {
+ aTimer = new System.Timers.Timer(1000);
+ aTimer.Start();
+ aTimer.Elapsed += timerEvent;
+ aTimer.AutoReset = true;
+ aTimer.Enabled = true;
+ }
+
+ private static void timerEvent(Object source, ElapsedEventArgs e)
+ {
+ seconds += 1;
+ }
+}
diff --git a/MathsGame/MathsGame/Helpers.cs b/MathsGame/MathsGame/Helpers.cs
new file mode 100644
index 00000000..f0e0ae23
--- /dev/null
+++ b/MathsGame/MathsGame/Helpers.cs
@@ -0,0 +1,25 @@
+using System.Diagnostics.Contracts;
+
+namespace MathsGame;
+
+internal class Helpers
+{
+ internal static bool isInRange(int number, int lowerBound, int higherBound)
+ {
+ if (number < lowerBound || number > higherBound)
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ internal static void ConsoleClear()
+ {
+ Thread.Sleep(1000);
+ Console.Clear();
+ }
+
+}
diff --git a/MathsGame/MathsGame/MathsGame.csproj b/MathsGame/MathsGame/MathsGame.csproj
new file mode 100644
index 00000000..ed9781c2
--- /dev/null
+++ b/MathsGame/MathsGame/MathsGame.csproj
@@ -0,0 +1,10 @@
+
+
+
+ Exe
+ net10.0
+ enable
+ enable
+
+
+
diff --git a/MathsGame/MathsGame/Operations.cs b/MathsGame/MathsGame/Operations.cs
new file mode 100644
index 00000000..f5e1545e
--- /dev/null
+++ b/MathsGame/MathsGame/Operations.cs
@@ -0,0 +1,11 @@
+namespace MathsGame
+{
+ internal class Operations
+ {
+ internal int Result { get; set; }
+ internal string? Question { get; set; }
+
+ internal Operations(int first, int second) { }
+
+ }
+}
diff --git a/MathsGame/MathsGame/Program.cs b/MathsGame/MathsGame/Program.cs
new file mode 100644
index 00000000..d7bf4b73
--- /dev/null
+++ b/MathsGame/MathsGame/Program.cs
@@ -0,0 +1,92 @@
+using MathsGame;
+
+// Game parameters
+const int MAX_ROUNDS = 2;
+int[] difficulty = new int[2];
+bool gameRunning = false;
+
+// Game Log
+List gameLog = new List();
+
+// Run initial difficulty setting
+GameFunctions.SetDifficulty(difficulty);
+
+TheMenu();
+
+void TheMenu()
+{
+ do
+ {
+ gameRunning = true;
+
+ Console.WriteLine("---------- Maths Game ----------");
+ Console.WriteLine("Select an option below by typing in the command line:\n");
+
+ Console.WriteLine("! - Change Difficulty\n");
+
+ Console.WriteLine("V - View Past Games\n");
+
+ Console.WriteLine("A - Addition");
+ Console.WriteLine("S - Subtraction");
+ Console.WriteLine("M - Multiplication");
+ Console.WriteLine("D - Division");
+ Console.WriteLine("R - Random\n");
+
+ Console.WriteLine("Q - Quit\n");
+
+ string? result = Console.ReadLine();
+ if (result == null)
+ {
+ Console.WriteLine("Input was null, exiting game.");
+ Environment.Exit(1);
+ }
+
+ try
+ {
+ char userInput = Convert.ToChar(result.Trim().ToLower());
+ if (Char.IsPunctuation(userInput))
+ {
+ switch (userInput)
+ {
+ case '!':
+ GameFunctions.SetDifficulty(difficulty);
+ break;
+
+ }
+ }
+ else if (Char.IsAsciiLetter(userInput))
+ {
+ switch (userInput)
+ {
+ // Place an arguement in the main Game() function that can be used to determine what
+ // operations to use.
+ case 'a':
+ Games.Game("Addition", difficulty, MAX_ROUNDS, gameLog);
+ break;
+ case 'd':
+ Games.Game("Division", difficulty, MAX_ROUNDS, gameLog);
+ break;
+ case 'v':
+ GameFunctions.ViewLog(gameLog);
+ break;
+ case 'r':
+ Games.Game("Random", difficulty, MAX_ROUNDS, gameLog);
+ break;
+ case 'q':
+ gameRunning = false;
+ Environment.Exit(1);
+ break;
+ }
+ }
+ else
+ {
+
+ }
+ }
+ catch (FormatException)
+ {
+ Console.WriteLine($"{result} has too many characters. Please only input one character.");
+ }
+
+ } while (gameRunning);
+}
From 708b4a61d988b523851ed54bdea94b220c15c081 Mon Sep 17 00:00:00 2001
From: hacc-ount <214715279+hacc-ount@users.noreply.github.com>
Date: Sun, 26 Jul 2026 11:29:06 +0100
Subject: [PATCH 2/4] Edit the output to the console
Added a few Console.Clear() to make it neater.
---
MathsGame/MathsGame/GameFunctions.cs | 1 +
MathsGame/MathsGame/Games.cs | 1 -
MathsGame/MathsGame/Program.cs | 3 +++
3 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/MathsGame/MathsGame/GameFunctions.cs b/MathsGame/MathsGame/GameFunctions.cs
index aef7ba1c..e0e11059 100644
--- a/MathsGame/MathsGame/GameFunctions.cs
+++ b/MathsGame/MathsGame/GameFunctions.cs
@@ -87,6 +87,7 @@ internal static int[] SetDifficulty(int[] difficulty)
internal static void ViewLog(List log)
{
+ Console.Clear();
Console.WriteLine("---------- Past Games Log ----------\n");
foreach (string line in log)
diff --git a/MathsGame/MathsGame/Games.cs b/MathsGame/MathsGame/Games.cs
index 994b566e..2abfb0b9 100644
--- a/MathsGame/MathsGame/Games.cs
+++ b/MathsGame/MathsGame/Games.cs
@@ -12,7 +12,6 @@ internal class Games
* which is found in the main Program.cs.*/
internal static void Game(string gameChoice, int[] difficulty, int MAX_ROUNDS, List gameLog)
{
-
// Initial variables
Random random = new Random();
int firstNumber;
diff --git a/MathsGame/MathsGame/Program.cs b/MathsGame/MathsGame/Program.cs
index d7bf4b73..446f4c33 100644
--- a/MathsGame/MathsGame/Program.cs
+++ b/MathsGame/MathsGame/Program.cs
@@ -10,6 +10,7 @@
// Run initial difficulty setting
GameFunctions.SetDifficulty(difficulty);
+Console.Clear();
TheMenu();
@@ -17,6 +18,7 @@ void TheMenu()
{
do
{
+ Console.Clear();
gameRunning = true;
Console.WriteLine("---------- Maths Game ----------");
@@ -86,6 +88,7 @@ void TheMenu()
catch (FormatException)
{
Console.WriteLine($"{result} has too many characters. Please only input one character.");
+ Helpers.ConsoleClear();
}
} while (gameRunning);
From 185ceb234222f1f5a20b9b740f34c7447165adaa Mon Sep 17 00:00:00 2001
From: hacc-ount <214715279+hacc-ount@users.noreply.github.com>
Date: Sun, 26 Jul 2026 11:47:40 +0100
Subject: [PATCH 3/4] Add game options
Added Subtraction and Multiplication games.
---
MathsGame/MathsGame/Games.cs | 8 +++++++-
MathsGame/MathsGame/Program.cs | 6 ++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/MathsGame/MathsGame/Games.cs b/MathsGame/MathsGame/Games.cs
index 2abfb0b9..6fbeb8c3 100644
--- a/MathsGame/MathsGame/Games.cs
+++ b/MathsGame/MathsGame/Games.cs
@@ -106,7 +106,7 @@ internal static void Game(string gameChoice, int[] difficulty, int MAX_ROUNDS, L
Console.WriteLine("Game Over. Press any key to return to the main menu.\n");
Console.ReadLine();
- string log = $"{gameChoice}: Total Score: {score}, Total Seconds: {seconds} --- {DateTime.Now}";
+ string log = $"{gameChoice}: Difficulty: {difficulty[0]} to {difficulty[1]}, Total Score: {score}, Total Seconds: {seconds} --- {DateTime.Now}";
gameLog.Add(log);
}
@@ -118,6 +118,12 @@ private static int GetAnswer(string gameChoice, int firstNumber, int secondNumbe
case "Addition":
Console.WriteLine($"What is {firstNumber} + {secondNumber}?\n");
return firstNumber + secondNumber;
+ case "Subtraction":
+ Console.WriteLine($"What is {firstNumber} - {secondNumber}?\n");
+ return firstNumber - secondNumber;
+ case "Multiplication":
+ Console.WriteLine($"What is {firstNumber} * {secondNumber}?\n");
+ return firstNumber * secondNumber;
case "Division":
Console.WriteLine($"What is {firstNumber} / {secondNumber}?\n");
return firstNumber / secondNumber;
diff --git a/MathsGame/MathsGame/Program.cs b/MathsGame/MathsGame/Program.cs
index 446f4c33..91f1a3ad 100644
--- a/MathsGame/MathsGame/Program.cs
+++ b/MathsGame/MathsGame/Program.cs
@@ -65,6 +65,12 @@ void TheMenu()
case 'a':
Games.Game("Addition", difficulty, MAX_ROUNDS, gameLog);
break;
+ case 's':
+ Games.Game("Subtraction", difficulty, MAX_ROUNDS, gameLog);
+ break;
+ case 'm':
+ Games.Game("Multiplication", difficulty, MAX_ROUNDS, gameLog);
+ break;
case 'd':
Games.Game("Division", difficulty, MAX_ROUNDS, gameLog);
break;
From 86e6332c35bb738ca693516ee678d6447b50a41f Mon Sep 17 00:00:00 2001
From: hacc-ount <214715279+hacc-ount@users.noreply.github.com>
Date: Sun, 26 Jul 2026 11:52:19 +0100
Subject: [PATCH 4/4] Change MAX_ROUNDS value
The game now runs for 5 rounds.
---
MathsGame/MathsGame/Program.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/MathsGame/MathsGame/Program.cs b/MathsGame/MathsGame/Program.cs
index 91f1a3ad..67680c5f 100644
--- a/MathsGame/MathsGame/Program.cs
+++ b/MathsGame/MathsGame/Program.cs
@@ -1,7 +1,7 @@
using MathsGame;
// Game parameters
-const int MAX_ROUNDS = 2;
+const int MAX_ROUNDS = 5;
int[] difficulty = new int[2];
bool gameRunning = false;