Ganxiang 5-10

Source: Internet
Author: User

My understanding of the basic statement of the C language program can be accomplished through a number of simple C language statements to write a function of the program, last semester learning is the most basic command, and have been so complicated programming, this time we try to write the aircraft game, let me benefit, in this program , we used the knowledge of last semester, start with include, then build the foundation, then add various settings, make it a more complex program, and finally succeeded in making it a simple game.

Although in the last semester, we have learned the "C language Program Design" This course, but I learned the most knowledge is in doing homework when it will be used, usually no practice opportunities, this course design is my first time through their own ideas, and students to discuss and constantly consult the data to design a program.  This design not only consolidates the knowledge I have learned, but also gives me a deeper understanding of C language and more skills and skills. C language is the important theoretical foundation of computer program design, which has a very important position in our future study and work. To learn this language, only to learn the knowledge of textbooks is not enough, but also often do their own hands, have a strong practical ability. Only more hands-on, often write programs, to discover our learning loopholes and their shortcomings, and in practice to solve these problems, and constantly improve their ability to transform knowledge.



#include "stdio.h"

#include "stdio.h"

#include "stdio.h"

#include "stdio.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

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 ();

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) 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;< p= "\" \ "" >

for (j=0;j> \ ");; J + +) {if (a[i][j]==0) printf (\\\\\\\\\\\\\\\\\\\\\>

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 the enemy plane density: 1.2. Medium 3. Small >>");

Switch (Getche ())

{

Case \ ' 0\ ':d ensity=10;

Break

Case \ ' 1\ ':d ensity=20;

Break;case \ ' 2\ ':d ensity=30;

Break;case \ ' 3\ ':d ensity=40;break;

default:printf (\ "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n error, please re-select ... \\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n\ ");

Sw=1;

}

}

while (SW);

Do

{

sw=0;

printf (\ "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n Aircraft flying speed: 1. Fast 2. Medium 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++) < p= "\" \ "" >

for (j=0;j<45;j++) < p= "\" \ "" >

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 control my machine left and right flight, W fired bullets \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n settings: Please press esc\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n start Game: any key \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\n\ ");

if (Getch () ==27) setting ();

}


This article is from the "11493864" blog, please be sure to keep this source http://11503864.blog.51cto.com/11493864/1774850

Ganxiang 5-10

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.