if(loopCount % (20 - loopCount / 100) == 0) {
if(dropBlock() == false) {
mode = -1;
loopCount = 1;
}
if(loopCount == 1900)
loopCount--;
}
loopCount++;
A tetris program from a book written by java. I just can’t understand why using such a piece of code to control the droping speed of a block and how it works.
Thank you !
The initial value of loopCount is 1 and dropBlock will return false if the game ends. This piece is contained in the main loop. And the mode is not relevant. I am sorry but I just can’t gvie the whole program here.
It appears that it is set to have loopcount start at one, and lets use a table to examine the effect of
if(loopCount % (20 - loopCount / 100) == 0) {loopCount < 100, loopCount/100 = 0, so loopCount % 20 returns true for 20, 40, 60 and 80. Lets say loopCount is 100 – 199. Now we’re checking if it’s divisible by 19, for 200-300 divisible by 18. I’m not sure what exactly he is trying to achieve with this though. Then it checks if it fails to drop the block maybe, (dropBlock possibly tried to drop the block, and returns true for success, false for failure. Then if it fails it sets mode to -1 (maybe exits?). Then once loopCount reaches 1900, it prevents it from going up (by decreasing to 1899 right before the
loopCount++;, which essentially decreased then increases, so does nothing (holding it at 1900)