C语言飞机大战源码.doc_第1页
C语言飞机大战源码.doc_第2页
C语言飞机大战源码.doc_第3页
C语言飞机大战源码.doc_第4页
C语言飞机大战源码.doc_第5页
已阅读5页,还剩27页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

.#include#include#include#include#includeusing namespace std;/*= all the structures =*/typedef struct FrameCOORD position2;int flag;Frame;/*= all the functions =*/void SetPos(COORD a)/ set cursor HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(out, a);void SetPos(int i, int j)/ set cursorCOORD pos=i, j;SetPos(pos);void HideCursor()CONSOLE_CURSOR_INFO cursor_info = 1, 0; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);/把第y行,x1, x2) 之间的坐标填充为 chvoid drawRow(int y, int x1, int x2, char ch)SetPos(x1,y);for(int i = 0; i = (x2-x1); i+)coutch;/在a, b 纵坐标相同的前提下,把坐标 a, b 之间填充为 chvoid drawRow(COORD a, COORD b, char ch)if(a.Y = b.Y)drawRow(a.Y, a.X, b.X, ch);elseSetPos(0, 25);couterror code 01:无法填充行,因为两个坐标的纵坐标(x)不相等;system(pause);/把第x列,y1, y2 之间的坐标填充为 chvoid drawCol(int x, int y1, int y2, char ch)int y=y1;while(y!=y2+1)SetPos(x, y);coutch;y+;/在a, b 横坐标相同的前提下,把坐标 a, b 之间填充为 chvoid drawCol(COORD a, COORD b, char ch)if(a.X = b.X)drawCol(a.X, a.Y, b.Y, ch);elseSetPos(0, 25);couterror code 02:无法填充列,因为两个坐标的横坐标(y)不相等;system(pause);/左上角坐标、右下角坐标、用row填充行、用col填充列void drawFrame(COORD a, COORD b, char row, char col)drawRow(a.Y, a.X+1, b.X-1, row);drawRow(b.Y, a.X+1, b.X-1, row);drawCol(a.X, a.Y+1, b.Y-1, col);drawCol(b.X, a.Y+1, b.Y-1, col);void drawFrame(int x1, int y1, int x2, int y2, char row, char col)COORD a=x1, y1;COORD b=x2, y2;drawFrame(a, b, row, col);void drawFrame(Frame frame, char row, char col)COORD a = frame.position0;COORD b = frame.position1;drawFrame(a, b, row, col);void drawPlaying()drawFrame(0, 0, 48, 24, =, |);/draw map frame;drawFrame(49, 0, 79, 4, -, |);/draw output framedrawFrame(49, 4, 79, 9, -, |);/draw score framedrawFrame(49, 9, 79, 20, -, |);/draw operate framedrawFrame(49, 20, 79, 24, -, |);/draw other message frameSetPos(52, 6);cout得分:;SetPos(52, 7);cout称号:;SetPos(52,10);cout操作方式:;SetPos(52,12);cout a,s,d,w 控制战机移动。;SetPos(52,14);cout p 暂停游戏。;SetPos(52,16);cout=frame.position0.X)if(spot.X=frame.position0.Y)if(spot.Y=frame.position0.Y)return true;return false;void printCoord(COORD a)cout( a.X , a.Y );void printFrameCoord(Frame a)printCoord(a.position0);cout - ;printCoord(a.position1);int drawMenu()SetPos(30, 1);coutP l a n e W a r;drawRow(3, 0, 79, -);drawRow(5, 0, 79, -);SetPos(28, 4);coutw 和 s 选择, k 确定;SetPos(15, 11);cout1. 简单的敌人;SetPos(15, 13);cout2. 冷酷的敌人;drawRow(20, 0, 79, -);drawRow(22, 0, 79, -);SetPos(47, 11);cout简单的敌人:;SetPos(51, 13);cout简单敌人有着较慢的移动速度。;SetPos(24, 21);cout制作: 中北大学 12060341 梦笔西谈;int j=11;SetPos(12, j);cout;/drawFrame(45, 9, 79, 17, =, |);while(1)if( _kbhit() )char x=_getch();switch (x)case w :if( j = 13)SetPos(12, j);cout;j = 11;SetPos(12, j);cout;SetPos(51, 13);cout;SetPos(47, 11);cout简单的敌人:;SetPos(51, 13);cout简单敌人有着较慢的移动速度。;break;case s :if( j = 11 )SetPos(12, j);cout;j = 13;SetPos(12, j);cout;SetPos(51, 13);cout;SetPos(47, 11);cout冷酷的敌人:;SetPos(51, 13);cout冷酷的敌人移动速度较快。;break;case k :if (j = 8)return 1;else return 2;/* DWORD WINAPI MusicFun(LPVOID lpParamte)/DWORD OBJ;sndPlaySound(TEXT(bgm.wav), SND_FILENAME|SND_ASYNC);return 0;*/*= the Game Class =*/class Gamepublic:COORD position10;COORD bullet10;Frame enemy8;int score;int rank;int rankf;string title;int flag_rank;Game ();/初始化所有void initPlane();void initBullet();void initEnemy();/初始化其中一个/void initThisBullet( COORD );/void initThisEnemy( Frame );void planeMove(char);void bulletMove();void enemyMove();/填充所有void drawPlane();void drawPlaneToNull();void drawBullet();void drawBulletToNull();void drawEnemy();void drawEnemyToNull();/填充其中一个void drawThisBulletToNull( COORD );void drawThisEnemyToNull( Frame );void Pause();void Playing();void judgePlane();void judgeEnemy();void Shoot();void GameOver();void printScore();Game:Game()initPlane();initBullet();initEnemy();score = 0;rank = 25;rankf = 0;flag_rank = 0;void Game:initPlane()COORD centren=39, 22;position0.X=position5.X=position7.X=position9.X=centren.X;position1.X=centren.X-2;position2.X=position6.X=centren.X-1;position3.X=position8.X=centren.X+1;position4.X=centren.X+2;for(int i=0; i=4; i+)positioni.Y=centren.Y;for(int i=6; i=8; i+)positioni.Y=centren.Y+1;position5.Y=centren.Y-1;position9.Y=centren.Y-2;void Game:drawPlane()for(int i=0; i9; i+)SetPos(positioni);if(i!=5)coutO;else if(i=5)cout|;void Game:drawPlaneToNull()for(int i=0; i9; i+)SetPos(positioni);cout ;void Game:initBullet()for(int i=0; i10; i+)bulleti.Y = 30;void Game:drawBullet()for(int i=0; i10; i+)if( bulleti.Y != 30)SetPos(bulleti);cout;void Game:drawBulletToNull()for(int i=0; i10; i+)if( bulleti.Y != 30 )COORD pos=bulleti.X, bulleti.Y+1;SetPos(pos);cout ;void Game:initEnemy()COORD a=1, 1;COORD b=45, 15;for(int i=0; i8; i+)enemyi.position0 = random(a, b);enemyi.position1.X = enemyi.position0.X + 3;enemyi.position1.Y = enemyi.position0.Y + 2;void Game:drawEnemy()for(int i=0; i8; i+)drawFrame(enemyi.position0, enemyi.position1, -, |);void Game:drawEnemyToNull()for(int i=0; i8; i+)drawFrame(enemyi.position0, enemyi.position1, , );void Game:Pause()SetPos(61,2);cout ;SetPos(61,2);cout暂停中.;char c=_getch();while(c!=p)c=_getch();SetPos(61,2);cout ;void Game:planeMove(char x)if(x = a)if(position1.X != 1)for(int i=0; i=9; i+)positioni.X -= 2;if(x = s)if(position7.Y != 23)for(int i=0; i=9; i+)positioni.Y += 1;if(x = d)if(position4.X != 47)for(int i=0; i=9; i+)positioni.X += 2;if(x = w)if(position5.Y != 3)for(int i=0; i=9; i+)positioni.Y -= 1;void Game:bulletMove()for(int i=0; i10; i+)if( bulleti.Y != 30)bulleti.Y -= 1;if( bulleti.Y = 1 )COORD pos=bulleti.X, bulleti.Y+1;drawThisBulletToNull( pos );bulleti.Y=30;void Game:enemyMove()for(int i=0; i8; i+)for(int j=0; j2; j+)enemyi.positionj.Y+;if(24 = enemyi.position1.Y)COORD a=1, 1;COORD b=45, 3;enemyi.position0 = random(a, b);enemyi.position1.X = enemyi.position0.X + 3;enemyi.position1.Y = enemyi.position0.Y + 2;void Game:judgePlane()for(int i = 0; i 8; i+)for(int j=0; j9; j+)if(judgeCoordInFrame(enemyi, positionj)SetPos(62, 1);cout坠毁;drawFrame(enemyi, +, +);Sleep(1000);GameOver();break;void Game:drawThisBulletToNull( COORD c)SetPos(c);cout ;void Game:drawThisEnemyToNull( Frame f )drawFrame(f, , );void Game:judgeEnemy()for(int i = 0; i 8; i+)for(int j = 0; j 10; j+)if( judgeCoordInFrame(enemyi, bulletj) )score += 5;drawThisEnemyToNull( enemyi );COORD a=1, 1;COORD b=45, 3;enemyi.position0 = random(a, b);enemyi.position1.X = enemyi.position0.X + 3;enemyi.position1.Y = enemyi.position0.Y + 2;drawThisBulletToNull( bulletj );bulletj.Y = 30;void Game:Shoot()for(int i=0; i10; i+)if(bulleti.Y = 30)bulleti.X = position5.X;bulleti.Y = position5.Y-1;break;void Game:printScore()if(score = 120 & flag_rank = 0)rank -= 3;flag_rank = 1;else if( score = 360 & flag_rank = 1)rank -= 5;flag_rank = 2;else if( score = 480 & flag_rank = 2)rank -= 5;flag_rank = 3;int x=rank/5;SetPos(60, 6);coutscore;if( rank!=rankf )SetPos(60, 7);if( x = 5)title=初级飞行员;else if( x = 4)title=中级飞行员;else if( x = 3)title=高级飞行员;else if( x = 2

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论