C Language Programming Thoughts

Source: Internet
Author: User

The combination of C language course design and the practical application of modern computer technology is a good test of our ability in this stage after we have finished the theoretical course. From the beginning of the algorithm to the beautiful graphical interface after commissioning and the other exciting program is a good learning and exercise process. So that we can consolidate the original theoretical knowledge and develop our ability to flexibly use and combine the knowledge and skills we have learned to analyze and solve practical problems. We realize that our knowledge and abilities can be applied and played in practice. Not only can inspire innovation consciousness but also can develop creative ability, develop communication ability. This internship, although only one weeks, has really benefited me. Through the internship I enriched the computer operation experience deepened the understanding of C language familiar with its environment more

    I learned the C language data types, constants and symbolic constants, variables, C-language operators and expressions, assignment operators and assignment expressions, self-increment and comma expressions, and so on.   think that the instance phase should be a transition stage, through the previous stage of the grammar of the study, there may be many concepts we are more vague, or a lot of things too abstract, this for our second stage of learning to do the instantiation of the preparation, so to speak, The first stage is a class that we build for our learning thing, which tells us what we should do in this area. The second order, that is, this stage, we should go to the previous paragraph of the thing materialized (instantiation of the previously created class), that how to materialize, plainly, to practice some small examples, from the online download of e-book There are many examples of this, if you have to buy books in the bookstore, it should also provide a lot of Inside the example, I have played every time, maybe some people will not personally to play with the hand, what copy and so on, of course, but I personally think, for beginners, it is better to do a good job, after all, these things for us, are more unfamiliar, if each word is finished by themselves, Some code you do not want to remember also difficult, here, we have to understand every example of practice, if you can change some examples slightly, to understand the essence of the thing, let oneself know why do so, then is the best, I usually practice, this step is indispensable, are accustomed to, so also became a reflex, I don't think so. Finally, we should remit the total, the previous examples used in the technology to rationale, and then do a larger example, as far as possible to understand all the knowledge to apply to the inside, just try to, of course, some things can not be integrated together, is also the exclusion of code.

Second, aircraft games (or other software) in the last semester to learn the basic C language statement is how to use it?

Before learning a lot of similar to what printf,scanf,if,else function, and so on, summed up a bit about the following several ways to use:

1, expression statement, empty statement, compound statement.
2, input and output data, input and output functions of the call.
3, compound statement.
4, goto statement and the use of the statement label.
III. analysis of the structure of aircraft games (or other software).

Make simple changes to the code as required by the teacher

1) The program uses functions to form a modular structure
2) in the main function, first call the menu () function to generate the menus
3) Then, by constantly receiving the user's keys, determine what the operation
4) Then set the airplane and the bullet to move
5) display
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#define N 35
void print (int [][n]);//Output function
void Movebul (int [][n]);//bullet Move function
void Movepla (int [][n]);//enemy 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, my machine initial position, interface width, enemy speed, enemy plane density, score, death
Main (void)
{
menu ();
Oper ();
}
void Oper ()
{
int i=0,j=0;
Scr[21][pl]=1;
scr[0][5]=3;
while (1)
{
if (Kbhit ())
Switch (Getch ())//control move around and enter menu
{
Case ' A ': Case ' a ':
if (pl>0)
Scr[21][pl]=0,scr[21][--pl]=1;
Break
Case ' d ': Case ' d ':
if (pl<width-2)
Scr[21][pl]=0,scr[21][++pl]=1;
Break
Case ' W ': Case ' W ':
scr[20][pl]=2;
Break
Case 27:
Setting ();
Break
}
if (++j%density==0)//control the speed of production of enemy aircraft
{
J=0;srand (Time (NULL));
Scr[0][rand ()%width]=3;
}
if (++i%speed==0)//control enemy movement speed, relative to the speed of the bullet movement
Movepla (SCR);
Movebul (SCR);

Print (SCR);
if (i==30000)
i=0;//lest I cross the border
}
}
void print (int a[][n])
{
System ("CLS");
int i,j;
for (i=0;i<22;i++)
{
a[i][width-1]=4;
for (j=0;j<width;j++)
{
if (a[i][j]==0)
printf ("");
if (a[i][j]==1)
printf ("\5");//output the symbol of my machine
if (a[i][j]==2)
printf ("."); /Bullets
if (a[i][j]==3)
printf ("\3"); Output enemy Symbol
if (a[i][j]==4)
printf ("|");
if (i==0&&j==width-1)
printf ("Score:%d", score);//The top right corner shows the score
if (i==1&&j==width-1)
printf ("Death:%d", death);
if (i==2&&j==width-1)
printf ("Settings: Esc");
if (i==3&&j==width-1)
printf ("Copyright: Zhang Xun");
}
printf ("\ n");
}
}
void Movebul (int a[][n])
{
int i,j;
for (i=0;i<22;i++)
for (j=0;j<width;j++)
{
if (i==0&&a[i][j]==2)
a[i][j]=0;
if (a[i][j]==2)
{
if (a[i-1][j]==3)
score+=10,printf ("\7");
a[i][j]=0,a[i-1][j]=2;
}
}
}
void Movepla (int a[][n])
{
int i,j;
for (i=21;i>=0;i--)//from the last line up is to avoid the enemy aircraft directly rushed to the group.
for (j=0;j<width;j++)
{
if (i==21&&a[i][j]==3)
a[i][j]=0;//the bottom row is assigned a value of 0 to avoid crossing.
if (a[i][j]==3)
a[i][j]=0,a[i+1][j]=3;
}
if (a[20][pl]==3&&a[21][pl]==1)
death++;
}
void setting (void)
{
int sw=0,i,j;
System ("CLS");
do{sw=0;printf ("\ n the size of the game interface: 1. Big 2. >>");
Switch (Getche ())
{
Case ' 1 ':
width=34;
Break
Case ' 2 ':
width=24;
Break
Default
printf ("\ n error, please re-select ... \ n");
Sw=1;
}
}
while (SW);
Do
{
sw=0;
printf ("\ n Please select enemy aircraft density: 1.2. Medium 3. Small >>");
Switch (Getche ())
{
Case ' 0 ':
density=10;
Break
Case ' 1 ':
density=20;
Break
Case ' 2 ':
density=30;
Break
Case ' 3 ':
density=40;
Break
Default
printf ("\ n error, please re-select ... \ n");
Sw=1;
}
}while (SW);
Do
{
sw=0;
printf ("\ nthe enemy aircraft speed: 1. Fast 2.3. Slow >>");
Switch (Getche ())
{
Case ' 1 ':
speed=2;
Break
Case ' 2 ':
speed=3;
Break
Case ' 3 ':
speed=4;
Break
Default
printf ("\ n error, please re-select ... \ n");
Sw=1;
}
}while (SW);
for (i=0;i<22;i++)
for (j=0;j<45;j++)
scr[i][j]=0;
Scr[21][pl=9]=1;
printf ("\ n Press any key to save ...");
Getch ();
}
void menu (void)
{
printf ("Description: Press a D to control my flight, W fired bullets \ n set: Please press esc\n to start the game: any key \ n by Zhang-xun");
if (Getch () ==27)
Setting ();
}


C Language Programming Thoughts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.