Skip to content

Commit

Permalink
clicker
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharyPatten committed Oct 25, 2023
1 parent 6448b23 commit 5637adb
Show file tree
Hide file tree
Showing 13 changed files with 408 additions and 1 deletion.
20 changes: 20 additions & 0 deletions .github/workflows/Clicker Build.yml
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
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions Projects/Clicker/Clicker.csproj
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>
101 changes: 101 additions & 0 deletions Projects/Clicker/Program.cs
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;
}
}
48 changes: 48 additions & 0 deletions Projects/Clicker/README.md
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)
116 changes: 116 additions & 0 deletions Projects/Website/Games/Clicker/Clicker.cs
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;
}
}
}
}
4 changes: 4 additions & 0 deletions Projects/Website/Pages/Checkers.razor
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
&#8635; You can restart the game by <strong>refreshing</strong> the page.
</div>

<div class="alert alert-info" role="alert">
&#129309; This game was a *<strong><a href="https://github.com/dotnet/dotnet-console-games/pull/40">Community Contribution</a></strong>!
</div>

@code
{
Games.Checkers.Checkers Game;
Expand Down
Loading

0 comments on commit 5637adb

Please sign in to comment.