Blizzardo1 icon

PartyTime

Blizzardo1 | PRO | 08/07/21 07:51:52 PM UTC | 0 ⭐ | 2113 👁️ | Never ⏰ | []
C# |

1.96 KB

|

None

|

0 👍

/

0 👎

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);
        }
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