Computer Science Canada Tetris!! |
Author: | OmegaSyrus [ Sat Nov 18, 2006 10:38 pm ] |
Post subject: | Tetris!! |
This is a tetris remake i created for a final project for grade 11 last school year. Turned out beautifully. Unfortunately is a mute-program only because in order to upload the file i had to take out all the music to make it small enough. But the graphics are pretty. Unfortunately the program lags like CRAZY on my just-bought computer and i cant figure out why, so if it lags on you i beg your forgiveness, because it ran perfectly on every other computer i used it on. Anyway, give it a try and i hope u enjoy it! ![]() |
Author: | DemonZ [ Sun Nov 19, 2006 7:25 pm ] |
Post subject: | |
this is a very good and inviting tetris game! only thing is it did run a little slow on my computer, but I think the reason ur game runs so slow is because you have too many pictures being drawn at once, or if not that, then maybe its because of how turing compiled it all (turing v. 4.0.5 compiler is very slow, while turing v. 4.1 is faster and better) overall, this games graphics are very nice, and the menu is very thought out. one suggestion though, try commenting your program so that people will have an easier time understanding your logic and learning from it (I dare say stealing or cheating from it) but anyways, good game. |
Author: | ericfourfour [ Sun Nov 19, 2006 8:45 pm ] | ||||||||||||||||||||||||||||||||||||
Post subject: | |||||||||||||||||||||||||||||||||||||
Wow ~2400 lines for Tetris. When there is that many lines in a game like Tetris there has to be room for improvement. Let's start here.
In the if statements you repeatedly check if the button equals 1. Make another if statement that checks if the button equals 1. If it is 1 it will go through the other if statements. It would look like this.
Another thing I noticed was you repeatedly check 180 <= y <= 200. However it is different in the first check. Instead you check 20 <= y <= 40. Why not separate all of the 180 <= y <= 200 checks into a different if structure and have the 20 <= y <= 40 in an exit when statement. It would look like this.
Next, I noticed you had the level choice increase by 1 in every if and the level change choice was 1 less than the it. We will deal with this after one other thing. This is where it can get a bit complicated. Each if checks if the x is between two certain values. These two values have a difference of 18 and the next if checks where the last one left off plus one. What you have to do is construct a good for loop to perform this check that increases by 19 every iteration. Then you would put the ifs inside the for loop so it would look like this.
Now it checks every place x can be in between. Next we have to convert i's value to a number that increments every iteration. The equation should look like this.
Now lets add that to the for loop. Wait, there is one more thing. How do we get the value of the level change choice? We simply subtract one from whatever the level choice is. This is what we have so far.
You will realize that the for loop, loops through every if even if it was not supposed to. In this case we will just add an exit inside the if statement. Here is the new version.
If you have been paying attention you will see that 44 lines have just been reduced to 10. Now for the next part of the section.
Once, again the repetitions. Since they it is checking a different y position as the above ifs we will start a new elsif.
This time it is checking if the x is between a space of 22 pixels and each if is separated by 30 pixels. This is going to work a lot like the previous for loop. Here is what it will look like.
For the checks we will need to do the same thing we did before and the formula for getting an incrementing value follows a pretty simple pattern.
This is what the combined work looks like so far.
Don't worry we're almost done. This is the second last part.
If you've been following you know the drill.
The combined work looks like this.
And now for the last part.
It can be reduced to.
And we are done. The final product looks like this.
65 lines reduced to 30 and I bet I saved more than 250 characters. It should run but I have not tested it. However, if there is an error and you were paying attention you should be able to spot it. |
Author: | OmegaSyrus [ Mon Nov 20, 2006 7:45 pm ] |
Post subject: | |
The reason for the excessive lines is because for 2 player, i simply doubled up and modified my program to run 2 seperate 1 player games, this required doubling up all the tracking variables. Hence you end up with 3x the amount of lines, my actual tetris was i think roughly 750 lines or something, excluding my 'options' menu. And yes, i know i do some not well thought out programming methods for certain things, more knowingly the menu, in my defense the teacher taught us nothing and all that i came up with was what i could think of. Also i've always feared 'for' loops for checking. But good programming eric. Anyway, i designed it for flexibility, for instance to increase the amount of possible square pictures, one must simply change i think 3 lines' numbers. But ya, the original tetris came to around 750, it only runs the 750 if you are in 1 player, the last 1600 lines are ignored since they are for 2 player. And vice versa. If you can make a tetris using all my pictures in less code, go for it. And thank you demonz for the comment. |