From 4fa44affcb964f24da786ba3889c787081fb87a5 Mon Sep 17 00:00:00 2001 From: ZacharyPatten Date: Thu, 22 Jun 2023 17:42:34 -0500 Subject: [PATCH] flash cards --- .github/workflows/Flash Cards Build.yml | 20 ++++ .vscode/launch.json | 10 ++ .vscode/settings.json | 3 +- .vscode/tasks.json | 13 +++ Projects/Flash Cards/Flash Cards.csproj | 8 ++ Projects/Flash Cards/Program.cs | 86 ++++++++++++++++ Projects/Flash Cards/README.md | 58 +++++++++++ Projects/Website/BlazorConsole.cs | 2 + .../Website/Games/Flash Cards/Flash Cards.cs | 97 +++++++++++++++++++ Projects/Website/Pages/Flash Cards.razor | 56 +++++++++++ Projects/Website/Shared/NavMenu.razor | 5 + README.md | 1 + dotnet-console-games.sln | 8 +- dotnet-console-games.slnf | 1 + 14 files changed, 366 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/Flash Cards Build.yml create mode 100644 Projects/Flash Cards/Flash Cards.csproj create mode 100644 Projects/Flash Cards/Program.cs create mode 100644 Projects/Flash Cards/README.md create mode 100644 Projects/Website/Games/Flash Cards/Flash Cards.cs create mode 100644 Projects/Website/Pages/Flash Cards.razor diff --git a/.github/workflows/Flash Cards Build.yml b/.github/workflows/Flash Cards Build.yml new file mode 100644 index 00000000..d0a6fbc6 --- /dev/null +++ b/.github/workflows/Flash Cards Build.yml @@ -0,0 +1,20 @@ +name: Flash Cards Build +on: + push: + paths: + - 'Projects/Flash Cards/**' + - '!**.md' + pull_request: + paths: + - 'Projects/Flash Cards/**' + - '!**.md' + workflow_dispatch: +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-dotnet@v3 + with: + dotnet-version: 7.0.x + - run: dotnet build "Projects\Flash Cards\Flash Cards.csproj" --configuration Release diff --git a/.vscode/launch.json b/.vscode/launch.json index 8f5ba213..7b41c281 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -32,6 +32,16 @@ "console": "externalTerminal", "stopAtEntry": false, }, + { + "name": "Flash Cards", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "Build Flash Cards", + "program": "${workspaceFolder}/Projects/Flash Cards/bin/Debug/Flash Cards.dll", + "cwd": "${workspaceFolder}/Projects/Flash Cards/bin/Debug", + "console": "externalTerminal", + "stopAtEntry": false, + }, { "name": "Quick Draw", "type": "coreclr", diff --git a/.vscode/settings.json b/.vscode/settings.json index 82e09b5a..b71b76fe 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,8 +6,9 @@ "**/obj": true, }, "csharp.semanticHighlighting.enabled": true, + "dotnet.defaultSolution": "dotnet-console-games.sln", - //// color/theme settings + //// optional color/theme settings //"workbench.colorTheme": "Default Dark+", //"editor.semanticTokenColorCustomizations": //{ diff --git a/.vscode/tasks.json b/.vscode/tasks.json index aa490561..e03affaf 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -600,6 +600,19 @@ ], "problemMatcher": "$msCompile", }, + { + "label": "Build Flash Cards", + "command": "dotnet", + "type": "process", + "args": + [ + "build", + "${workspaceFolder}/Projects/Flash Cards/Flash Cards.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary", + ], + "problemMatcher": "$msCompile", + }, { "label": "Build Solution", "command": "dotnet", diff --git a/Projects/Flash Cards/Flash Cards.csproj b/Projects/Flash Cards/Flash Cards.csproj new file mode 100644 index 00000000..6d3f6cb5 --- /dev/null +++ b/Projects/Flash Cards/Flash Cards.csproj @@ -0,0 +1,8 @@ + + + Exe + net7.0 + disable + enable + + diff --git a/Projects/Flash Cards/Program.cs b/Projects/Flash Cards/Program.cs new file mode 100644 index 00000000..88f14942 --- /dev/null +++ b/Projects/Flash Cards/Program.cs @@ -0,0 +1,86 @@ +using System; + +(char Letter, string CodeWord)[] array = new[] +{ + ( 'A', "Alpha" ), ( 'B', "Bravo" ), ( 'C', "Charlie" ), ( 'D', "Delta" ), + ( 'E', "Echo" ), ( 'F', "Foxtrot" ), ( 'G', "Golf" ), ( 'H', "Hotel" ), + ( 'I', "India" ), ( 'J', "Juliett" ), ( 'K', "Kilo" ), ( 'L', "Lima" ), + ( 'M', "Mike" ), ( 'N', "November" ), ( 'O', "Oscar" ), ( 'P', "Papa" ), + ( 'Q', "Quebec" ), ( 'R', "Romeo" ), ( 'S', "Sierra" ), ( 'T', "Tango" ), + ( 'U', "Uniform" ), ( 'V', "Victor" ), ( 'W', "Whiskey" ), ( 'X', "X-ray" ), + ( 'Y', "Yankee" ), ( 'Z', "Zulu" ), +}; + +while (true) +{ + Console.Clear(); + Console.WriteLine(); + Console.WriteLine(" Flash Cards"); + Console.WriteLine(); + Console.WriteLine(" In this game you will be doing flash card exercises"); + Console.WriteLine(" to help you memorize the NATO phonetic alphabet. The"); + Console.WriteLine(" NATO phonetic alphabet is commonly used during radio"); + Console.WriteLine(" communication in aviation. Each flash card will have"); + Console.WriteLine(" a letter from the english alphabet and you need to"); + Console.WriteLine(" provide the corresponding code word for that letter."); + Console.WriteLine(); + Console.WriteLine(" | NATO phonetic alphabet code words"); + Console.WriteLine(" |"); + Console.WriteLine(" | A -> Alpha B -> Bravo C -> Charlie D -> Delta"); + Console.WriteLine(" | E -> Echo F -> Foxtrot G -> Golf H -> Hotel"); + Console.WriteLine(" | I -> India J -> Juliett K -> Kilo L -> Lima"); + Console.WriteLine(" | M -> Mike N -> November O -> Oscar P -> Papa"); + Console.WriteLine(" | Q -> Quebec R -> Romeo S -> Sierra T -> Tango"); + Console.WriteLine(" | U -> Uniform V -> Victor W -> Whiskey X -> X-ray"); + Console.WriteLine(" | Y -> Yankee Z -> Zulu"); + Console.WriteLine(); + Console.Write(" Press [enter] to continue or [escape] to quit..."); + while (true) + { + ConsoleKey key = Console.ReadKey(true).Key; + if (key is ConsoleKey.Enter) + { + break; + } + if (key is ConsoleKey.Escape) + { + Console.Clear(); + Console.WriteLine("Flash Cards was closed."); + return; + } + } + bool returnToMainMenu = false; + while (!returnToMainMenu) + { + int index = Random.Shared.Next(array.Length); + Console.Clear(); + Console.WriteLine(); + Console.WriteLine(" What is the NATO phonetic alphabet code word for..."); + Console.WriteLine(); + Console.Write($" {array[index].Letter}? "); + string input = Console.ReadLine()!; + Console.WriteLine(); + if (input.Trim().ToUpper() == array[index].CodeWord.ToUpper()) + { + Console.WriteLine(" Correct! :)"); + } + else + { + Console.WriteLine($" Incorrect. :( {array[index].Letter} -> {array[index].CodeWord}"); + } + Console.Write(" Press [enter] to continue or [escape] to return to main menu..."); + while (true) + { + ConsoleKey key = Console.ReadKey(true).Key; + if (key is ConsoleKey.Enter) + { + break; + } + if (key is ConsoleKey.Escape) + { + returnToMainMenu = true; + break; + } + } + } +} diff --git a/Projects/Flash Cards/README.md b/Projects/Flash Cards/README.md new file mode 100644 index 00000000..f77338e2 --- /dev/null +++ b/Projects/Flash Cards/README.md @@ -0,0 +1,58 @@ +

