diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..1ff0c423 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore index 154e1272..9491a2fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. ## -## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files *.rsuser @@ -29,6 +29,7 @@ x86/ bld/ [Bb]in/ [Oo]bj/ +[Oo]ut/ [Ll]og/ [Ll]ogs/ @@ -57,14 +58,11 @@ dlldata.c # Benchmark Results BenchmarkDotNet.Artifacts/ -# .NET +# .NET Core project.lock.json project.fragment.lock.json artifacts/ -# Tye -.tye/ - # ASP.NET Scaffolding ScaffoldingReadMe.txt @@ -93,7 +91,6 @@ StyleCopReport.xml *.tmp_proj *_wpftmp.csproj *.log -*.tlog *.vspscc *.vssscc .builds @@ -297,17 +294,6 @@ node_modules/ # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) *.vbw -# Visual Studio 6 auto-generated project file (contains which files were open etc.) -*.vbp - -# Visual Studio 6 workspace and project file (working project files containing files to include in project) -*.dsw -*.dsp - -# Visual Studio 6 technical files -*.ncb -*.aps - # Visual Studio LightSwitch build output **/*.HTMLClient/GeneratedArtifacts **/*.DesktopClient/GeneratedArtifacts @@ -364,9 +350,6 @@ ASALocalRun/ # Local History for Visual Studio .localhistory/ -# Visual Studio History (VSHistory) files -.vshistory/ - # BeatPulse healthcheck temp database healthchecksdb @@ -377,101 +360,4 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd - -# VS Code files for those working on multiple tools -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -*.code-workspace - -# Local History for Visual Studio Code -.history/ - -# Windows Installer files from build outputs -*.cab -*.msi -*.msix -*.msm -*.msp - -# JetBrains Rider -*.sln.iml - -## -## Visual studio for Mac -## - - -# globs -Makefile.in -*.userprefs -*.usertasks -config.make -config.status -aclocal.m4 -install-sh -autom4te.cache/ -*.tar.gz -tarballs/ -test-results/ - -# Mac bundle stuff -*.dmg -*.app - -# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore -# Windows thumbnail cache files -Thumbs.db -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk +FodyWeavers.xsd \ No newline at end of file diff --git a/MathGame.slnx b/MathGame.slnx new file mode 100644 index 00000000..c91187ad --- /dev/null +++ b/MathGame.slnx @@ -0,0 +1,3 @@ + + + diff --git a/MathGame/MathGame.csproj b/MathGame/MathGame.csproj new file mode 100644 index 00000000..ed9781c2 --- /dev/null +++ b/MathGame/MathGame.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/MathGame/Program.cs b/MathGame/Program.cs new file mode 100644 index 00000000..3fa85118 --- /dev/null +++ b/MathGame/Program.cs @@ -0,0 +1,212 @@ +Game game = new Game(); +bool keepPlaying = true; + +while (keepPlaying) +{ + Console.WriteLine("====Main Menu===="); + Console.WriteLine("Please choose what you would like to do:"); + Console.WriteLine("1.New Round"); + Console.WriteLine("2.View Past Rounds"); + Console.WriteLine("3.Exit"); + + string choice = Console.ReadLine(); + + switch (choice) + { + case "1": + Console.Clear(); + CreateNewRound(game); + break; + case "2": + Console.Clear(); + ViewPastRounds(game); + Console.WriteLine("Press any key to continue"); + Console.ReadKey(); + break; + case "3": + keepPlaying = false; + break; + default: + Console.Clear(); + Console.WriteLine("Invalid choice, please try again"); + Console.WriteLine("Press any key to continue"); + Console.ReadKey(); + Console.Clear(); + break; + } +} + +void ViewPastRounds(Game game) +{ + for (int i = 0; i < game.pastRounds.Count(); i++) + { + Round pastRound = game.pastRounds[i]; + Console.WriteLine( + $"For round {i + 1} you scored {pastRound.score} out of {pastRound.ListOfQuestions.Count}" + ); + Console.WriteLine( + $"it took you {pastRound.RoundLength.Minutes}m and {pastRound.RoundLength.Seconds}s" + ); + Console.WriteLine( + $"-----------------------------------------------------------------------" + ); + Console.WriteLine($"Here are the questions and your answers:"); + foreach ((Question pastQuestion, int pastAnswer) in pastRound.PlayerAnswers) + { + Console.WriteLine( + $"Qustion: {pastQuestion.QuestionText} Your Answer: {pastAnswer}, Correct Answer: {pastQuestion.Answer}" + ); + } + } +} + +void CreateNewRound(Game game) +{ + int numQuestions; + string operand; + + Console.WriteLine("Enter the number of questions you want to answer, you must enter a number 5 or greater."); + do + { + numQuestions = int.Parse(Console.ReadLine()); + } while (numQuestions < 5); + + Console.WriteLine("Enter the operand for the questions you want to answer"); + Console.WriteLine("Please enter +, -, *, or /"); + + do + { + operand = Console.ReadLine(); + } while (operand is not ("+" or "-" or "*" or "/")); + + game.NewRound(numQuestions, operand); +} + + +class Game +{ + public Round round { get; private set; } + public List pastRounds { get; private set; } = new(); + + public Game() { } + + public void NewRound(int numQuestions, string operand) + { + round = new Round(numQuestions, operand); + foreach (Question question in round.ListOfQuestions) + { + Console.WriteLine(question.QuestionText); + int answer = int.Parse(Console.ReadLine()); + round.AnswerQuestion(question, answer); + } + round.EndRound(); + ArchiveRound(round); + } + + private void ArchiveRound(Round currentRound) + { + pastRounds.Add(currentRound); + } +} + +class Round +{ + public List ListOfQuestions { get; private set; } = new(); + public int score { get; private set; } + private DateTime startTime; + public TimeSpan RoundLength { get; private set; } + + public List<(Question, int)> PlayerAnswers { get; private set; } = new(); + + public Round(int numQuestions, string operand) + { + score = 0; + startTime = DateTime.Now; + QuestionGenerator(numQuestions, operand); + } + + private void QuestionGenerator(int numQuestions, string operand) + { + for (int i = 0; i < numQuestions; i++) + { + ListOfQuestions.Add(new Question(operand)); + } + } + + public void AnswerQuestion(Question question, int answer) + { + PlayerAnswers.Add((question, answer)); + if (question.CheckAnswer(answer)) + { + score++; + Console.WriteLine("You got it right!"); + } + else + { + Console.WriteLine("Sorry that is incorrect"); + } + } + + public void EndRound() + { + RoundLength = (DateTime.Now - startTime); + Console.WriteLine( + $"End of round, your score was {score}, and it took {RoundLength.Minutes}m {RoundLength.Seconds}s" + ); + } +} + +class Question +{ + private int firstNum; + private int secondNum; + private string operand; + + // Properties to expose the text and the correct answer + public string QuestionText { get; private set; } + public int Answer { get; private set; } + + public Question(string Operand) + { + operand = Operand; + firstNum = Random.Shared.Next(0, 101); + secondNum = Random.Shared.Next(0, 101); + + CalculateAnswer(); + } + + private void CalculateAnswer() + { + if (operand != "/") + { + QuestionText = $"{firstNum} {operand} {secondNum} = ?"; + } + Answer = operand switch + { + "+" => firstNum + secondNum, + "-" => firstNum - secondNum, + "*" => firstNum * secondNum, + "/" => divisionAnswer(firstNum, secondNum), + _ => 0, + }; + } + + private int divisionAnswer(int dividend, int divisor) + { + do + { + dividend = Random.Shared.Next(0, 101); + divisor = Random.Shared.Next(1, 101); + } while (dividend % divisor != 0); + QuestionText = $"{dividend} / {divisor} = ?"; + return dividend / divisor; + } + + public bool CheckAnswer(int answer) + { + if (answer == Answer) + return true; + else + return false; + } +}