diff --git a/MathGame.tetris_y/MathGame.tetris_y.slnx b/MathGame.tetris_y/MathGame.tetris_y.slnx new file mode 100644 index 00000000..39cdfa66 --- /dev/null +++ b/MathGame.tetris_y/MathGame.tetris_y.slnx @@ -0,0 +1,3 @@ + + + diff --git a/MathGame.tetris_y/MathGame.tetris_y/MathGame.tetris_y.csproj b/MathGame.tetris_y/MathGame.tetris_y/MathGame.tetris_y.csproj new file mode 100644 index 00000000..ed9781c2 --- /dev/null +++ b/MathGame.tetris_y/MathGame.tetris_y/MathGame.tetris_y.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/MathGame.tetris_y/MathGame.tetris_y/Menu.cs b/MathGame.tetris_y/MathGame.tetris_y/Menu.cs new file mode 100644 index 00000000..98138fb8 --- /dev/null +++ b/MathGame.tetris_y/MathGame.tetris_y/Menu.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathGame.tetris_y +{ + internal class Menu + { + } +} diff --git a/MathGame.tetris_y/MathGame.tetris_y/Program.cs b/MathGame.tetris_y/MathGame.tetris_y/Program.cs new file mode 100644 index 00000000..7260796c --- /dev/null +++ b/MathGame.tetris_y/MathGame.tetris_y/Program.cs @@ -0,0 +1,130 @@ +using System; +using System.Runtime.Intrinsics.Arm; + +class Program +{ + static void Main(string[] args) + { + List previousGames = new List(); + + while (true) + { + Console.WriteLine("===== Welcome to the Math Game! ====="); + Console.WriteLine("1. Addition"); + Console.WriteLine("2. Subtraction"); + Console.WriteLine("3. Multiplication"); + Console.WriteLine("4. Division"); + Console.WriteLine("5. Display game history"); + Console.WriteLine("0. Exit"); + + Console.Write("Enter your choice (1-5): "); + int choice = Convert.ToInt32(Console.ReadLine()); + + switch (choice) + { + case 1: + Console.Clear(); + previousGames.AddRange(PerformCalculation("+")); + break; + case 2: + previousGames.AddRange(PerformCalculation("-")); + break; + case 3: + previousGames.AddRange(PerformCalculation("*")); + break; + case 4: + previousGames.AddRange(PerformCalculation("/")); + break; + case 5: + DisplayHistory(previousGames); + break; + case 0: + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("Thank you for playing! Goodbye!\n"); + Console.ResetColor(); + return; + default: + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Invalid choice. Please try again.\n"); + Console.ResetColor(); + break; + } + } + } + + static void DisplayHistory(List history) + { + Console.Clear(); + + foreach(string game in history) + { + Console.WriteLine(game); + } + + Console.Write("Press any key to continue..."); + Console.ReadLine(); + } + + static List PerformCalculation(string operation) + { + Random random = new Random(); + List history = new List(); + + for (int i = 0; i < 5; i++) + { + int num1 = 0; + int num2 = 0; + int correctAnswer = 0; + + switch (operation) + { + case "+": + num1 = random.Next(1, 101); + num2 = random.Next(1, 101); + correctAnswer = num1 + num2; + Console.Write($"What is {num1} + {num2}?: "); + break; + case "-": + num1 = random.Next(1, 101); + num2 = random.Next(1, 101); + correctAnswer = num1 - num2; + Console.Write($"What is {num1} - {num2}?: "); + break; + case "*": + num1 = random.Next(1, 101); + num2 = random.Next(1, 101); + correctAnswer = num1 * num2; + Console.Write($"What is {num1} * {num2}?: "); + break; + case "/": + do + { + num1 = random.Next(1, 101); + num2 = random.Next(1, 101); + } while (num1 % num2 != 0); + correctAnswer = num1 / num2; + Console.Write($"What is {num1} / {num2}?: "); + break; + } + + + int userAnswer = Convert.ToInt32(Console.ReadLine()); + if (userAnswer == correctAnswer) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("Correct!\n"); + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"Incorrect. The correct answer is {correctAnswer}.\n"); + } + + history.Add($"Operation: {num1} {operation} {num2} Correct Answer: {correctAnswer} Your Answer: {userAnswer}"); + + Console.ResetColor(); + } + + return history; + } +} \ No newline at end of file