+ Flash Cards +

+ +

+ GitHub repo + Language C# + Target Framework + Build + Discord + License +

+ +

+ You can play this game in your browser: +
+ + Play Now + +
+ Hosted On GitHub Pages +

+ +In this game you will be doing flash card exercises to help you memorize the NATO phonetic alphabet. +The NATO phonetic alphabet is commonly used during radio communication in aviation. Each flash card +will have a letter from the english alphabet and you need to provide the corresponding code word for +that letter. + +``` + | NATO phonetic alphabet code words + | + | A -> Alpha B -> Bravo C -> Charlie D -> Delta + | E -> Echo F -> Foxtrot G -> Golf H -> Hotel + | I -> India J -> Juliett K -> Kilo L -> Lima + | M -> Mike N -> November O -> Oscar P -> Papa + | Q -> Quebec R -> Romeo S -> Sierra T -> Tango + | U -> Uniform V -> Victor W -> Whiskey X -> X-ray + | Y -> Yankee Z -> Zulu +``` + +``` + What is the NATO phonetic alphabet code word for... + + C? Casper + Incorrect. :( C -> Charlie +``` + +## Input + +- `enter`: confirm + +## Downloads + +[win-x64](https://github.com/dotnet/dotnet-console-games/raw/binaries/win-x64/Flash%20Cards.exe) + +[linux-x64](https://github.com/dotnet/dotnet-console-games/raw/binaries/linux-x64/Flash%20Cards) + +[osx-x64](https://github.com/dotnet/dotnet-console-games/raw/binaries/osx-x64/Flash%20Cards) diff --git a/Projects/Website/BlazorConsole.cs b/Projects/Website/BlazorConsole.cs index 766fae22..5f33445c 100644 --- a/Projects/Website/BlazorConsole.cs +++ b/Projects/Website/BlazorConsole.cs @@ -115,6 +115,7 @@ public void EnqueueInput(ConsoleKey key, bool shift = false, bool alt = false, b ConsoleKey.Enter => '\n', ConsoleKey.Backspace => '\b', ConsoleKey.OemPeriod => '.', + ConsoleKey.OemMinus => '-', _ => '\0', }; InputBuffer.Enqueue(new(shift ? char.ToUpper(c) : c, key, shift, alt, control)); @@ -136,6 +137,7 @@ public void OnKeyDown(KeyboardEventArgs e) case "ArrowUp": EnqueueInput(ConsoleKey.UpArrow); break; case "ArrowDown": EnqueueInput(ConsoleKey.DownArrow); break; case ".": EnqueueInput(ConsoleKey.OemPeriod); break; + case "-": EnqueueInput(ConsoleKey.OemMinus); break; default: if (e.Key.Length is 1) { diff --git a/Projects/Website/Games/Flash Cards/Flash Cards.cs b/Projects/Website/Games/Flash Cards/Flash Cards.cs new file mode 100644 index 00000000..420b17da --- /dev/null +++ b/Projects/Website/Games/Flash Cards/Flash Cards.cs @@ -0,0 +1,97 @@ +using System; +using System.Threading.Tasks; + +namespace Website.Games.Flash_Cards; + +public class Flash_Cards +{ + public readonly BlazorConsole Console = new(); + + public async Task Run() + { + (char Letter, string CodeWord)[] array = new[] + { + ( 'A', "Alpha" ), ( 'B', "Bravo" ), ( 'C', "Charlie" ), ( 'D', "Delta" ), + ( 'E', "Echo" ), ( 'F', "Foxtrot" ), ( 'G', "Golf" ), ( 'H', "Hotel" ), + ( 'I', "India" ), ( 'J', "Juliett" ), ( 'K', "Kilo" ), ( 'L', "Lima" ), + ( 'M', "Mike" ), ( 'N', "November" ), ( 'O', "Oscar" ), ( 'P', "Papa" ), + ( 'Q', "Quebec" ), ( 'R', "Romeo" ), ( 'S', "Sierra" ), ( 'T', "Tango" ), + ( 'U', "Uniform" ), ( 'V', "Victor" ), ( 'W', "Whiskey" ), ( 'X', "X-ray" ), + ( 'Y', "Yankee" ), ( 'Z', "Zulu" ), + }; + + while (true) + { + await Console.Clear(); + await Console.WriteLine(); + await Console.WriteLine(" Flash Cards"); + await Console.WriteLine(); + await Console.WriteLine(" In this game you will be doing flash card exercises"); + await Console.WriteLine(" to help you memorize the NATO phonetic alphabet. The"); + await Console.WriteLine(" NATO phonetic alphabet is commonly used during radio"); + await Console.WriteLine(" communication in aviation. Each flash card will have"); + await Console.WriteLine(" a letter from the english alphabet and you need to"); + await Console.WriteLine(" provide the corresponding code word for that letter."); + await Console.WriteLine(); + await Console.WriteLine(" | NATO phonetic alphabet code words"); + await Console.WriteLine(" |"); + await Console.WriteLine(" | A -> Alpha B -> Bravo C -> Charlie D -> Delta"); + await Console.WriteLine(" | E -> Echo F -> Foxtrot G -> Golf H -> Hotel"); + await Console.WriteLine(" | I -> India J -> Juliett K -> Kilo L -> Lima"); + await Console.WriteLine(" | M -> Mike N -> November O -> Oscar P -> Papa"); + await Console.WriteLine(" | Q -> Quebec R -> Romeo S -> Sierra T -> Tango"); + await Console.WriteLine(" | U -> Uniform V -> Victor W -> Whiskey X -> X-ray"); + await Console.WriteLine(" | Y -> Yankee Z -> Zulu"); + await Console.WriteLine(); + await Console.Write(" Press [enter] to continue or [escape] to quit..."); + while (true) + { + ConsoleKey key = (await Console.ReadKey(true)).Key; + if (key is ConsoleKey.Enter) + { + break; + } + if (key is ConsoleKey.Escape) + { + await Console.Clear(); + await Console.WriteLine("Flash Cards was closed."); + return; + } + } + bool returnToMainMenu = false; + while (!returnToMainMenu) + { + int index = Random.Shared.Next(array.Length); + await Console.Clear(); + await Console.WriteLine(); + await Console.WriteLine(" What is the NATO phonetic alphabet code word for..."); + await Console.WriteLine(); + await Console.Write($" {array[index].Letter}? "); + string input = await Console.ReadLine()!; + await Console.WriteLine(); + if (input.Trim().ToUpper() == array[index].CodeWord.ToUpper()) + { + await Console.WriteLine(" Correct! :)"); + } + else + { + await Console.WriteLine($" Incorrect. :( {array[index].Letter} -> {array[index].CodeWord}"); + } + await Console.Write(" Press [enter] to continue or [escape] to return to main menu..."); + while (true) + { + ConsoleKey key = (await Console.ReadKey(true)).Key; + if (key is ConsoleKey.Enter) + { + break; + } + if (key is ConsoleKey.Escape) + { + returnToMainMenu = true; + break; + } + } + } + } + } +} diff --git a/Projects/Website/Pages/Flash Cards.razor b/Projects/Website/Pages/Flash Cards.razor new file mode 100644 index 00000000..7acb7469 --- /dev/null +++ b/Projects/Website/Pages/Flash Cards.razor @@ -0,0 +1,56 @@ +@using System + +@page "/Flash Cards" + +Flash Cards + +

Flash Cards

+ + + Go To Readme + + +
+
+
+			@Console.State
+		
+
+
+ @for (char i = 'a'; i <= 'z'; i++) + { + char c = i; + + + + } + + + +
+
+ + + + + +@code +{ + Games.Flash_Cards.Flash_Cards Game; + BlazorConsole Console; + + public Flash_Cards() + { + Game = new(); + Console = Game.Console; + Console.WindowWidth = 70; + Console.WindowHeight = 24; + Console.TriggerRefresh = StateHasChanged; + } + + protected override void OnInitialized() => InvokeAsync(Game.Run); +} diff --git a/Projects/Website/Shared/NavMenu.razor b/Projects/Website/Shared/NavMenu.razor index d27e71cc..abcf149c 100644 --- a/Projects/Website/Shared/NavMenu.razor +++ b/Projects/Website/Shared/NavMenu.razor @@ -23,6 +23,11 @@ Dice Game +