Checking the date in your games

I have recently started a tradition of programming April Fools day pranks into my games.  You can activate them any day of the year by setting your computer calendar to April 1st.

 

Computers currently calculate the date by counting the number of milliseconds that have passed since Jan 1st, 1970 at 12 AM.  Of course, deriving dates from that would be a pain with just that number, so C# and Java naturally have a class to do that part for you.

Here is an example in using it:

DateTime today = DateTime.Today;
int month = today.Month; 
int day = today.Day; 
afDisplay = true; 
if(month == 4 && day == 1) 
{
  StartCoroutine(ShowAFPanel()); 
}

In this example, the game claims it has become sentient and will eat your device (but only on April 1st).   DateTime.Today gets the current time, and DateTime is a class that takes that number and feeds you dates, times, etc.

You can also derive things such as which day of the week it is (Monday, Tuesday, etc), the year, and the time.  afDisplay is a variable I made that checks to see if the prank has already happened (once it’s set to “true”, the prank won’t go off again)

That’s all for now.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s