From 5637adbbe7f6a36ac327aab884ad3123973fad1c Mon Sep 17 00:00:00 2001 From: ZacharyPatten Date: Tue, 24 Oct 2023 22:38:18 -0500 Subject: [PATCH] clicker --- .github/workflows/Clicker Build.yml | 20 ++++ .vscode/launch.json | 10 ++ .vscode/tasks.json | 13 +++ Projects/Clicker/Clicker.csproj | 8 ++ Projects/Clicker/Program.cs | 101 +++++++++++++++++++ Projects/Clicker/README.md | 48 +++++++++ Projects/Website/Games/Clicker/Clicker.cs | 116 ++++++++++++++++++++++ Projects/Website/Pages/Checkers.razor | 4 + Projects/Website/Pages/Clicker.razor | 74 ++++++++++++++ Projects/Website/Shared/NavMenu.razor | 5 + README.md | 1 + dotnet-console-games.sln | 8 +- dotnet-console-games.slnf | 1 + 13 files changed, 408 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/Clicker Build.yml create mode 100644 Projects/Clicker/Clicker.csproj create mode 100644 Projects/Clicker/Program.cs create mode 100644 Projects/Clicker/README.md create mode 100644 Projects/Website/Games/Clicker/Clicker.cs create mode 100644 Projects/Website/Pages/Clicker.razor diff --git a/.github/workflows/Clicker Build.yml b/.github/workflows/Clicker Build.yml new file mode 100644 index 00000000..889b7698 --- /dev/null +++ b/.github/workflows/Clicker Build.yml @@ -0,0 +1,20 @@ +name: Clicker Build +on: + push: + paths: + - 'Projects/Clicker/**' + - '!**.md' + pull_request: + paths: + - 'Projects/Clicker/**' + - '!**.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\Clicker\Clicker.csproj" --configuration Release diff --git a/.vscode/launch.json b/.vscode/launch.json index a6a89bac..476816fe 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -132,6 +132,16 @@ "console": "externalTerminal", "stopAtEntry": false, }, + { + "name": "Clicker", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "Build Clicker", + "program": "${workspaceFolder}/Projects/Clicker/bin/Debug/Clicker.dll", + "cwd": "${workspaceFolder}/Projects/Clicker/bin/Debug", + "console": "externalTerminal", + "stopAtEntry": false, + }, { "name": "Hangman", "type": "coreclr", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 6d9ec4a1..2f312b30 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -626,6 +626,19 @@ ], "problemMatcher": "$msCompile", }, + { + "label": "Build Clicker", + "command": "dotnet", + "type": "process", + "args": + [ + "build", + "${workspaceFolder}/Projects/Clicker/Clicker.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary", + ], + "problemMatcher": "$msCompile", + }, { "label": "Build Solution", "command": "dotnet", diff --git a/Projects/Clicker/Clicker.csproj b/Projects/Clicker/Clicker.csproj new file mode 100644 index 00000000..6d3f6cb5 --- /dev/null +++ b/Projects/Clicker/Clicker.csproj @@ -0,0 +1,8 @@ + + + Exe + net7.0 + disable + enable + + diff --git a/Projects/Clicker/Program.cs b/Projects/Clicker/Program.cs new file mode 100644 index 00000000..83540dd0 --- /dev/null +++ b/Projects/Clicker/Program.cs @@ -0,0 +1,101 @@ +using System; +using System.Globalization; +using System.Numerics; + +char[] keys = +{ + 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', + 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', + 'Z', 'X', 'C', 'V', 'B', 'N', 'M', +}; + +MainMenu: +Console.Clear(); +Console.WriteLine( + $""" + Clicker + + In this game you will continually click + keys on your keyboard to increase your + score, but you cannot press the same key + twice in a row. :P You will start with + the [{keys[0]}] & [{keys[1]}] keys but unlock additional + keys as you click. + + NOTE FROM DEVELOPER: Do not play this game. + Clicker games are nothing but a waste of + your time. I only made this game as an + educational example. + + ESC: close game + ENTER: continue + """); +MainMenuInput: +Console.CursorVisible = false; +switch (Console.ReadKey(true).Key) +{ + case ConsoleKey.Enter: break; + case ConsoleKey.Escape: Console.Clear(); return; + default: goto MainMenuInput; +} + +DateTime start = DateTime.Now; +BigInteger clicks = 0; +ConsoleKey previous = default; +Console.Clear(); +while (true) +{ + string clicksString = clicks.ToString(CultureInfo.InvariantCulture); + int keyCount = clicksString.Length + 1; + + if (keyCount > keys.Length) + { + TimeSpan duration = DateTime.Now - start; + Console.Clear(); + Console.WriteLine( + $""" + Clicker + + You Win! + + Your time: {duration} + + ESC: return to main menu + """); + GameOverInput: + Console.CursorVisible = false; + switch (Console.ReadKey(true).Key) + { + case ConsoleKey.Escape: goto MainMenu; + default: goto GameOverInput; + } + } + + Console.SetCursorPosition(0, 0); + Console.WriteLine( + $""" + Clicker + + Clicks: {clicksString} + + Keys: {string.Join(" ", keys[0..keyCount])} + + ESC: return to main menu + """); + ClickerInput: + Console.CursorVisible = false; + ConsoleKey key = Console.ReadKey(true).Key; + switch (key) + { + case >= ConsoleKey.A and <= ConsoleKey.Z: + int index = Array.IndexOf(keys, (char)key); + if (index < keyCount && key != previous) + { + previous = key; + clicks += index > 1 ? BigInteger.Pow(10, index > 1 ? index - 1 : 0) / (index - 1) : 1; + } + break; + case ConsoleKey.Escape: goto MainMenu; + default: goto ClickerInput; + } +} \ No newline at end of file diff --git a/Projects/Clicker/README.md b/Projects/Clicker/README.md new file mode 100644 index 00000000..6443f181 --- /dev/null +++ b/Projects/Clicker/README.md @@ -0,0 +1,48 @@ +

