In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
In the first C programming class, we came into contact with large programs with nearly 200 lines of programs for the first time. Even though the program has been analyzed very clearly now, it still gives me a headache every time I see so many programs.
This large program is a basic aircraft type game. Although it is more than hundreds of times simpler than the games we play on mobile phones and computers, and because it is outputted by cyclic sentences in C language, it always flashes constantly while playing and makes people a little dizzy. But I still find it very interesting.
The printf function is used to display and output the entire game in this airplane game. Found that printf this function is not only used for simple output, but also with getch () this function, and then there is a two-dimensional array scr [22] [N], used together, can make the part of the output constantly refreshed, thus successfully completing the display function of the game. This is an experience of learning this plane game. I feel that the function of C language is very powerful and has more functions than I thought before. it can also be regarded as an incentive for me to learn.
two
When I first started to understand the game, it was not very easy. Some sentences I learned last semester were not enough. Some sentences such as while,for loop and if else judgment can be understood. The usage is the same as when I was learning. To play this game, I think it is actually to see if I can think of using this sentence and when to use it. This is the most important thing. In this aircraft game, such as the movement of enemy planes, it is like this, constantly moving downwards, which requires conditional statements to achieve, judging from the first element of the array line. If it is an enemy plane value, the value moves down one line, the original position assignment blank, if (itemized zero & a [I] [j] = 2), a [I] [j] = 0; if you meet this condition, you will successfully move down. Writing ordinary sentences can also play a powerful role.
3.
Structure, some use SCANF input, or there is no input, printf output I think there must be. This is the beginning and the end, and then the middle part, which may use loops or judgments, such as this aircraft game, first play main (void), first type the frame, and then use ASC code to define our aircraft, × ×, enemy aircraft, and then use switch--case. Then there is a constant cycle and judgment. I think the same is true for most apps.
Several sentences applied
Printf display
While cycle
If else judgment
Switch...case multi-condition judgment
Then there is a two-dimensional array scr [22] [N]
source code
# include
# include
# include
# include
# define N 35
Void print (int [] [N]); / / output function
Void movebul (int [] [N]); / / × × mobile function
Void movepla (int [] [N]); / / enemy aircraft movement function
Void setting (void); / / set function
Void menu (void); / / menu function
Void oper (void); / / Operation function
Int scr [22] [N] = {0}, pl=9,width=24,speed=3,density=30,score=0,death=0;// global variables: interface, our initial position, interface width, enemy plane speed, enemy plane density, score, death
Main (void)
{
Menu ()
Oper ()
}
Void oper ()
{
Int iMago Junior 0
Scr [21] [pl] = 1
Scr [0] [5] = 3
While (1)
{
If (kbhit ())
Switch (getch ()) / / controls moving left and right and entering the menu
{
Case 'a':case' Aids:
If (pl > 0)
Scr [21] [pl] = 0recom SCR [21] [--pl] = 1
Break
Case 'd':case' Downs:
If (pl
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.