From 72262afe9203dfdf2d4696925c8e0c8302d8937e Mon Sep 17 00:00:00 2001 From: Decimo Date: Sat, 7 Nov 2026 18:41:12 -0600 Subject: [PATCH] Finished Project --- AcaMathGame/AcaMathGame.csproj | 10 ++ AcaMathGame/Program.cs | 235 +++++++++++++++++++++++++++++++++ 2 files changed, 245 insertions(+) create mode 100644 AcaMathGame/AcaMathGame.csproj create mode 100644 AcaMathGame/Program.cs diff --git a/AcaMathGame/AcaMathGame.csproj b/AcaMathGame/AcaMathGame.csproj new file mode 100644 index 00000000..ed9781c2 --- /dev/null +++ b/AcaMathGame/AcaMathGame.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/AcaMathGame/Program.cs b/AcaMathGame/Program.cs new file mode 100644 index 00000000..62927471 --- /dev/null +++ b/AcaMathGame/Program.cs @@ -0,0 +1,235 @@ +using System.ComponentModel.Design; +using System.Formats.Asn1; + +Console.WriteLine("Please type your name"); +string? name = Console.ReadLine(); + +var games = new List(); +Random rand = new Random(); +int answer; +bool playAgain = true; + + +WhichGame(); + + +// Main method to call games +void WhichGame() +{ + do + { + Console.WriteLine("-------------------------------------------"); + Console.WriteLine($"Hello {name.ToUpper()} today's date is {DateTime.UtcNow}. Here is the menu for today's game:"); + Console.WriteLine($@"Please select a game you would like to play. + V - View Previous Games + A - Addition + S - Subtraction + M - Multiplication + D - Division + Q - Quit the program"); + Console.WriteLine("------------------------------------------"); + var gameSelected = Console.ReadLine().Trim().ToUpper(); + Console.Clear(); + + switch (gameSelected) + { + case "V": + GetGames(); + break; + case "A": + Console.Clear(); + Console.WriteLine("Addition Game Selected"); + AdditionGame(); + break; + + case "S": + Console.Clear(); + Console.WriteLine("Subtraction Game Selected"); + SubtractionGame(); + break; + + case "M": + Console.Clear(); + Console.WriteLine("Multiplication Game Selected"); + MultiGame(); + break; + + case "D": + Console.Clear(); + Console.WriteLine("Division Game Selected"); + DivisionGame(); + break; + + case "Q": + playAgain = false; + Console.WriteLine("User has quit the game"); + break; + + default: + + Console.WriteLine("Invalid Input"); + break; + } + } while (playAgain); + + +} + +void GetGames() +{ + Console.Clear(); + Console.WriteLine("Game History"); + Console.WriteLine("-------------------"); + foreach (var game in games) + { + Console.WriteLine(game); + } + Console.WriteLine("-------------------\n"); + Console.WriteLine("Press any key to return to the menu"); + Console.ReadLine(); +} + +// Methods for each game +void AdditionGame() +{ + int questions = 0; + int points = 0; + + do + { + int num1 = rand.Next(10); + int num2 = rand.Next(10); + answer = (num1 + num2); + + Console.WriteLine($"Solve {num1} + {num2}"); + int userAn = Convert.ToInt32(Console.ReadLine()); + questions++; + + if (answer == userAn) // Point tracker + { + points++; + Console.WriteLine("Correct!"); + } + else + { + Console.WriteLine("Incorrect!"); + } + + } while (questions < 7); // Loop questions until 7 + + Console.WriteLine("You finished with a score of " + points + "!"); + Console.WriteLine("Press any key to play again"); + + AddToHistory(points, "Addition"); +} + +void SubtractionGame() +{ + int questions = 0; + int points = 0; + + do + { + int num1 = rand.Next(10); + int num2 = rand.Next(10); + answer = (num1 - num2); + + Console.WriteLine($"Solve {num1} - {num2}"); + int userAn = Convert.ToInt32(Console.ReadLine()); + questions++; + + if (answer == userAn) // Point tracker + { + points++; + Console.WriteLine("Correct!"); + } + else + { + Console.WriteLine("Incorrect!"); + } + + } while (questions < 7); // Loop questions until 7 + + Console.WriteLine("You finished with a score of " + points + "!"); + Console.WriteLine("Press any key to play again"); + + AddToHistory(points, "Subtraction"); +} + +void MultiGame() +{ + int questions = 0; + int points = 0; + + do + { + int num1 = rand.Next(10); + int num2 = rand.Next(10); + answer = (num1 * num2); + + Console.WriteLine($"Solve {num1} * {num2}"); + int userAn = Convert.ToInt32(Console.ReadLine()); + questions++; + + if (answer == userAn) // Point tracker + { + points++; + Console.WriteLine("Correct!"); + } + else + { + Console.WriteLine("Incorrect!"); + } + + } while (questions < 7); // Loop questions until 7 + + Console.WriteLine("You finished with a score of " + points + "!"); + Console.WriteLine("Press any key to play again"); + + AddToHistory(points, "Multiplication"); +} + +void DivisionGame() +{ + int questions = 0; + int points = 0; + + do + { + int num1 = rand.Next(1, 99); + int num2 = rand.Next(1, 99); + + while (num1 % num2 != 0) // Chooses other numbers incase result has a decimal + { + num1 = rand.Next(1, 99); + num2 = rand.Next(1, 99); + } + answer = (num1 / num2); + + Console.WriteLine($"Solve {num1} / {num2}"); + int userAn = Convert.ToInt32(Console.ReadLine()); + questions++; + + if (answer == userAn) // Point tracker + { + points++; + Console.WriteLine("Correct!"); + } + else + { + Console.WriteLine("Incorrect!"); + } + + } while (questions < 7); // Loop questions until 7 + + Console.WriteLine("You finished with a score of " + points + "!"); + Console.WriteLine("Press any key to play again"); + + AddToHistory(points, "Division"); +} + +// Method to keep track of game history +void AddToHistory(int gameScore, string gameType) +{ + games.Add($"{DateTime.Now} - {gameType}: {gameScore} points"); +}