Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Threading;
- namespace ConsoleApplication1 {
- internal static class Program {
- private static DateTime _partyBegin;
- private static DateTime _partyEnd;
- private static DateTime _dt;
- private static int SetPartyWindow(int begin, int end) {
- _partyBegin = DateTime.Today.AddHours(begin);
- _partyEnd = DateTime.Today.AddHours(end);
- return end - begin;
- }
- private static string FormatWithTime(bool condition, string @true, string @false) =>
- $"{( condition ? @true : @false )} {_dt:HH:mm:ss}";
- public static void Main(string[] args) {
- int diff = SetPartyWindow(12, 20);
- string quitMsg;
- Console.CursorVisible = false;
- Console.WriteLine($"Set for a(n) {diff} hour party.");
- Console.WriteLine($"Party begins {_partyBegin:yyyy MMMM dd} at {_partyBegin:HH:mm:ss}");
- Console.WriteLine($"Party ends {_partyEnd:yyyy MMMM dd} at {_partyEnd:HH:mm:ss}");
- while (true) {
- _dt = DateTime.Now;
- bool partyTime = _dt.Hour >= _partyBegin.Hour && _dt.Hour <= _partyEnd.Hour;
- string msg = FormatWithTime(partyTime, "PARTY TIME!" , "There is no party at this time...");
- quitMsg = FormatWithTime(partyTime, "Party's over :(" , "Goodbye");
- int buffDiff = Console.BufferWidth - 1 - msg.Length;
- Console.Write($"{msg}{string.Join("", Enumerable.Repeat(" ", buffDiff))}");
- if (Console.KeyAvailable) {
- if (Console.ReadKey(true).Key == ConsoleKey.Escape) {
- break;
- }
- }
- Console.CursorLeft = 0;
- Thread.Sleep(1000);
- }
- Console.WriteLine();
- Console.WriteLine(quitMsg);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement