I wondered if it would be possible for me to write a fully-functioning Tetris game in less than two hours. This essentially means I would have to rush through writing everything, ignoring anything nice like comments, structure, presentation... it just had to work. I figured the necessary parts would be:
Would it really be possible for me to write all that in less than two hours? I wanted to find out!
I decided to use Visual Basic 6 to write the game, since it's designed for Rapid Application Development. I started my watch, ran VB and started rushing through writing code.
First I ran a nested loop to show lines on the form so you could see where tiles would be. Then I added a boolean array to store the tiles. I quickly worked out that using 0 and 1 to represent the squares wouldn't work, so I made it an integer array. 0 would be empty, 1 would be an old tile and 2 would be the active shape. I added in code to display the squares using, err, circles.
Then I added in a timer, a function to generate pieces and tested it out. It was working fine so far and I had only used up 16 minutes. Then I added in the controls to move left or right, which involved numerous loops to check the active shape wouldn't overlap anything or hit the sides. Then I added in code to zoom the piece down at speed using the down key.
I added in four other shapes and tested everything again. I made a few changes, and was approaching one hour. The game was going along nicely though. Next I added in code to check for lines and move all the lines above down. It took a bit of time to get it working perfectly. After that I added in the code to work out the current level based on the number of lines. Every 8 lines would push you up one level and everything would get faster. I set the maximum levels at 10.
Then I hit my first bit of trouble... rotating shapes. I struggled for a few minutes working out the fastest way of moving the tiles round, I tried a few things but all the checking and flipping items in the array around was going to take too long to write. I figured there was only a small number of pieces, so I would just write all the rotations in manually. I did that and now it was getting on for 1 hour and 40 minutes.
I added in code to check if the first three lines had blocks and if so, you had gone too high and the game should finish. Then I added in a message displaying the level, lines and time taken. I also made the game restartable. I spent a few more minutes testing and amazingly I encountered no bugs.
I had completed the whole game in 1 hour and 47 minutes! It wasn't pretty, it had hardly any comments, the 474 lines of code were terrible... but I had completed it and that's what counts. I played through a game up to level 9 and it worked perfectly.
You can download the code and game (16kb, RAR). It's released under the GNU General Public License. You'll need the Visual Basic 6.0 run time library, but I believe that's included with Windows 2000 and onwards.