




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
#include<iostream>#include<windows.h>#include<conio.h>#include<time.h>#include<string>usingnamespacestd;/*===============allthestructures===============*/typedefstructFrame{COORDposition[2];intflag;}Frame;/*===============allthefunctions===============*/voidSetPos(COORDa)//setcursor{HANDLEout=GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(out,a);}voidSetPos(inti,intj)//setcursor{COORDpos={i,j};SetPos(pos);}voidHideCursor(){CONSOLE_CURSOR_INFOcursor_info={1,0};SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);}//把第y行,[xl,x2)之間的坐標(biāo)填充為chvoiddrawRow(inty,intx1,intx2,charch){SetPos(x1,y);for(inti=0;i<=(x2-x1);i)cout<<ch;}//在a,b縱坐標(biāo)相同的前提下,把坐標(biāo)[a,b]之間填充為chvoiddrawRow(COORDa,COORDb,charch){if(a.Y==b.Y)drawRow(a.Y,a.X,b.X,ch);else{SetPos(0,25);cout<<"errorcode01:無法填充行,因?yàn)閮蓚€(gè)坐標(biāo)的縱坐標(biāo)(x)不相等";system("pause");}}//把第x列,[yl,y2]之間的坐標(biāo)填充為chvoiddrawCol(intx,inty1,inty2,charch){inty=y1;while(y!=y21){SetPos(x,y);cout<<ch;y;}}//在a,b橫坐標(biāo)相同的前提下,把坐標(biāo)[a,b]之間填充為chvoiddrawCol(COORDa,COORDb,charch){if(a.X==b.X)drawCol(a.X,a.Y,b.Y,ch);else{SetPos(0,25);cout<<"errorcode02:無法填充列,因?yàn)閮蓚€(gè)坐標(biāo)的橫坐標(biāo)(y)不相等";system("pause");}}//左上角坐標(biāo)、右下角坐標(biāo)、用row填充行、用col填充列voiddrawFrame(COORDa,COORDb,charrow,charcol){drawRow(a.Y,a.X1,b.X-1,row)drawRow(b.Y,a.X1,b.X-1,row)drawCol(a.X,a.Y1,b.Y-1,col)drawCol(b.X,a.Y1,b.Y-1,col)voiddrawFrame(intx1,inty1,intx2,inty2,charrow,charcol){COORDa={x1,y1};COORDb={x2,y2};drawFrame(a,b,row,col);}voiddrawFrame(Frameframe,charrow,charcol){COORDa=frame.position[0];COORDb=frame.position[1];drawFrame(a,b,row,col);}voiddrawPlaying()IdrawFrame(0,0,48,24,'=','|');//drawmapframe;drawFrame(49,0,79,4,'-','|');//drawoutputframedrawFrame(49,4,79,9,'-','|');//drawscoreframedrawFrame(49,9,79,20,'-','|');//drawoperateframedrawFrame(49,20,79,24,'-','|');//drawothermessageframeSetPos(52,6);cout<<"得分:";SetPos(52,7);cout<<"稱號(hào):";SetPos(52,10);cout<<"操作方式:";SetPos(52,12);cout<<"a,s,d,w控制戰(zhàn)機(jī)移動(dòng)。";SetPos(52,14);cout<<"p暫停游戲。";SetPos(52,16);cout<<"e退出游戲。";}//在[a,b)之間產(chǎn)生一個(gè)隨機(jī)整數(shù)intrandom(inta,intb){intc=(rand()%(a-b))a;returnc;}//在兩個(gè)坐標(biāo)包括的矩形框內(nèi)隨機(jī)產(chǎn)生一個(gè)坐標(biāo)COORDrandom(COORDa,COORDb){intx=random(a.X,b.X);inty=random(a.Y,b.Y);COORDc={x,y};returnc;}booljudgeCoordInFrame(Frameframe,COORDspot){if(spot.X>=frame.position[0].X)if(spot.X<=frame.position[1].X)if(spot.Y>=frame.position[0].Y)if(spot.Y<=frame.position[0].Y)returntrue;returnfalse;}voidprintCoord(COORDa){cout<<"("<<a.X<<","<<a.Y<<")";}voidprintFrameCoord(Framea){printCoord(a.position[0]);cout<<"-";printCoord(a.position[1]);intdrawMenu(){SetPos(30,1);cout<<"PlaneWar";drawRow(3,0,79,'-');drawRow(5,0,79,'-');SetPos(28,4);cout<<"w和s選擇,k確定";SetPos(15,11);cout<<"1.簡(jiǎn)單的敵人";SetPos(15,13);cout<<"2.冷酷的敵人";drawRow(20,0,79,'-');drawRow(22,0,79,'-');SetPos(47,11);cout<<"簡(jiǎn)單的敵人:";SetPos(51,13);cout<<"簡(jiǎn)單敵人有著較慢的移動(dòng)速度。";SetPos(24,21);cout<〈"制作:LJF神犇";intj=11;SetPos(12,j);cout<<">>";//drawFrame(45,9,79,17,'=','|');while(1){if(_kbhit()){charx=_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<<"簡(jiǎn)單的敵人:";SetPos(51,13);cout<<"簡(jiǎn)單敵人有著較慢的移動(dòng)速度,比較容易對(duì)付";}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<<"冷酷的敵人移動(dòng)速度較快,難對(duì)付喲。";break;}case'k':{if(j==8)return1;elsereturn2;/*DWORDWINAPIMusicFun(LPVOIDlpParamte){//DWORDOBJ;sndPlaySound(TEXT("bgm.wav"),SND_FILENAME|SND_ASYNC);return0;}*//*==================theGameClass==================*/classGame{public:COORDposition[10];COORDbullet[10];Frameenemy[8];intscore;intrank;intrankf;stringtitle;intflag_rank;Game();//初始化所有voidinitPlane();voidinitBullet();voidinitEnemy();//初始化其中一個(gè)//voidinitThisBullet(COORD);//voidinitThisEnemy(Frame);voidplaneMove(char);voidbulletMove();voidenemyMove();//填充所有voiddrawPlane();voiddrawPlaneToNull();voiddrawBullet();voiddrawBulletToNull();voiddrawEnemy();voiddrawEnemyToNull();//填充其中一個(gè)voiddrawThisBulletToNull(COORD);voiddrawThisEnemyToNull(Frame);voidPause();voidPlaying();voidjudgePlane();voidjudgeEnemy();voidShoot();voidGameOver();voidprintScore();};Game::Game(){initPlane();initBullet();initEnemy();score=0;rank=25;rankf=0;flag_rank=0;}voidGame::initPlane(){COORDcentren={39,22};position[9].X=position[0].X=position[5].X=position[9].X=position[1].X=centren.X-2;position[2].X=position[6].X=centren.X-1;voidGame::drawBullet()voidGame::drawBullet(){centren.X1;1;position[3].X=position[8].X=position[4].X=centren.X2;for(inti=0;i<=4;i)position[i].Y=centren.X1;1;for(inti=6;i<=8;i)position[i].Y=centren.Yposition[5].Y=centren.Y-1;position[9].Y=centren.Y-2;}voidGame::drawPlane(){for(inti=0;i<9;i){SetPos(position[i]);if(i!=5)cout<<"O";elseif(i==5)cout<<"|";}}voidGame::drawPlaneToNull(){for(inti=0;i<9;i){SetPos(position[i]);cout<<"";}}voidGame::initBullet(){for(inti=0;i<10;i)bullet[i].Y=30;}for(inti=0;i<10;i){if(bullet[i].Y!=30){SetPos(bullet[i]);cout<<""";}}}voidGame::drawBulletToNull(){for(inti=0;i<10;i)if(bullet[i].Y!=30){COORDpos={bullet[i].X,bullet[i].Y1};SetPos(pos);cout<<"";}}voidGame::initEnemy(){COORDa={1,1};COORDb={45,15};for(inti=0;i<8;i){enemy[i].position[0]=random(a,b);enemy[i].position[1].X=enemy[i].position[0].X3;enemy[i].position[1].Y=enemy[i].position[0].Y2;}}voidGame::drawEnemy(){for(inti=0;i<8;i)drawFrame(enemy[i].position[0],enemy[i].position[1],'-','|');}voidGame::drawEnemyToNull(){for(inti=0;i<8;i){{drawFrame(enemy[i].position[0],enemy[i].position[1],''');}}voidGame::Pause(){SetPos(61,2);cout<<"SetPos(61,2);cout<<"暫停中...";charc=_getch();while(c!='p')c=_getch();SetPos(61,2);cout<<"";}voidGame::planeMove(charx){if(x=='a')if(position[1].X!=1)for(inti=0;i<=9;i)position[i].X-=2;if(x=='s')if(position[7].Y!=23)for(inti=0;i<=9;i)position[i].Y=1;if(x=='d')if(position[4].X!=47)for(inti=0;i<=9;i)
position[i].X=2;if(x=='w')if(position[5].Y!=3)for(inti=0;i<=9;i)
position[i].Y-=1;voidGame::bulletMove(){for(inti=0;i<10;i){if(bullet[i].Y!=30){bullet[i].Y-=1;if(bullet[i].Y==1){COORDpos={bullet[i].X,bullet[i].Y1};drawThisBulletToNull(pos);bullet[i].Y=30;}}}}voidGame::enemyMove(){for(inti=0;i<8;i){for(intj=0;j<2;j)enemy[i].position[j].Y;if(24==enemy[i].position[1].Y){COORDa={1,1};COORDb={45,3};enemy[i].position[0]=random(a,b);enemy[i].position[1].X=enemy[i].position[0].X3;enemy[i].position[1].Y=enemy[i].position[0].Y2;}}}voidGame::judgePlane(){for(inti=0;i<8;i)for(intj=0;j<9;j)if(judgeCoordInFrame(enemy[i],position[j])){SetPos(62,1);cout<<"墜毀";drawFrame(enemy[i],'','');Sleep(1000);GameOver();break;}}voidGame::drawThisBulletToNull(COORDc){SetPos(c);cout<<"";}voidGame::drawThisEnemyToNull(Framef){drawFrame(f,'','');}voidGame::judgeEnemy(){for(inti=0;i<8;i)for(intj=0;j<10;j)if(judgeCoordInFrame(enemy[i],bullet[j])){score=5;drawThisEnemyToNull(enemy[i]);COORDa={1,1};COORDb={45,3};enemy[i].position[0]=random(a,b);enemy[i].position[1].X=enemy[i].position[0].X3;enemy[i].position[1].Y=enemy[i].position[0].Y2;drawThisBulletToNull(bullet[j]);bullet[j].Y=30;voidGame::Shoot(){for(inti=0;i<10;i)if(bullet[i].Y==30){bullet[i].X=position[5].X;bullet[i].Y=position[5].Y-1;break;}}voidGame::printScore(){if(score==120&&flag_rank==0){rank-=3;flag_rank=1;}elseif(score==360&&flag_rank==1){rank-=5;flag_rank=2;}elseif(score==480&&flag_rank==2){rank-=5;flag_rank=3;}intx=rank/5;SetPos(60,6);cout<<score;if(rank!=rankf){SetPos(60,7);if(x==5)title="初級(jí)飛行員";elseif(x==4)title="中級(jí)飛行員";elseif(x==3)title="高級(jí)飛行員";elseif(x==2)title="王牌飛行員";cout<<title;}rankf=rank;}voidGame::Playing(){//HANDLEMFUN;//MFUN=CreateThread(NULL,0,MusicFun,NULL,0,NULL);drawEnemy();drawPlane();intflag_bullet=0;intflag_enemy=0;while(1){Sleep(8);if(_kbhit()){charx=_getch();if('a'==x||'s'==x||'d'==x||'w'==x){drawPlaneToNull();planeMove(x);drawPlane();judgePlane();}elseif('p'==x)Pause();elseif('k'==x)Shoot();elseif('e'==x){//CloseHandle(MFUN);GameOver();break;}/*處理子彈*/if(0==flag_bullet){bulletMove();drawBulletToNull();drawBullet();judgeEnemy();}flag_bullet;if(5==flag_bullet)flag_bullet=0;/*處理敵人*/if(0==flag_enemy){drawEnemyToN
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 電話通訊班管理制度
- 硫酸使用及管理制度
- 科主任外出管理制度
- 耳塞防噪音管理制度
- 職工更衣櫥管理制度
- 肉市場(chǎng)衛(wèi)生管理制度
- 肯德基廚房管理制度
- 育雛期飲食管理制度
- 膠輪車使用管理制度
- 膩?zhàn)由皾{廠管理制度
- 2025年伽師縣(中小學(xué)、幼兒園)教師招聘考試模擬試題及答案
- 2025年廣西壯族自治區(qū)普通高中學(xué)業(yè)水平合格性考試生物模擬二 (含答案)
- 香港證券及期貨從業(yè)資格考試溫習(xí)手冊(cè)版HK
- 2025年中考物理知識(shí)點(diǎn)歸納(挖空版)
- 2024年安徽省初中學(xué)業(yè)水平考試生物試題含答案
- 2024年浙江省中考英語試題卷(含答案解析)
- 2024年演出經(jīng)紀(jì)人考試必背1000題及完整答案(各地真題)
- 團(tuán)員組織關(guān)系轉(zhuǎn)接介紹信(樣表)
- GB/T 18926-2008包裝容器木構(gòu)件
- 一份很詳細(xì)的模具報(bào)價(jià)單
- LANTEK蘭特鈑金軟件手冊(cè)(上)
評(píng)論
0/150
提交評(píng)論