C语言飞机大战题目,C语言飞机大战源码.pdf

c8da8f5a7cda2d62dda9e5a200b168b9.gifC语言飞机大战源码.pdf

include include include include include using namespace std; /* all the structures */ typedef struct Frame COORD position2; int flag; Frame; /* all the functions */ void SetPosCOORD a// set cursor HANDLE outGetStdHandleSTD_OUTPUT_HANDLE; SetConsoleCursorPositionout, a; void SetPosint i, int j// set cursor COORD posi, j; SetPospos; void HideCursor CONSOLE_CURSOR_INFO cursor_info 1, 0; SetConsoleCursorInfoGetStdHandleSTD_OUTPUT_HANDLE, //把第 y 行, x1, x2 之间的坐标填充为ch void drawRowint y, int x1, int x2, char ch SetPosx1,y; forint i 0; i x2-x1; i coutch; //在 a, b 纵坐标相同的前提下,把坐标a, b 之间填充为ch void drawRowCOORD a, COORD b, char ch ifa.Y b.Y drawRowa.Y, a.X, b.X, ch; else SetPos0, 25; couterror code 01无法填充行,因为两个坐标的纵坐标x不相等 ; systempause; //把第 x 列, y1, y2 之间的坐标填充为ch void drawColint x, int y1, int y2, char ch int yy1; whileyy21 SetPosx, y; coutch; y; //在 a, b 横坐标相同的前提下,把坐标a, b 之间填充为ch void drawColCOORD a, COORD b, char ch ifa.X b.X drawCola.X, a.Y, b.Y, ch; else SetPos0, 25; couterror code 02无法填充列,因为两个坐标的横坐标y不相等 ; systempause; //左上角坐标、右下角坐标、用row 填充行、用col 填充列 void drawFrameCOORD a, COORD b, char row, char col drawRowa.Y, a.X1, b.X-1, row; drawRowb.Y, a.X1, b.X-1, row; drawCola.X, a.Y1, b.Y-1, col; drawColb.X, a.Y1, b.Y-1, col; void drawFrameint x1, int y1, int x2, int y2, char row, char col COORD ax1, y1; COORD bx2, y2; drawFramea, b, row, col; void drawFrameFrame frame, char row, char col COORD a frame.position0; COORD b frame.position1; drawFramea, b, row, col; void drawPlaying drawFrame0, 0, 48, 24, , |;// draw map frame; drawFrame49, 0, 79, 4, -, |;// draw output frame drawFrame49, 4, 79, 9, -, |;// draw score frame drawFrame49, 9, 79, 20, -, |;// draw operate frame drawFrame49, 20, 79, 24, -, |;// draw other message frame SetPos52, 6; cout 得分 ; SetPos52, 7; cout 称号 ; SetPos52,10; cout 操作方式 ; SetPos52,12; cout a,s,d,w 控制战机移动。; SetPos52,14; cout p 暂停游戏。 ; SetPos52,16; coutframe.position0.X ifspot.Xframe.position0.Y ifspot.Yframe.position0.Y return true; return false; void printCoordCOORD a cout a.X , a.Y ; void printFrameCoordFrame a printCoorda.position0; cout - ; printCoorda.position1; int drawMenu SetPos30, 1; coutP l a n e W a r; drawRow3, 0, 79, -; drawRow5, 0, 79, -; SetPos28, 4; coutw 和 s 选择,k 确定 ; SetPos15, 11; cout1. 简单的敌人 ; SetPos15, 13; cout2. 冷酷的敌人 ; drawRow20, 0, 79, -; drawRow22, 0, 79, -; SetPos47, 11; cout 简单的敌人 ; SetPos51, 13; cout 简单敌人有着较慢的移动速度。; SetPos24, 21; cout 制作中北大学12060341 梦笔西谈 ; int j11; SetPos12, j; cout; //drawFrame45, 9, 79, 17, , |; while1 if _kbhit char x_getch; switch x case w if j 13 SetPos12, j; cout ; j 11; SetPos12, j; cout; SetPos51, 13; cout ; SetPos47, 11; cout 简单的敌人; SetPos51, 13; cout 简单敌人有着较慢的移动速度。; break; case s if j 11 SetPos12, j; cout ; j 13; SetPos12, j; cout; SetPos51, 13; cout ; SetPos47, 11; cout 冷酷的敌人; SetPos51, 13; cout 冷酷的敌人移动速度较快。; break; case k if j 8 return 1; else return 2; /* DWORD WINAPI MusicFunLPVOID lpParamte //DWORD OBJ; sndPlaySoundTEXTbgm.wav, SND_FILENAME|SND_ASYNC; return 0; */ /* the Game Class */ class Game public 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 planeMovechar; 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; ; GameGame initPlane; initBullet; initEnemy; score 0; rank 25; rankf 0; flag_rank 0; void GameinitPlane COORD centren39, 22; position0.Xposition5.Xposition7.Xposition9.Xcentren.X; position1.Xcentren.X-2; position2.Xposition6.Xcentren.X-1; position3.Xposition8.Xcentren.X1; position4.Xcentren.X2; forint i0; i4; i positioni.Ycentren.Y; forint i6; i8; i positioni.Ycentren.Y1; position5.Ycentren.Y-1; position9.Ycentren.Y-2; void GamedrawPlane forint i0; i9; i SetPospositioni; ifi5 coutO; else ifi5 cout|; void GamedrawPlaneToNull forint i0; i9; i SetPospositioni; cout ; void GameinitBullet forint i0; i10; i bulleti.Y 30; void GamedrawBullet forint i0; i10; i if bulleti.Y 30 SetPosbulleti; cout; void GamedrawBulletToNull forint i0; i10; i if bulleti.Y 30 COORD posbulleti.X, bulleti.Y1; SetPospos; cout ; void GameinitEnemy COORD a1, 1; COORD b45, 15; forint i0; i8; i enemyi.position0 randoma, b; enemyi.position1.X enemyi.position0.X 3; enemyi.position1.Y enemyi.position0.Y 2; void GamedrawEnemy forint i0; i8; i drawFrameenemyi.position0, enemyi.position1, -, |; void GamedrawEnemyToNull forint i0; i8; i drawFrameenemyi.position0, enemyi.position1, , ; void GamePause SetPos61,2; cout ; SetPos61,2; cout 暂停中 ...; char c_getch; whilecp c_getch; SetPos61,2; cout ; void GameplaneMovechar x ifx a ifposition1.X 1 forint i0; i9; i positioni.X - 2; ifx s ifposition7.Y 23 forint i0; i9; i positioni.Y 1; ifx d ifposition4.X 47 forint i0; i9; i positioni.X 2; ifx w ifposition5.Y 3 forint i0; i9; i positioni.Y - 1; void GamebulletMove forint i0; i10; i if bulleti.Y 30 bulleti.Y - 1; if bulleti.Y 1 COORD posbulleti.X, bulleti.Y1; drawThisBulletToNull pos ; bulleti.Y30; void GameenemyMove forint i0; i8; i forint j0; j2; j enemyi.positionj.Y; if24 enemyi.position1.Y COORD a1, 1; COORD b45, 3; enemyi.position0 randoma, b; enemyi.position1.X enemyi.position0.X 3; enemyi.position1.Y enemyi.position0.Y 2; void GamejudgePlane forint i 0; i 8; i forint j0; j9; j ifjudgeCoordInFrameenemyi, positionj SetPos62, 1; cout 坠毁 ; drawFrameenemyi, , ; Sleep1000; GameOver; break; void GamedrawThisBulletToNull COORD c SetPosc; cout ; void GamedrawThisEnemyToNull Frame f drawFramef, , ; void GamejudgeEnemy forint i 0; i 8; i forint j 0; j 10; j if judgeCoordInFrameenemyi, bulletj score 5; drawThisEnemyToNull enemyi ; COORD a1, 1; COORD b45, 3; enemyi.position0 randoma, b; enemyi.position1.X enemyi.position0.X 3; enemyi.position1.Y enemyi.position0.Y 2; drawThisBulletToNull bulletj ; bulletj.Y 30; void GameShoot forint i0; i10; i ifbulleti.Y 30 bulleti.X position5.X; bulleti.Y position5.Y-1; break; void GameprintScore ifscore 120 flag_rank 1; else if score 360 flag_rank 2; else if score 480 flag_rank 3; int xrank/5; SetPos60, 6; coutscore; if rankrankf SetPos60, 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 GameGameOver systemcls; COORD p128,9; COORD p253,15; drawFramep1, p2, , |; SetPos36,12; string strGame Over; forint i0; istr.size; i Sleep80; coutstri; Sleep1000; systemcls; drawFramep1, p2, , |; SetPos31, 11; cout 击落敌机 score/5 架; SetPos31, 12; cout 得分 score; SetPos31, 13; cout 获得称号 title; SetPos30, 16; Sleep1000; cout 继续是( y) | 否( n); as char x_getch; if x n exit0; else if x y systemcls; Game game; int a drawMenu; ifa 2 game.rank 20; systemcls; drawPlaying; game.Playing; else goto as; /* the main function */ int main //游戏准备 srandinttime0; //随机种子 HideCursor; //隐藏光标 Game game; int a drawMenu; ifa 2 game.rank 20; systemcls; drawPlaying; game.Playing;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值