-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6448b23
commit 7da34b8
Showing
13 changed files
with
408 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>disable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<h1 align="center"> | ||
Clicker | ||
</h1> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/dotnet/dotnet-console-games"><img src="../../.github/resources/github-repo-black.svg" alt="GitHub repo"></a> | ||
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/"><img src="../../.github/resources/language-csharp.svg" alt="Language C#"></a> | ||
<a href="https://dotnet.microsoft.com/download"><img src="../../.github/resources/dotnet-badge.svg" title="Target Framework" alt="Target Framework"></a> | ||
<a href="https://github.com/dotnet/dotnet-console-games/actions"><img src="https://github.com/dotnet/dotnet-console-games/workflows/Clicker%20Build/badge.svg" title="Goto Build" alt="Build"></a> | ||
<a href="https://discord.gg/4XbQbwF"><img src="../../.github/resources/discord-badge.svg" title="Go To Discord Server" alt="Discord"></a> | ||
<a href="../../LICENSE"><img src="../../.github/resources/license-MIT-green.svg" alt="License"></a> | ||
</p> | ||
|
||
<p align="center"> | ||
You can play this game in your browser: | ||
<br /> | ||
<a href="https://dotnet.github.io/dotnet-console-games/Clicker" alt="Play Now"> | ||
<sub><img height="40"src="../../.github/resources/play-badge.svg" alt="Play Now"></sub> | ||
</a> | ||
<br /> | ||
<sup>Hosted On GitHub Pages</sup> | ||
</p> | ||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.