diff --git a/MathGames/MathGames.csproj b/MathGames/MathGames.csproj new file mode 100644 index 00000000..206b89a9 --- /dev/null +++ b/MathGames/MathGames.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/MathGames/Program.cs b/MathGames/Program.cs new file mode 100644 index 00000000..4e6f6479 --- /dev/null +++ b/MathGames/Program.cs @@ -0,0 +1,172 @@ +using System; +using System.Runtime.ConstrainedExecution; +using System.Runtime.InteropServices; + +namespace HelloWorld; + +class Program +{ + static void Main(string[] args) + { + int points = 0; + bool playAgain = true; + Random random = new Random(); + + List questions = new List(); + // Addition questions + questions.Add(new Questions("9 + 10 = ?", '+', 19)); + questions.Add(new Questions("7 + 13 = ?", '+', 20)); + questions.Add(new Questions("25 + 35 = ?", '+', 60)); + questions.Add(new Questions("18 + 22 = ?", '+', 40)); + + // Subtraction questions + questions.Add(new Questions("15 - 4 = ?", '-', 11)); + questions.Add(new Questions("50 - 23 = ?", '-', 27)); + questions.Add(new Questions("100 - 45 = ?", '-', 55)); + questions.Add(new Questions("73 - 28 = ?", '-', 45)); + + // Multiplication questions + questions.Add(new Questions("12 * 12 = ?", '*', 144)); + questions.Add(new Questions("6 * 9 = ?", '*', 54)); + questions.Add(new Questions("7 * 8 = ?", '*', 56)); + questions.Add(new Questions("11 * 5 = ?", '*', 55)); + questions.Add(new Questions("8 * 8 = ?", '*', 64)); + + // Division questions (integers only, dividends 0-100) + questions.Add(new Questions("56 / 7 = ?", '/', 8)); + questions.Add(new Questions("81 / 9 = ?", '/', 9)); + questions.Add(new Questions("100 / 10 = ?", '/', 10)); + questions.Add(new Questions("48 / 6 = ?", '/', 8)); + questions.Add(new Questions("72 / 8 = ?", '/', 9)); + questions.Add(new Questions("63 / 7 = ?", '/', 9)); + + List PreviousGames = new List(); + + while (playAgain) + { + System.Console.WriteLine("Welcome to the Math Game!"); + while (playAgain) + { + Console.WriteLine("=== Math Game Menu ==="); + Console.WriteLine("1. Addition"); + Console.WriteLine("2. Subtraction"); + Console.WriteLine("3. Multiplication"); + Console.WriteLine("4. Division"); + Console.WriteLine("5. View Previous Games"); + Console.WriteLine("6. Exit"); + Console.Write("Enter your choice (1-6): "); + string choiceInput = Console.ReadLine(); + int choice; + + // Try parsing safely + if (!int.TryParse(choiceInput, out choice) || choice < 1 || choice > 5) + { + Console.WriteLine("\nExiting the game. Thanks for playing!"); + playAgain = false; + break; + } + else if (choice == 5) + { + Console.WriteLine("\nHere are your previous games:"); + foreach (var answered in PreviousGames) + { + string correctness = answered.IsCorrect ? "Correct" : "Wrong"; + Console.WriteLine($"{answered.QuestionText} Your answer: {answered.UserAnswer}. Correct answer: {answered.Answer}. Result: {correctness}"); + } + continue; + } + + char operationChar = ' '; + switch (choice) + { + case 1: operationChar = '+'; break; + case 2: operationChar = '-'; break; + case 3: operationChar = '*'; break; + case 4: operationChar = '/'; break; + } + + List filteredQuestions = questions.Where(q => q.Operation == operationChar).ToList(); + Questions question = filteredQuestions[random.Next(filteredQuestions.Count)]; + + Console.WriteLine(question.QuestionText); + if (!int.TryParse(Console.ReadLine(), out int userAnswer)) + { + Console.WriteLine("Invalid input! Please enter a number.\n"); + continue; + } + + PreviousGames.Add(new AnsweredQuestion(question.QuestionText, question.Operation, question.Answer, userAnswer)); + + if (userAnswer == question.Answer) + { + points++; + Console.WriteLine("Correct!\n"); + } + else + { + Console.WriteLine($"Wrong! The correct answer is {question.Answer}\n"); + } + } + Console.WriteLine($"Your total points is: {points}!"); + Console.WriteLine("Do you want to play again? (y/n)"); + string response = Console.ReadLine(); + if (response.ToLower() != "y") + { + playAgain = false; + } + else + { + playAgain = true; + points = 0; + } + } + + } +} + +class Questions +{ + public string QuestionText { get; } + public char Operation { get; } + public int Answer { get; } + + public Questions(string questionText, char operation, int answer) + { + QuestionText = questionText; + Operation = operation; + Answer = answer; + } +} +class AnsweredQuestion : Questions +{ + public int UserAnswer { get; set; } + public bool IsCorrect { get; set; } + + // Call base constructor for QuestionText, Operation, Answer + public AnsweredQuestion(string questionText, char operation, int answer, int userAnswer) + : base(questionText, operation, answer) + { + UserAnswer = userAnswer; + IsCorrect = userAnswer == answer; + } +} + + +/* +You need to create a game that consists of asking the player what's the result of a math question (i.e. 9 x 9 = ?), collecting the input and adding a point in case of a correct answer. + + +A game needs to have at least 5 questions. + + +The divisions should result on INTEGERS ONLY and dividends should go from 0 to 100. Example: Your app shouldn't present the division 7/2 to the user, since it doesn't result in an integer. + + +Users should be presented with a menu to choose an operation + + +You should record previous games in a List and there should be an option in the menu for the user to visualize a history of previous games. + + +You don't need to record results on a database. Once the program is closed the results will be deleted. +*/ \ No newline at end of file diff --git a/MathGames/bin/Debug/net8.0/MathGames b/MathGames/bin/Debug/net8.0/MathGames new file mode 100644 index 00000000..2b59c8e3 Binary files /dev/null and b/MathGames/bin/Debug/net8.0/MathGames differ diff --git a/MathGames/bin/Debug/net8.0/MathGames.deps.json b/MathGames/bin/Debug/net8.0/MathGames.deps.json new file mode 100644 index 00000000..b437c1b0 --- /dev/null +++ b/MathGames/bin/Debug/net8.0/MathGames.deps.json @@ -0,0 +1,23 @@ +{ + "runtimeTarget": { + "name": ".NETCoreApp,Version=v8.0", + "signature": "" + }, + "compilationOptions": {}, + "targets": { + ".NETCoreApp,Version=v8.0": { + "MathGames/1.0.0": { + "runtime": { + "MathGames.dll": {} + } + } + } + }, + "libraries": { + "MathGames/1.0.0": { + "type": "project", + "serviceable": false, + "sha512": "" + } + } +} \ No newline at end of file diff --git a/MathGames/bin/Debug/net8.0/MathGames.dll b/MathGames/bin/Debug/net8.0/MathGames.dll new file mode 100644 index 00000000..d0f0d5fb Binary files /dev/null and b/MathGames/bin/Debug/net8.0/MathGames.dll differ diff --git a/MathGames/bin/Debug/net8.0/MathGames.pdb b/MathGames/bin/Debug/net8.0/MathGames.pdb new file mode 100644 index 00000000..7f004c7b Binary files /dev/null and b/MathGames/bin/Debug/net8.0/MathGames.pdb differ diff --git a/MathGames/bin/Debug/net8.0/MathGames.runtimeconfig.json b/MathGames/bin/Debug/net8.0/MathGames.runtimeconfig.json new file mode 100644 index 00000000..becfaeac --- /dev/null +++ b/MathGames/bin/Debug/net8.0/MathGames.runtimeconfig.json @@ -0,0 +1,12 @@ +{ + "runtimeOptions": { + "tfm": "net8.0", + "framework": { + "name": "Microsoft.NETCore.App", + "version": "8.0.0" + }, + "configProperties": { + "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false + } + } +} \ No newline at end of file diff --git a/MathGames/obj/Debug/net8.0/MathGames.AssemblyInfo.cs b/MathGames/obj/Debug/net8.0/MathGames.AssemblyInfo.cs new file mode 100644 index 00000000..7792a54b --- /dev/null +++ b/MathGames/obj/Debug/net8.0/MathGames.AssemblyInfo.cs @@ -0,0 +1,22 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +using System; +using System.Reflection; + +[assembly: System.Reflection.AssemblyCompanyAttribute("MathGames")] +[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] +[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+043425ecfa1f7cf5f208ca503ab4d36c9f26a980")] +[assembly: System.Reflection.AssemblyProductAttribute("MathGames")] +[assembly: System.Reflection.AssemblyTitleAttribute("MathGames")] +[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] + +// Generated by the MSBuild WriteCodeFragment class. + diff --git a/MathGames/obj/Debug/net8.0/MathGames.AssemblyInfoInputs.cache b/MathGames/obj/Debug/net8.0/MathGames.AssemblyInfoInputs.cache new file mode 100644 index 00000000..6f0ba039 --- /dev/null +++ b/MathGames/obj/Debug/net8.0/MathGames.AssemblyInfoInputs.cache @@ -0,0 +1 @@ +bb2934a45acf3a162e9d119df0c693baba55113264d0183ec138818151ca7811 diff --git a/MathGames/obj/Debug/net8.0/MathGames.GeneratedMSBuildEditorConfig.editorconfig b/MathGames/obj/Debug/net8.0/MathGames.GeneratedMSBuildEditorConfig.editorconfig new file mode 100644 index 00000000..d33e4d57 --- /dev/null +++ b/MathGames/obj/Debug/net8.0/MathGames.GeneratedMSBuildEditorConfig.editorconfig @@ -0,0 +1,17 @@ +is_global = true +build_property.TargetFramework = net8.0 +build_property.TargetFrameworkIdentifier = .NETCoreApp +build_property.TargetFrameworkVersion = v8.0 +build_property.TargetPlatformMinVersion = +build_property.UsingMicrosoftNETSdkWeb = +build_property.ProjectTypeGuids = +build_property.InvariantGlobalization = +build_property.PlatformNeutralAssembly = +build_property.EnforceExtendedAnalyzerRules = +build_property._SupportedPlatformList = Linux,macOS,Windows +build_property.RootNamespace = MathGames +build_property.ProjectDir = /Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/ +build_property.EnableComHosting = +build_property.EnableGeneratedComInterfaceComImportInterop = +build_property.EffectiveAnalysisLevelStyle = 8.0 +build_property.EnableCodeStyleSeverity = diff --git a/MathGames/obj/Debug/net8.0/MathGames.GlobalUsings.g.cs b/MathGames/obj/Debug/net8.0/MathGames.GlobalUsings.g.cs new file mode 100644 index 00000000..d12bcbc7 --- /dev/null +++ b/MathGames/obj/Debug/net8.0/MathGames.GlobalUsings.g.cs @@ -0,0 +1,8 @@ +// +global using System; +global using System.Collections.Generic; +global using System.IO; +global using System.Linq; +global using System.Net.Http; +global using System.Threading; +global using System.Threading.Tasks; diff --git a/MathGames/obj/Debug/net8.0/MathGames.assets.cache b/MathGames/obj/Debug/net8.0/MathGames.assets.cache new file mode 100644 index 00000000..ad686bf1 Binary files /dev/null and b/MathGames/obj/Debug/net8.0/MathGames.assets.cache differ diff --git a/MathGames/obj/Debug/net8.0/MathGames.csproj.CoreCompileInputs.cache b/MathGames/obj/Debug/net8.0/MathGames.csproj.CoreCompileInputs.cache new file mode 100644 index 00000000..a2067b58 --- /dev/null +++ b/MathGames/obj/Debug/net8.0/MathGames.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +a9ac62a7453ed13a3f0254f4f97d7dfebed9b0a29bc3d42e680b831495d894d9 diff --git a/MathGames/obj/Debug/net8.0/MathGames.csproj.FileListAbsolute.txt b/MathGames/obj/Debug/net8.0/MathGames.csproj.FileListAbsolute.txt new file mode 100644 index 00000000..5d1b846d --- /dev/null +++ b/MathGames/obj/Debug/net8.0/MathGames.csproj.FileListAbsolute.txt @@ -0,0 +1,15 @@ +/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/obj/Debug/net8.0/MathGames.GeneratedMSBuildEditorConfig.editorconfig +/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/obj/Debug/net8.0/MathGames.AssemblyInfoInputs.cache +/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/obj/Debug/net8.0/MathGames.AssemblyInfo.cs +/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/obj/Debug/net8.0/MathGames.csproj.CoreCompileInputs.cache +/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/obj/Debug/net8.0/MathGames.sourcelink.json +/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/bin/Debug/net8.0/MathGames +/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/bin/Debug/net8.0/MathGames.deps.json +/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/bin/Debug/net8.0/MathGames.runtimeconfig.json +/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/bin/Debug/net8.0/MathGames.dll +/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/bin/Debug/net8.0/MathGames.pdb +/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/obj/Debug/net8.0/MathGames.dll +/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/obj/Debug/net8.0/refint/MathGames.dll +/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/obj/Debug/net8.0/MathGames.pdb +/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/obj/Debug/net8.0/MathGames.genruntimeconfig.cache +/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/obj/Debug/net8.0/ref/MathGames.dll diff --git a/MathGames/obj/Debug/net8.0/MathGames.dll b/MathGames/obj/Debug/net8.0/MathGames.dll new file mode 100644 index 00000000..d0f0d5fb Binary files /dev/null and b/MathGames/obj/Debug/net8.0/MathGames.dll differ diff --git a/MathGames/obj/Debug/net8.0/MathGames.genruntimeconfig.cache b/MathGames/obj/Debug/net8.0/MathGames.genruntimeconfig.cache new file mode 100644 index 00000000..0d0e271b --- /dev/null +++ b/MathGames/obj/Debug/net8.0/MathGames.genruntimeconfig.cache @@ -0,0 +1 @@ +7e5a5cc1a296877529521fdcda4942f79fd896a8bc935621aefa4ac91c1b7012 diff --git a/MathGames/obj/Debug/net8.0/MathGames.pdb b/MathGames/obj/Debug/net8.0/MathGames.pdb new file mode 100644 index 00000000..7f004c7b Binary files /dev/null and b/MathGames/obj/Debug/net8.0/MathGames.pdb differ diff --git a/MathGames/obj/Debug/net8.0/MathGames.sourcelink.json b/MathGames/obj/Debug/net8.0/MathGames.sourcelink.json new file mode 100644 index 00000000..af0eed66 --- /dev/null +++ b/MathGames/obj/Debug/net8.0/MathGames.sourcelink.json @@ -0,0 +1 @@ +{"documents":{"/Users/hyungminoh/asp-learn/aspnet-learning/*":"https://raw.githubusercontent.com/hyungminoh2/aspnet-learning/043425ecfa1f7cf5f208ca503ab4d36c9f26a980/*"}} \ No newline at end of file diff --git a/MathGames/obj/Debug/net8.0/apphost b/MathGames/obj/Debug/net8.0/apphost new file mode 100644 index 00000000..2b59c8e3 Binary files /dev/null and b/MathGames/obj/Debug/net8.0/apphost differ diff --git a/MathGames/obj/Debug/net8.0/ref/MathGames.dll b/MathGames/obj/Debug/net8.0/ref/MathGames.dll new file mode 100644 index 00000000..dc875a33 Binary files /dev/null and b/MathGames/obj/Debug/net8.0/ref/MathGames.dll differ diff --git a/MathGames/obj/Debug/net8.0/refint/MathGames.dll b/MathGames/obj/Debug/net8.0/refint/MathGames.dll new file mode 100644 index 00000000..dc875a33 Binary files /dev/null and b/MathGames/obj/Debug/net8.0/refint/MathGames.dll differ diff --git a/MathGames/obj/MathGames.csproj.nuget.dgspec.json b/MathGames/obj/MathGames.csproj.nuget.dgspec.json new file mode 100644 index 00000000..a819d99a --- /dev/null +++ b/MathGames/obj/MathGames.csproj.nuget.dgspec.json @@ -0,0 +1,67 @@ +{ + "format": 1, + "restore": { + "/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/MathGames.csproj": {} + }, + "projects": { + "/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/MathGames.csproj": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/MathGames.csproj", + "projectName": "MathGames", + "projectPath": "/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/MathGames.csproj", + "packagesPath": "/Users/hyungminoh/.nuget/packages/", + "outputPath": "/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/obj/", + "projectStyle": "PackageReference", + "configFilePaths": [ + "/Users/hyungminoh/.nuget/NuGet/NuGet.Config" + ], + "originalTargetFrameworks": [ + "net8.0" + ], + "sources": { + "https://api.nuget.org/v3/index.json": {} + }, + "frameworks": { + "net8.0": { + "targetAlias": "net8.0", + "projectReferences": {} + } + }, + "warningProperties": { + "warnAsError": [ + "NU1605" + ] + }, + "restoreAuditProperties": { + "enableAudit": "true", + "auditLevel": "low", + "auditMode": "direct" + }, + "SdkAnalysisLevel": "10.0.100" + }, + "frameworks": { + "net8.0": { + "targetAlias": "net8.0", + "imports": [ + "net461", + "net462", + "net47", + "net471", + "net472", + "net48", + "net481" + ], + "assetTargetFallback": true, + "warn": true, + "frameworkReferences": { + "Microsoft.NETCore.App": { + "privateAssets": "all" + } + }, + "runtimeIdentifierGraphPath": "/usr/local/share/dotnet/sdk/10.0.102/PortableRuntimeIdentifierGraph.json" + } + } + } + } +} \ No newline at end of file diff --git a/MathGames/obj/MathGames.csproj.nuget.g.props b/MathGames/obj/MathGames.csproj.nuget.g.props new file mode 100644 index 00000000..4349e63e --- /dev/null +++ b/MathGames/obj/MathGames.csproj.nuget.g.props @@ -0,0 +1,15 @@ + + + + True + NuGet + $(MSBuildThisFileDirectory)project.assets.json + /Users/hyungminoh/.nuget/packages/ + /Users/hyungminoh/.nuget/packages/ + PackageReference + 7.0.0 + + + + + \ No newline at end of file diff --git a/MathGames/obj/MathGames.csproj.nuget.g.targets b/MathGames/obj/MathGames.csproj.nuget.g.targets new file mode 100644 index 00000000..3dc06ef3 --- /dev/null +++ b/MathGames/obj/MathGames.csproj.nuget.g.targets @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/MathGames/obj/project.assets.json b/MathGames/obj/project.assets.json new file mode 100644 index 00000000..27019614 --- /dev/null +++ b/MathGames/obj/project.assets.json @@ -0,0 +1,72 @@ +{ + "version": 3, + "targets": { + "net8.0": {} + }, + "libraries": {}, + "projectFileDependencyGroups": { + "net8.0": [] + }, + "packageFolders": { + "/Users/hyungminoh/.nuget/packages/": {} + }, + "project": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/MathGames.csproj", + "projectName": "MathGames", + "projectPath": "/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/MathGames.csproj", + "packagesPath": "/Users/hyungminoh/.nuget/packages/", + "outputPath": "/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/obj/", + "projectStyle": "PackageReference", + "configFilePaths": [ + "/Users/hyungminoh/.nuget/NuGet/NuGet.Config" + ], + "originalTargetFrameworks": [ + "net8.0" + ], + "sources": { + "https://api.nuget.org/v3/index.json": {} + }, + "frameworks": { + "net8.0": { + "targetAlias": "net8.0", + "projectReferences": {} + } + }, + "warningProperties": { + "warnAsError": [ + "NU1605" + ] + }, + "restoreAuditProperties": { + "enableAudit": "true", + "auditLevel": "low", + "auditMode": "direct" + }, + "SdkAnalysisLevel": "10.0.100" + }, + "frameworks": { + "net8.0": { + "targetAlias": "net8.0", + "imports": [ + "net461", + "net462", + "net47", + "net471", + "net472", + "net48", + "net481" + ], + "assetTargetFallback": true, + "warn": true, + "frameworkReferences": { + "Microsoft.NETCore.App": { + "privateAssets": "all" + } + }, + "runtimeIdentifierGraphPath": "/usr/local/share/dotnet/sdk/10.0.102/PortableRuntimeIdentifierGraph.json" + } + } + } +} \ No newline at end of file diff --git a/MathGames/obj/project.nuget.cache b/MathGames/obj/project.nuget.cache new file mode 100644 index 00000000..36ce14cb --- /dev/null +++ b/MathGames/obj/project.nuget.cache @@ -0,0 +1,8 @@ +{ + "version": 2, + "dgSpecHash": "E92NfaqeZCk=", + "success": true, + "projectFilePath": "/Users/hyungminoh/asp-learn/aspnet-learning/BeginnerConsole/MathGames/MathGames.csproj", + "expectedPackageFiles": [], + "logs": [] +} \ No newline at end of file