-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
85 lines (66 loc) · 2.04 KB
/
Program.cs
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
using System;
using System.Text.RegularExpressions;
using System.Threading;
namespace Stopwatch
{
class Program
{
static void Main(string[] args)
{
Menu();
}
static void Menu()
{
Console.Clear();
Console.WriteLine("Welcome to the stopwatch! Select how long you want to count below:");
Console.WriteLine();
Console.WriteLine("S => Seconds (ex: 10s = 10 Seconds)");
Console.WriteLine("M => Minutes (ex: 1m = 1 Minute)");
Console.WriteLine("E => Exit");
Console.WriteLine();
Console.Write("Enter your choice: ");
string value = Console.ReadLine().ToLower();
if (value == "e")
{
System.Environment.Exit(0);
}
else if (!Regex.IsMatch(value, @"^\d+[sm]$"))
{
Console.WriteLine("Invalid Format!");
Console.ReadKey();
Menu();
return;
}
char type = char.Parse(value.Substring(value.Length - 1, 1));
int time = int.Parse(value.Substring(0, value.Length - 1));
int multiplier = type == 'm' ? 60 : 1;
PreStart(time * multiplier);
}
static void PreStart(int time)
{
Console.Clear();
Console.WriteLine("Ready...");
Thread.Sleep(1000);
Console.WriteLine("Set...");
Thread.Sleep(1000);
Console.WriteLine("Go...");
Thread.Sleep(2500);
Start(time);
}
static void Start(int time)
{
int currentTime = 0;
while (currentTime != time)
{
Console.Clear();
currentTime++;
Console.WriteLine(currentTime);
Thread.Sleep(1000);
}
Console.Clear();
Console.Write("Stopwatch Finish!");
Thread.Sleep(2500);
Menu();
}
}
}