How to rewrite the Russian square in C and the Russian square in C
I used to write a Tetris in C language, but I haven't read the program since I wrote it. The source code is too bad for anyone to read. I also posted the source code on the Internet. I really don't know what I think. Maybe it was the first time I wrote a program that I always wanted to write. So I'm very excited. I believe that many people who have studied C language have written about tetris.
This time I re-intend to re-write Russia. I felt that my programming skills had been improved a little, so I wanted to re-create a better source code; second, I learned some content about direct X game programming. I want to write a Russian box under DX instead of a Russian box under GDI. You know that the performance of GDI is not enough for games.
1>. Data and animation Separation
The main design idea of this time is to separate program data from animation. In the previous version of the program, I combined data processing and animation.
For example, the Move_left function moves to the left. Not only will the data be updated, but the animation code moving to the left is also in this function. It was quite convenient at the time, but it was quite troublesome to modify it. The main purpose of this operation is to port DX to remove the data code from the animation code by using the dual-buffer of DX.
In this case, data processing is data processing, and animation processing is animation processing without interfering with each other. DX Code only needs to draw an animation with the processed data.
2>. module functions
There are a lot of repeated code in the previous version, so in this version, I made the same part of the logic code that processes data into a public module, as long as the parameters are passed in, check the return value to use it. This is more convenient, and the main thing is that if this module has any bugs, it will not be searched for in several functions.
Does this reduce code coupling?
3>. Develop and fix bugs
We should design algorithms from the very beginning when writing programs. Otherwise, it is easy to write while thinking.
This is a typical example. So the bug went on one by one. Fortunately, the code was too powerful to run.
However, it is estimated that there are still a lot of bugs. Well, let's try again. However, how to test the code is also a requirement.
Now it is better than before. In the past, only printf was used, and now there is a compiler.
4>. About header files
For the inclusion of header files in the C language, I have always been a programmer before writing this software. Now we know how to declare the function in the header file, and then implement the specific function in the C file. The usage of the extern keyword is also known.
To sum up, programming is a practical task, and practice is actually known.
Conclusion:
This article mainly records my experiences and ideas about using C to write the Tetris program. There have been a lot of things in the past few days. It took three days to finish the work planned for two days. The next few days are even more busy. To prepare for the final exam, you have to write a php crawler exercise. You also need to switch this Russian Box program to DX and write a blog. There are a lot of things, but it's okay.
Look forward to the Russian square under DX. I will add more interesting things. The source code will be open at that time, which is also a test for myself.