Always write source code and comments in English (I'm not a native English speaker either). You will sooner or later need to share code with other people around the world, like you just did here and now. Therefore it needs to be in English.
More importantly still, learning two technical programming terms for everything when you only need to learn one is madness. The worst mistake I did when studying engineering back at university was to read books translated to my own language, rather than English. This meant that I had to learn twice the amount of technical terms: the real, correct term in English, and the hogwash term questionably translated to my own language. The latter is completely useless knowledge - in the real world outside school, English terms are used.
As pointed out in another review, the
ritardo
busy-delay should have been replaced by Windows APISleep
in this case. In more advanced Windows programming with threads and events, you wouldn't useSleep
either butWaitForSingleObject
etc. Multi-threading is a somewhat advanced topic, but one you'll eventually need to pick up. Then this program would use one thread for the graphics, one for input and maybe a third for calculations. Rather than using old MS DOS stylekbhit
- DOS didn't have threads.If you were to implement a busy-delay loop, the loop iterator
i
would need to be declaredvolatile
. Otherwise the compiler is just going to optimize away the whole loop.Never use floating point numbers for loop iterators. It makes the code slower and the comparison expression might unexpectedly fail because of floating point inaccuracy.
Always try to declare the loop iterator inside the for loop:
for(int i=0; ...
.You need to get rid of all global variables. Plenty of info about why they are bad to be found on the net.
Never use obsolete style empty parenthesis functions in C:
void caricaArray()
. This means that the function takes any parameter and this style might get removed from C at any point, since it is formally obsolete. Correct form isvoid caricaArray(void)
.(Not to be confused with C++ where empty parenthesis is fine and equivalent to
(void)
.)As noted in another review, you need to decide a coding style and stick with it. Brace placement, indention etc. As it stands, the code is barely readable.
srand();
should only be called once at the beginning of the program, you call it inside a loop.
↧
Answer by Lundin for Simple Tetris game
↧