首页 c语言打飞机

c语言打飞机

举报
开通vip

c语言打飞机c语言打飞机 打飞机的代码如下: #include #include #include #include #include #include //step 3 #define WIDTH 40 /* Step 1 : Width of Box */ #define HEIGHT 20 /* Step 1 : Height of Box */ #define BLOCKS 4 /* Step 2 : Number of Block */ #define beep() cout << (...

c语言打飞机
c语言打飞机 打飞机的代码如下: #include #include #include #include #include #include //step 3 #define WIDTH 40 /* Step 1 : Width of Box */ #define HEIGHT 20 /* Step 1 : Height of Box */ #define BLOCKS 4 /* Step 2 : Number of Block */ #define beep() cout << ("\a") /* Step 5 : Define Beep function*/ using namespace std; /* Define Variables */ char box[WIDTH+2][HEIGHT+1]; /* Step 1 : Array of Box */ char block[BLOCKS][4][4]={ /* Step 2 : 7 types of block */ { { 1,0,0,0 }, { 1,0,0,0 }, { 1,0,0,0 }, { 1,0,0,0 } }, { { 0,1,0,0 }, { 0,1,0,0 }, { 0,1,0,0 }, { 0,1,0,0 } }, { { 0,0,1,0 }, { 0,0,1,0 }, { 0,0,1,0 }, { 0,0,1,0 } }, { { 0,0,0,1 }, { 0,0,0,1 }, { 0,0,0,1 }, { 0,0,0,1 } } }; char current_block[4][4]; /* Step 2 : Current block */ int blockx, blocky,a=2000; /* Step 2 : Position of block */ char current_blocknum; /* Step 3 : No of present block */ int dz[HEIGHT]; /* if -1, not selected */ int nextblock,bz=0,sc=0,bz2=0,bz3=0; /* Step 3 : Next block number */ int bkx,bky,fdx,fdy,fdx1,fdy1; char c_block[2][2]; /* Define Function */ void gotoxy(int x, int y) // Step 1 : Move the cursor { COORD Pos = {x-1, y-1}; //COORD is Structure data type SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos); } void init_box(void) /* Step 1 : Function of setup initial screen */ { int x, y; // x -> width, y -> height for(y=0;y= blockx && x < blockx + 4 && // Step 3 y >= blocky && y < blocky + 4 ) // Step 3 cout <<("%c", (current_block[x - blockx][y - blocky]) ? '@' : // Step 3 (box[x][y]==1) ? '#' : '.' ); // Step 3 else cout <<("%c", (box[x][y]==1) ? '#' : '.' ); /* if box[x][y] is 1 ==> draw #, box[x][y] is 0 ==> draw . */ } } cout <<("\n\r"); } } void draw2_box(void) /* Step 1 : Draw screen */ { int x,y,x1; x1=0; gotoxy(1,HEIGHT-3); // Move Cursor for(y=HEIGHT-3;y<=HEIGHT;y++) { for(x=0;x= bkx && x < bkx + 3 && // Step 3 y > bky && y < bky + 3)// Step 3 cout <<("%c", (c_block[x - bkx][y - bky]) ? '@' : // Step 3 (box[x][y]==1) ? '#' : '.' ); // Step 3 else cout <<("%c", (box[x][y]==1) ? '#' : '.' ); } cout <<("\n\r"); } } void draw3_box(void) /* Step 1 : Draw screen */ { int x; if (bz2==0) fdx=bkx+1; if (fdy>0 && bz2==1) { gotoxy(1,fdy); // Move Cursor for(x=0;x0 && bz3==1) { gotoxy(1,fdy1); // Move Cursor for(x=0;x0 && bz2==1) fdy--; else { bz2=0; fdy=HEIGHT-3; } } else { for(x=1;x0 && bz3==1) fdy1--; else { bz3=0; fdy1=HEIGHT-3; } } else { for(x=1;x w if(bz==1) blockx++;/* move one */ else blockx--; if(!check_crash()) /* Step 5: Check crash with block placed in bottom and make bottom area */ { if (bz==1) bz=0; else bz=1; for(x=0;x<4;x++) for(y=0;y<4;y++) if(current_block[x][y]) box[blockx+x][blocky+y] = 0; box[0][current_blocknum+1]=1; box[WIDTH+1][current_blocknum+1]=1;// Make bottom area(Fix block in the bottom) current_blocknum = -1; // Call Next block } } void left() /* Step 4 : move left */ { bkx--; if (bkx<=0)bkx++; } void right() /* Step 4 : Move left */ { bkx++; if (bkx>=WIDTH-1) bkx--; } /* Main Function */ int main() { int key; // Step 4 : check key int timer=0; // Step 3 system("cls"); //Step 1 init_box(); //Step 1 Setup initialize Secreen init_cblk(); current_blocknum = -1; // Step 3 : Present Block srand((unsigned int)time(NULL)); // Step 3 nextblock = rand() % BLOCKS; bkx=(WIDTH+2)/2; bky=HEIGHT-3; fdy=HEIGHT-3; while(1) // Step 3 { int x,y ; if(current_blocknum==-1) /* Step 3 : if block is not selsected */ { //Step 2 current_blocknum = nextblock; // Step 3 nextblock = rand() % BLOCKS; // Step 3 for(y=0;y<4;y++) //Step 2 Set the current block for(x=0;x<4;x++) current_block[x][y] = block[current_blocknum][x][y]; // Step 3 if (bz==1) blockx = 1; //Step 2 set the starting position of block else blockx=(WIDTH-2); blocky = 1; //Step 2 } timer++; // Step 3 if( timer >= a){ /* // Step 3 : if timer >= 100, down block one line */ draw_box(); //Step 1 Draw screen draw2_box(); draw3_box(); timer = 0; down(); if (bz2==1) up_1(); continue; } if(kbhit()) /* Check key, if key is pressed, return true */ { key = getch(); switch(key) { case 224: continue; case 72: // Up key if(bz2==0) rotate(); break; case 75: /* Left Key */ left(); break; case 77: /* Right Key */ right(); break; case 80: /* increase speed Key */ a-=50; if(a<=50) a=50; break; case 27: /* Esc.. End of Game */ return 0; } } } }
本文档为【c语言打飞机】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_686908
暂无简介~
格式:doc
大小:53KB
软件:Word
页数:14
分类:
上传时间:2018-10-14
浏览量:79