Advertisement
Blizzardo1

PartyTime

Aug 7th, 2021
1,755
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Threading;
  4.  
  5. namespace ConsoleApplication1 {
  6.     internal static class Program {
  7.         private static DateTime _partyBegin;
  8.         private static DateTime _partyEnd;
  9.         private static DateTime _dt;
  10.  
  11.         private static int SetPartyWindow(int begin, int end) {
  12.             _partyBegin = DateTime.Today.AddHours(begin);
  13.             _partyEnd = DateTime.Today.AddHours(end);
  14.             return end - begin;
  15.         }
  16.  
  17.         private static string FormatWithTime(bool condition, string @true, string @false) =>
  18.             $"{( condition ? @true : @false )} {_dt:HH:mm:ss}";
  19.  
  20.         public static void Main(string[] args) {
  21.             int diff = SetPartyWindow(12, 20);
  22.             string quitMsg;
  23.             Console.CursorVisible = false;
  24.             Console.WriteLine($"Set for a(n) {diff} hour party.");
  25.             Console.WriteLine($"Party begins {_partyBegin:yyyy MMMM dd} at {_partyBegin:HH:mm:ss}");
  26.             Console.WriteLine($"Party ends {_partyEnd:yyyy MMMM dd} at {_partyEnd:HH:mm:ss}");
  27.             while (true) {
  28.                 _dt = DateTime.Now;
  29.                 bool partyTime = _dt.Hour >= _partyBegin.Hour && _dt.Hour <= _partyEnd.Hour;
  30.                 string msg = FormatWithTime(partyTime, "PARTY TIME!" , "There is no party at this time...");
  31.                 quitMsg =  FormatWithTime(partyTime, "Party's over :(" , "Goodbye");
  32.                 int buffDiff = Console.BufferWidth - 1 - msg.Length;
  33.                 Console.Write($"{msg}{string.Join("", Enumerable.Repeat(" ", buffDiff))}");
  34.                
  35.                 if (Console.KeyAvailable) {
  36.                     if (Console.ReadKey(true).Key == ConsoleKey.Escape) {
  37.                         break;
  38.                     }
  39.                 }
  40.  
  41.                 Console.CursorLeft = 0;
  42.                 Thread.Sleep(1000);
  43.             }
  44.  
  45.             Console.WriteLine();
  46.             Console.WriteLine(quitMsg);
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement