Fun countdown timer C#

C Sharp - C# (programming language)
Post Reply
dzcadii
Posts: 94
Joined: Sun Mar 01, 2015 4:36 am

Fun countdown timer C#

Post by dzcadii » Sun Mar 01, 2015 10:48 pm

This is for fun!
Source: http://stackoverflow.com/a/24232554

*Note: Change the namespace for your needs

Code:

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;

namespace Helpers.TimeDate
{
    public class FunTimerHelper
    {
        static Timer timer = new Timer(1000);
        static int i = 5;

        public static void StartFunTime()
        {
            timer.Elapsed += timer_Elapsed;
            timer.Start();
            System.Console.Read();
        }


        public  static void timer_Elapsed(object sender, ElapsedEventArgs e)
        {

            i--;

            System.Console.Clear();
            System.Console.WriteLine("=================================================");
            System.Console.WriteLine("                  DIFFUSE THE BOMB");
            System.Console.WriteLine("");
            System.Console.WriteLine("                Time Remaining:  " + i.ToString());
            System.Console.WriteLine("");
            System.Console.WriteLine("=================================================");

            if (i == 0)
            {
                System.Console.Clear();
                System.Console.WriteLine("");
                System.Console.WriteLine("==============================================");
                System.Console.WriteLine("         B O O O O O M M M M M ! ! ! !");
                System.Console.WriteLine("");
                System.Console.WriteLine("               G A M E  O V E R");
                System.Console.WriteLine("==============================================");

                timer.Close();
                timer.Dispose();
            }

            GC.Collect();
        }
    }
}
Usage:

Code: Select all

using Helpers.TimeDate;

//Just some fun :: Exits after
FunTimerHelper.StartFunTime();
Environment.Exit(0);
:text-goodpost:

Post Reply