Wednesday, September 29, 2010

Input System: Part 1 Static Classes

This is going to be a mini tutorial on how to create a simple input system now there are many ways you can go about creating an input system and this is just my approach and is in no way the best but works for what I use it for which is all that matters. Now before I go into the code itself I want to first discuss static classes since there are major discussions with why static classes are bad and should be avoided and such. I will also try and explain when to use static classes and how to use them in relation to c#. 

Now lets start with the good parts of static classes. First off static classes do not need to be created they are automatically created at runtime and because of that these classes can be accessed from anywhere in your code without creating any new variables. This is the main reason why we are using a static class for our input because we want to be able to get whether or not buttons were pressed from not only our main class but a lot of sub classes will also need them. Because there is only one instance of the static class you will never need to create multiple instances of the input class which will simplify a lot of code. 

These characteristics of static classes do come with some downsides though. Now because static classes are created at runtime automatically they can not contain and constructors which in our case is not a problem. And because there are only one version of the class objects like bullets or particles are completely out of the question. Also people do not like it when you continually  reference static classes in your code because it makes it so they can not reuse only part of the code they would need the extra static class for it to function. Now this argument makes sense in a lot of ways but most of the time for me it is the static classes that I want to reuse anyway. For example whenever I create a new project I will instantly copy and paste in my input class and my base game class and build the game up from that. I can see it if someone was to use nothing but static classes to do everything in their game that it would get quite annoying to have to look at all the different classes to understand what is going on, but in this example our input class will be so self explanatory that this will be unnecessary. If this doesn't make complete since it should when I go over how to create and use static classes in the next part. 

Now I do not know exactly what static classes do behind the scenes but this is what I have read and noticed when I use them but I could be wrong in some parts. If you want to do some extra reading you can go here. This was a little more then I wanted to do on static classes since most of this will make since when I show you the code in the next few parts but oh well. Should have the next one ready soon. 

Tuesday, September 14, 2010

Fun Computer Prank

So I was at my school in the computer lab when my friend and I were messing around with the command prompt when we combined forces to create a fun prank. This prank requires access to the command prompt so if your trying it on a school computer make sure you can use it. Now the first step is to take a screenshot of your desktop by pressing the print screen button located above the insert key. Then go into Microsoft Paint and paste it in there ( Control + V ) then save the image ( Control + S ) somewhere like the desktop. Open the image and set it as the desktop background. Then you have to delete all the desktop icons if there are any, these are easily recoverable from the recycle bin or just replacing them so its not that bad. You can also open up a program that takes up all or most of the screen and take the screenshot instead of being confused on the desktop they will try and use or close the program. I would suggest using a common program like internet browser or just a folder thats open. So far this is just a normal prank but this is when things get fun.

Next your going to open the command prompt and type in the following command.

taskkill /f /im explorer.exe

This command ends the task of the windows explorer. You may think the explorer is just to browse your folders or using the internet but explorer does a lot more. After you do this command the task bar is removed and what is showing at the bottom is instead the desktop background which means it is worthless. The start button also doesn't function anymore and no new windows will open. If you close the command prompt there is no way for them to do anything other then restarting which will restart the windows explorer and everything will work just like it did before. If you do not close the command prompt the command that will restart it is.


This will turn back on the windows explorer and return everything to normal and will not do any damage to the computer or anything like that. Besides deleting the desktop icons and changing the desktop background but those are easily fixed.

To long didn't read:
1: Take screenshot of desktop
2: Set background to screenshot
3: type in "taskkill /f /im explorer.exe" into console
4: close console
5: ???
6: profit