diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..4ed7e6c9 --- /dev/null +++ b/.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/encodings.xml b/.idea/encodings.xml new file mode 100644 index 00000000..df87cf95 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/indexLayout.xml b/.idea/indexLayout.xml new file mode 100644 index 00000000..7b08163c --- /dev/null +++ b/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CSharpMathGame/.idea/.idea.CSharpMathGame/.idea/.gitignore b/CSharpMathGame/.idea/.idea.CSharpMathGame/.idea/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/CSharpMathGame/.idea/.idea.CSharpMathGame/.idea/encodings.xml b/CSharpMathGame/.idea/.idea.CSharpMathGame/.idea/encodings.xml new file mode 100644 index 00000000..df87cf95 --- /dev/null +++ b/CSharpMathGame/.idea/.idea.CSharpMathGame/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/CSharpMathGame/.idea/.idea.CSharpMathGame/.idea/indexLayout.xml b/CSharpMathGame/.idea/.idea.CSharpMathGame/.idea/indexLayout.xml new file mode 100644 index 00000000..7b08163c --- /dev/null +++ b/CSharpMathGame/.idea/.idea.CSharpMathGame/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/CSharpMathGame/.idea/.idea.CSharpMathGame/.idea/projectSettingsUpdater.xml b/CSharpMathGame/.idea/.idea.CSharpMathGame/.idea/projectSettingsUpdater.xml new file mode 100644 index 00000000..ef20cb08 --- /dev/null +++ b/CSharpMathGame/.idea/.idea.CSharpMathGame/.idea/projectSettingsUpdater.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/CSharpMathGame/.idea/.idea.CSharpMathGame/.idea/workspace.xml b/CSharpMathGame/.idea/.idea.CSharpMathGame/.idea/workspace.xml new file mode 100644 index 00000000..833c36b6 --- /dev/null +++ b/CSharpMathGame/.idea/.idea.CSharpMathGame/.idea/workspace.xml @@ -0,0 +1,162 @@ + + + + CSharpMathGame.csproj + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + "associatedIndex": 7, + "fromUser": false +} + + + + { + "keyToString": { + "ModuleVcsDetector.initialDetectionPerformed": "true", + "RunOnceActivity.MCP Project settings loaded": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "RunOnceActivity.cidr.known.project.marker": "true", + "RunOnceActivity.readMode.enableVisualFormatting": "true", + "RunOnceActivity.typescript.service.memoryLimit.init": "true", + "cidr.known.project.marker": "true", + "codeWithMe.voiceChat.enabledByDefault": "false", + "com.intellij.ml.llm.matterhorn.ej.ui.settings.DefaultModelSelectionForGA.v1": "true", + "junie.onboarding.icon.badge.shown": "true", + "nodejs_package_manager_path": "npm", + "to.speed.mode.migration.done": "true" + } +} + + + + + + + + 1791129897174 + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CSharpMathGame/CSharpMathGame.csproj b/CSharpMathGame/CSharpMathGame.csproj new file mode 100644 index 00000000..6c1dc922 --- /dev/null +++ b/CSharpMathGame/CSharpMathGame.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/CSharpMathGame/CSharpMathGame.sln b/CSharpMathGame/CSharpMathGame.sln new file mode 100644 index 00000000..efc4458b --- /dev/null +++ b/CSharpMathGame/CSharpMathGame.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpMathGame", "CSharpMathGame.csproj", "{E125FF75-3FA9-470D-B7D1-591B02733878}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E125FF75-3FA9-470D-B7D1-591B02733878}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E125FF75-3FA9-470D-B7D1-591B02733878}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E125FF75-3FA9-470D-B7D1-591B02733878}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E125FF75-3FA9-470D-B7D1-591B02733878}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/CSharpMathGame/Program.cs b/CSharpMathGame/Program.cs new file mode 100644 index 00000000..bc5cd823 --- /dev/null +++ b/CSharpMathGame/Program.cs @@ -0,0 +1,204 @@ +using System.Net.Mail; +using System.Runtime.InteropServices.JavaScript; + +public class CSharpMathgame +{ + private static int _gameScore = 0; + private static List> _history = []; + private static List _currentHistoryArray = []; + private static string _currentHistory = ""; + + + public static void Main(string[] args) + { + Menu(); + } + + private static class Helpers + { + public static string ValidateResult(string input) + { + while (!int.TryParse(input, out _)) + { + Console.WriteLine("Invalid input! Please enter a valid number:"); + input = Console.ReadLine(); + } + + return input; + } + } + + + private enum MathOperation + { + addition, + subtraction, + division, + multiplication + } + + + public static int Reroll(string symbol,string diff, int x, int y) + { + Random random = new Random(); + if (symbol == "/") + { + while (x%y != 0) + { + switch (diff) + { + case "Easy": + + y = random.Next(1, 10); + break; + case "Medium": + y = random.Next(1, 100); + break; + default: + y = random.Next(1, 1000); + break; + } + } + + } + return y; + } + + public static void Menu() + { + Console.WriteLine("Play"); + Console.WriteLine("History"); + Console.WriteLine("Quit"); + var a = Console.ReadLine(); + switch (a) + { + case "Play": + Game(); + break; + + case "History": + History(); + break; + + case "Quit": + Console.WriteLine("Goodbye!"); + break; + + default: + throw new ArgumentException("GoodBye!"); + } + } + + + private static void Game() + { + + _gameScore = 0; + Random random = new Random(); + Console.WriteLine("\nWhat difficulty would you like to play in:\nEasy \nMedium \nHard"); + var d = Console.ReadLine(); + int x; + int y; + for (var i = 0; i < 5; i++) + { + switch (d) + { + case "Easy": + x = random.Next(1, 10); + y = random.Next(1, 10); + break; + case "Medium": + x = random.Next(1, 100); + y = random.Next(1, 100); + break; + case "Hard": + x = random.Next(1, 1000); + y = random.Next(1, 1000); + break; + default: + throw new ArgumentException("Not an Difficulty"); + } + _currentHistory = ""; + int firstNumber = x; + int secondNumber = y; + Console.WriteLine($"\nWhat would you like to do: \nAddition \nSubtraction \nMultiplication \nDivision\n"); + var answer = Console.ReadLine(); + MathOperation l = Enum.Parse(answer.ToLower()); + string operatorSymbol = l switch + { + MathOperation.addition => "+", + MathOperation.subtraction => "-", + MathOperation.multiplication => "*", + MathOperation.division => "/", + _ => throw new ArgumentException("Invalid operation") + }; + secondNumber = Reroll(operatorSymbol, d, firstNumber, secondNumber); + + Console.WriteLine($"What is {firstNumber} {operatorSymbol} {secondNumber}?"); + var result = Console.ReadLine(); + result = Helpers.ValidateResult(result); + + int correctAnswer = l switch + { + MathOperation.addition => firstNumber + secondNumber, + MathOperation.subtraction => firstNumber - secondNumber, + MathOperation.multiplication => firstNumber * secondNumber, + MathOperation.division => firstNumber / secondNumber, + _ => throw new ArgumentException("Invalid operation") + }; + + if (int.Parse(result) == correctAnswer) + { + Console.WriteLine("Your answer was correct!"); + _gameScore++; + _currentHistory = $"Correct, Score: {_gameScore}, Problem: {answer}."; + } + else + { + Console.WriteLine("Your answer wasn't correct!"); + _currentHistory = $"Wrong, Score: {_gameScore}, Problem: {answer}."; + } + + _currentHistoryArray.Add(_currentHistory); + + } + _history.Add(_currentHistoryArray); + Console.WriteLine($"Your final score is {_gameScore}."); + Console.WriteLine("Would you like to the menu or play again?"); + var b = Console.ReadLine(); + if (b.ToLower() == "menu") + { + Menu(); + } + else if (b.ToLower() == "play") + { + Game(); + } + else + { + Console.WriteLine("Goodbye!"); + } + + } + + private static void History() + { + foreach (var item in _history) + { + foreach (var jtem in item) + { + Console.WriteLine(jtem); + } + } + Console.WriteLine("\nType 1 to go back to Menu"); + string a = Console.ReadLine(); + switch (a) + { + case "1": + Menu(); + break; + default: + throw new ArgumentException("Nope"); + } + } +} \ No newline at end of file