+ Clicker +

+ +

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

+ +

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

+ +Clicker is a... clicker game. You just click to increase your number of clicks. That is it. + +``` + Clicker + + Clicks: 11651 + + Keys: Q W E R T Y + + ESC: return to main menu +``` + +## Input + +- `A`-`Z`: click +- `enter`: continue +- `escape`: return to main menu and exit game + +## Downloads + +[win-x64](https://github.com/dotnet/dotnet-console-games/raw/binaries/win-x64/Clicker.exe) + +[linux-x64](https://github.com/dotnet/dotnet-console-games/raw/binaries/linux-x64/Clicker) + +[osx-x64](https://github.com/dotnet/dotnet-console-games/raw/binaries/osx-x64/Clicker) diff --git a/Projects/Website/Games/Clicker/Clicker.cs b/Projects/Website/Games/Clicker/Clicker.cs new file mode 100644 index 00000000..d147ec7c --- /dev/null +++ b/Projects/Website/Games/Clicker/Clicker.cs @@ -0,0 +1,116 @@ +using System; +using System.Globalization; +using System.Numerics; +using System.Threading.Tasks; + +namespace Website.Games.Clicker; + +public class Clicker +{ + public readonly BlazorConsole Console = new(); + + public async Task Run() + { + char[] keys = + { + 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', + 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', + 'Z', 'X', 'C', 'V', 'B', 'N', 'M', + }; + + MainMenu: + await Console.Clear(); + await Console.WriteLine( + $""" + Clicker + + In this game you will continually click + keys on your keyboard to increase your + score, but you cannot press the same key + twice in a row. :P You will start with + the [{keys[0]}] & [{keys[1]}] keys but unlock additional + keys as you click. + + NOTE FROM DEVELOPER: Do not play this game. + Clicker games are nothing but a waste of + your time. I only made this game as an + educational example. + + ESC: close game + ENTER: continue + """); + MainMenuInput: + Console.CursorVisible = false; + switch ((await Console.ReadKey(true)).Key) + { + case ConsoleKey.Enter: break; + case ConsoleKey.Escape: + await Console.Clear(); + await Console.WriteLine("Clicker was closed."); + await Console.Refresh(); + return; + default: goto MainMenuInput; + } + + DateTime start = DateTime.Now; + BigInteger clicks = 0; + ConsoleKey previous = default; + await Console.Clear(); + while (true) + { + string clicksString = clicks.ToString(CultureInfo.InvariantCulture); + int keyCount = clicksString.Length + 1; + + if (keyCount > keys.Length) + { + TimeSpan duration = DateTime.Now - start; + await Console.Clear(); + await Console.WriteLine( + $""" + Clicker + + You Win! + + Your time: {duration} + + ESC: return to main menu + """); + GameOverInput: + Console.CursorVisible = false; + switch ((await Console.ReadKey(true)).Key) + { + case ConsoleKey.Escape: goto MainMenu; + default: goto GameOverInput; + } + } + + await Console.SetCursorPosition(0, 0); + await Console.WriteLine( + $""" + Clicker + + Clicks: {clicksString} + + Keys: {string.Join(" ", keys[0..keyCount])} + + ESC: return to main menu + """); + ClickerInput: + Console.CursorVisible = false; + ConsoleKey key = (await Console.ReadKey(true)).Key; + switch (key) + { + case >= ConsoleKey.A and <= ConsoleKey.Z: + int index = Array.IndexOf(keys, (char)key); + if (index < keyCount && key != previous) + { + previous = key; + clicks += index > 1 ? BigInteger.Pow(10, index > 1 ? index - 1 : 0) / (index - 1) : 1; + } + break; + case ConsoleKey.Escape: goto MainMenu; + default: goto ClickerInput; + } + } + } +} diff --git a/Projects/Website/Pages/Checkers.razor b/Projects/Website/Pages/Checkers.razor index bdc799c5..d8804f57 100644 --- a/Projects/Website/Pages/Checkers.razor +++ b/Projects/Website/Pages/Checkers.razor @@ -37,6 +37,10 @@ ↻ You can restart the game by refreshing the page. + + @code { Games.Checkers.Checkers Game; diff --git a/Projects/Website/Pages/Clicker.razor b/Projects/Website/Pages/Clicker.razor new file mode 100644 index 00000000..55bb63db --- /dev/null +++ b/Projects/Website/Pages/Clicker.razor @@ -0,0 +1,74 @@ +@using System + +@page "/Clicker" + +Clicker + +

Clicker

+ + + Go To Readme + + +
+
+
+			@Console.State
+		
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + +@code +{ + Games.Clicker.Clicker Game; + BlazorConsole Console; + + public Clicker() + { + Game = new(); + Console = Game.Console; + Console.WindowWidth = 82; + Console.WindowHeight = 25; + 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 13e74349..b2c080a1 100644 --- a/Projects/Website/Shared/NavMenu.razor +++ b/Projects/Website/Shared/NavMenu.razor @@ -68,6 +68,11 @@ Tower Of Hanoi +