C语言飞机大战源码.doc

上传人:xin****828 文档编号:6686640 上传时间:2020-03-02 格式:DOC 页数:16 大小:16.67KB
返回 下载 相关 举报
C语言飞机大战源码.doc_第1页
第1页 / 共16页
C语言飞机大战源码.doc_第2页
第2页 / 共16页
C语言飞机大战源码.doc_第3页
第3页 / 共16页
点击查看更多>>
资源描述
#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 )title=王牌飞行员;cout= rank )flag_enemy = 0;/* 输出得分 */printScore();void Game:GameOver()system(cls);COORD p1=28,9;COORD p2=53,15;drawFrame(p1, p2, =, |);SetPos(36,12);string str=Game Over!;for(int i=0; istr.size(); i+)Sleep(80);coutstri;Sleep(1000);system(cls);drawFrame(p1, p2, =, |);SetPos(31, 11);cout击落敌机:score/5 架;SetPos(31, 12);cout得分:score;SetPos(31, 13);cout获得称号:title;SetPos(30, 16);Sleep(1000);cout继续? 是(y)| 否(n);as:char x=_getch();if (x = n)exit(0);else if (x = y)system(cls);Game game;int a = drawMenu();if(a = 2)game.rank = 20;system(cls);drawPlaying();game.Playing();else goto as;/*= the main function =*/int main()/游戏准备srand(int)time(0);/随机种子HideCursor();/隐藏光标Game game;int a = drawMenu();if(a = 2)game.rank = 20;system(cls);drawPlaying();game.Playing();
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 中学资料


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!