forked from dotnet/dotnet-console-games
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
104 lines (90 loc) · 2.14 KB
/
Copy pathProgram.cs
File metadata and controls
104 lines (90 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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();
Console.CursorVisible = true;
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) : 1;
}
break;
case ConsoleKey.Escape: goto MainMenu;
default: goto ClickerInput;
}
}