C语言飞机大战源码.docx

上传人:rrsccc 文档编号:10420659 上传时间:2021-05-15 格式:DOCX 页数:17 大小:17.67KB
返回 下载 相关 举报
C语言飞机大战源码.docx_第1页
第1页 / 共17页
C语言飞机大战源码.docx_第2页
第2页 / 共17页
C语言飞机大战源码.docx_第3页
第3页 / 共17页
C语言飞机大战源码.docx_第4页
第4页 / 共17页
亲,该文档总共17页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《C语言飞机大战源码.docx》由会员分享,可在线阅读,更多相关《C语言飞机大战源码.docx(17页珍藏版)》请在三一文库上搜索。

1、。#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 cursorHANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(out, a);void SetPos(int i, int j)/ se

2、t 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

3、 纵坐标相同的前提下,把坐标 a, b 之间填充为 ch void 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;

4、y+;/ 在 a, b 横坐标相同的前提下,把坐标 a, b 之间填充为 ch void 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,

5、 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 = fr

6、ame.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,

7、 -, |);/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

8、(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.冷酷的敌人 ;精选资料,欢迎下载。d

9、rawRow(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

10、;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;els

11、e 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 init

12、Plane();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();/ 填充其

13、中一个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:initP

14、lane()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;positio

15、n5.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

16、 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 = en

17、emyi.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;

18、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+)positio

19、ni.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+)f

20、or(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(e

21、nemyi, 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( judgeCoordI

22、nFrame(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

23、(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

24、(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

25、,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

26、 (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();精选资料,欢迎下载。Welcome !欢迎您的下载,资料仅供参考!精选资料,欢迎下载

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1