diff --git a/.idea/.idea.CodeReviews.Console.MathGame.dir/.idea/.gitignore b/.idea/.idea.CodeReviews.Console.MathGame.dir/.idea/.gitignore new file mode 100644 index 00000000..4ed7e6c9 --- /dev/null +++ b/.idea/.idea.CodeReviews.Console.MathGame.dir/.idea/.gitignore @@ -0,0 +1,15 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Rider ignored files +/modules.xml +/contentModel.xml +/projectSettingsUpdater.xml +/.idea.CodeReviews.Console.MathGame.iml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.CodeReviews.Console.MathGame.dir/.idea/encodings.xml b/.idea/.idea.CodeReviews.Console.MathGame.dir/.idea/encodings.xml new file mode 100644 index 00000000..df87cf95 --- /dev/null +++ b/.idea/.idea.CodeReviews.Console.MathGame.dir/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.CodeReviews.Console.MathGame.dir/.idea/indexLayout.xml b/.idea/.idea.CodeReviews.Console.MathGame.dir/.idea/indexLayout.xml new file mode 100644 index 00000000..7b08163c --- /dev/null +++ b/.idea/.idea.CodeReviews.Console.MathGame.dir/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.CodeReviews.Console.MathGame.dir/.idea/vcs.xml b/.idea/.idea.CodeReviews.Console.MathGame.dir/.idea/vcs.xml new file mode 100644 index 00000000..e3ff9d17 --- /dev/null +++ b/.idea/.idea.CodeReviews.Console.MathGame.dir/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/MathGame.anemicmoth/MathGame2.csproj b/MathGame.anemicmoth/MathGame2.csproj new file mode 100644 index 00000000..2f4fc776 --- /dev/null +++ b/MathGame.anemicmoth/MathGame2.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/MathGame.anemicmoth/Program.cs b/MathGame.anemicmoth/Program.cs new file mode 100644 index 00000000..3e6a8bfe --- /dev/null +++ b/MathGame.anemicmoth/Program.cs @@ -0,0 +1,110 @@ +// Difficulty based questions + +string[,] beginnerQuestions = {{"1 + 5", "6"}, {"2 * 2", "4"}, {"21 + 3", "24"}}; +string[,] moderateQuestions = {{"22/3", "7"}, {"17 * 2", "34"}, {"125 - 56", "69"}}; +string[,] advancedQuestions = {{"147/6", "24"}, {"13 ^ 2", "169"}, {"23 * 25", "575"}}; + +string entry = ""; + + +while (entry != "exit") +{ + Console.WriteLine("Please enter a difficulty: b (beginner), m (moderate), a (advanced)"); + entry = Console.ReadLine(); + switch (entry) + { + case "b": + askQuestion(Difficulty.Beginner); + break; + case "m": + askQuestion(Difficulty.Moderate); + break; + case "a": + askQuestion(Difficulty.Advanced); + break; + default: + Console.WriteLine("Invalid input."); + break; + } + Console.WriteLine("Do you want to play again? Press Enter to continue or type \"exit\" to quit."); + entry = Console.ReadLine(); +} + +void askQuestion(Difficulty difficulty) +{ + System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch(); + Tuple question = createQuestion(difficulty); + + timer.Start(); + Console.WriteLine(question.Item1); + entry = Console.ReadLine(); + timer.Stop(); + + TimeSpan ts = timer.Elapsed; + string elapsedTime = String.Format("{0:00}:{1:00}", ts.Minutes, ts.Seconds); + if (entry != null && entry.Equals(question.Item2)) + { + Console.WriteLine($"Correct! Your time to answer is: {elapsedTime} min"); + } + else + { + Console.WriteLine($"That was the wrong answer. The correct answer is: {question.Item2}"); + } +} + +Tuple createQuestion(Difficulty difficulty) +{ + Random rand = new Random(); + int num1 = rand.Next(1, 51); + int num2 = rand.Next(1, 51); + int operand = 0; + int result; + + switch (difficulty) + { + case Difficulty.Beginner: + operand = rand.Next(0, 2); + break; + case Difficulty.Moderate: + operand = rand.Next(0, 4); + break; + case Difficulty.Advanced: + num1 = rand.Next(51, 201); + num2 = rand.Next(51, 201); + operand = rand.Next(2, 5); + if (operand == 4) + { + num1 = rand.Next(1, 51); + num2 = rand.Next(1, 5); + } + break; + } + + switch (operand) + { + case 0: + result = num1 + num2; + return new Tuple(num1 + " + " + num2, Convert.ToString(result)); + case 1: + result = num1 - num2; + return new Tuple(num1 + " - " + num2, Convert.ToString(result)); + case 2: + result = num1 * num2; + return new Tuple(num1 + " * " + num2, Convert.ToString(result)); + case 3: + result = num1 / num2; + return new Tuple(num1 + " / " + num2, Convert.ToString(result)); + case 4: + result = Convert.ToInt32(Math.Pow(num1, num2)); + return new Tuple(num1 + " ^ " + num2, Convert.ToString(result)); + } + + return null; +} + +enum Difficulty +{ + Beginner, + Moderate, + Advanced +} \ No newline at end of file