計(jì)算機(jī)技術(shù)基礎(chǔ)(c語言)課程設(shè)計(jì)-潛艇大戰(zhàn)_第1頁
計(jì)算機(jī)技術(shù)基礎(chǔ)(c語言)課程設(shè)計(jì)-潛艇大戰(zhàn)_第2頁
計(jì)算機(jī)技術(shù)基礎(chǔ)(c語言)課程設(shè)計(jì)-潛艇大戰(zhàn)_第3頁
計(jì)算機(jī)技術(shù)基礎(chǔ)(c語言)課程設(shè)計(jì)-潛艇大戰(zhàn)_第4頁
計(jì)算機(jī)技術(shù)基礎(chǔ)(c語言)課程設(shè)計(jì)-潛艇大戰(zhàn)_第5頁
已閱讀5頁,還剩12頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、文檔從網(wǎng)絡(luò)中收集,已重新整理排版.word版本可編輯:歡迎下載支持.計(jì)算機(jī)技術(shù)基礎(chǔ)課程設(shè)計(jì)C語言設(shè)計(jì)報(bào)告題目:簡(jiǎn)單潛艇大戰(zhàn)一、選題背景:隨著人們生活水平的提高,人們對(duì)精神生活的要求也隨 之提高了,當(dāng)然,娛樂也成了人們生活中必不可少的一部分, 為此,我用C語言編輯了一個(gè)簡(jiǎn)單的簡(jiǎn)單潛艇大戰(zhàn)游戲程序。 它操作起來簡(jiǎn)單方便,運(yùn)行速度快。二、設(shè)計(jì)思想:簡(jiǎn)單潛艇大戰(zhàn)就是玩家和電腦對(duì)戰(zhàn)的游戲,玩家在確保 本身不被敵人擊中的情況下?lián)糁袛橙藙t得分,若被敵人擊中 游戲結(jié)束。此程序利用了 if, for, while等多種語句進(jìn)行了 編譯,而且多次使用了 for語句進(jìn)行了循環(huán),用if語句進(jìn) 行操作,if語句是用來處

2、理?xiàng)l件選擇的一種語句。此游戲可 以任意移動(dòng)玩家的位置。三、程序流程圖開始V丿圖形初始化否否(敵人在攻擊范圍之內(nèi))(玩家在攻擊范困之內(nèi))9word版本可編輯歡迎下載支持.四、程序清單include include include #include define KEY_ESC 0x01define KEY.SPACE 0x39define KEY.LEFT 0x4bdefine KEY_RIGHT 0x4dint speed二10000;char key_state128, key_pressed128 ;/*鍵盤操作用的變量*/int score二0;/*得分*/char scorestrEl

3、O ;/*輸出分?jǐn)?shù)的變量*/struct Fire/*子彈的結(jié)構(gòu)體*/int x;int y;int start;/*是否發(fā)射炮彈*/amyfire6 ;/*屏幕上最多有5個(gè)敵人可以發(fā)子彈*/struct Play/*玩家的結(jié)構(gòu)體*/int x;int y;struct Fire fire 16;life;Jplay;struct Amy/*敵人的結(jié)構(gòu)體*/int x;int y;int speed;/*敵人的速度*/int color;int direction;Hfe;amy6;void InitGraph(void) ;/*圖形初始化*/void CloseGraph(void) ;/*

4、圖形結(jié)束*/void GamePlay (void) ;/*具體玩游戲*/void DrawPlay (void) ;/*畫玩家*/void DrawAmy(int i) ;/*畫敵人*/void DrawFire (int x, int y, int n) ;/*畫子彈,0 去除,1 顯示*/void DrawAmyFire(int x, int y, int n) ;/*畫子彈,0 去除,1 顯示*/void DrawBlack(int x, int y, int color) ;/*去除原來地方的物體*/void PrScore 0 ;/*輸出得分*/int GetKey (int Sc

5、anCode) ;/*這里開始都是按鍵函數(shù)*/void interrupt far (*01dInt9Handler)();void far interrupt Newlnt9();void InstallKeyboardO ;void ShutDownKeyboard();void main(void)InitGraphO ;/*圖形初始化*/GamePlay () ;/*具體玩游戲*/CloseGraphO ;/*圖形結(jié)束*/void InitGraph(void) /*圖形初始化*/int gd二DETECT, gm;initgraph(&gd, &gm, c:tc);cleardevi

6、ce 0;InstalIKeyboard 0;void DrawPlay(void)/*畫玩家*/setfillstyle(SOLID.FILL, 6);bar (play. x20, play y10, play. x+20, play. y);setfillstyle(SOLID.FILL, 4);bar (play. x20, play. y-10, play. x10, play. y);void DrawAmy(int :1)/*畫敵人*/setfillstyle(SOLID_FILL, amyi color);bar(amyi x20, amyi y10, amyi x+20, a

7、myi y);setfillstyle(SOLID.FILL, GREEN);if(amyi direction=l)bar (amyi x20, amy i y-10, amyi x*10, amyi y);elsebar (amyi x+10, amyi y10, amyi x+20, amyi y);void DrawBlack(int x, int y, int color)/*去除原來地方的物體*/setfillstyle(SOLID.FILL, color);bar (x-20,廠 10, x+20, y);void DrawFire (int x, int y, int n)/*

8、畫子彈,0 去除,1 顯示*/if(n=0)setfillstyle(SOLID.FILL BLUE);elsesetfillstyle(SOLID.FILL 0);setcolor(BLUE);fillellipse (x, y, 5, 5);void DrawAmyFire (int x, int y, int n)/*畫子彈,0 去除1 顯示*/if(n=0)setfillstyle(SOLID.FILL, BLUE);elsesetfillstyle(SOLID.FILL, YELLOW) ;/*敵人的炮彈是黃的*/setcolor(BLUE);fillellipse (x, y, 3

9、, 3);void PrScoreO/*輸出得分*/setfillstyle (SOLID.FILL, 8) ;/*把原來分?jǐn)?shù)去除*/bar (30,0, 200, 40);setcolor (11) ;/*輸出新得分*/settextstyle (0,0,2);sprintf(scorestr,score);outtextxy(30,20, scorestr);void GamePlay(void)/*具體玩游戲*/int i, j;setfillstyle(SOLID.FILL, BLUE);bar(0, 100, 640, 480);setfillstyle(SOLID.FILL, 8)

10、;bar(0, 0, 640, 99);play. x=200;play. y=99; /*玩家初始位置*/for(i=0;i6;i+)play. firei. start二0;/*開始的子彈都為沒發(fā)射狀態(tài)*/amyfireLi start二0;amyEi1辻e=0;play. life=l;DrawPlay 0 ;/*玩家初始位置*/PrScore 0 ;/*輸出得分*/randomize();while(l)for(i=0;i6;i+)/*查找玩家是否有發(fā)射的子彈*/辻(play. firei. start二二 1)/*發(fā)射的子彈*/DrawFire (play, f irei. x, p

11、lay. firei. y, 0) ;/*去除原來子彈位置*/ play firei y+=3;DrawFire (play. fireij. x, play. fireZi. y, 1) ;/*顯示新位置*/for (j二0 ;j(amyj x22)&play. fireLi x(amyj. y14)&play. firei. y480) /*子彈超出屏幕就等于消失*/play, fire Ci. start=0;DrawFire(play, fire Li, x,play.firei.y,0);for (i=0 ;i6; i+) /*敵人炮彈的產(chǎn)生*/if (amy i. life=l&a

12、my i. color14&amyfireiL start=0)/*敵人發(fā)射炮彈 的條件*/amyfirei. start=l;amyfirei. x二amyi. x;amyfirei. y=amyLil. y-10;for (i=0 ;i(play. xl4)&amyfireEi x(play. x+14)&(amyfireEil y+3X100)/*擊中玩家*/play. life二0;amyfirei start=0;DrawAmyFire(amyfireli x, amyfireLiZ y, 0);DrawBlack(play, x, play, y, 8) ;/*去除玩家*/brea

13、k;if (amyf ire i. y96) /*敵人炮彈超出海洋就消失*/amyfireEi start=0;setfillstyle(SOLID.FILL, 8);setcolor (8);fillellipse(amyfire Li x, amyfireLi y,3, 3);delay (speed) ;/*間隔時(shí)間可以口己定*/if (play. life!=l)/* 玩家被擊中 */break;for(i=0;i6;i+)if (amy il. life=0)/*出現(xiàn)一個(gè)敵人后就跳出循環(huán)*/11word版本可編輯歡迎下載支持.文檔從網(wǎng)絡(luò)中收集,已重新整理排版.word版本可編輯:歡迎

14、下載支持.amy i. color=rand()%4+10;/*敵人的顏色*/amyLi y=rand()%300+130;/*高度隨機(jī)*/amy i. speed=2+rand()%10;/*敵人的移動(dòng)速度隨機(jī)*/amyi. direction=rand()%2;/*敵人的移動(dòng)方向,0左邊,1右邊出來*/if (amyi directionO)amyi x=20;elseamyZi x=660;break;辻(GetKey (KEY_ESC) /* 退出鍵*/break;辻(GetKey (KEY.SPACE) /* 發(fā)射*/for(i=0;i6;i+)if (play. firei. st

15、art=0)/*發(fā)射一顆子彈后跳出循環(huán)*/play. firei x=play. x;play. firei.y=105;play. firei start=l;break;if (GetKey (KEY_RIGHT)&play. x20)/*左鍵的控制*/DrawBlack(play. x, play. y, 8);play. x=10;DrawPlay0;for (i=0; i660 amy i. x-20)/*敵人超出屏幕范圍就消失*/amyli life二0;if (play. life=0)/*被擊中失敗的話*/setcolor(6);settextstyle(0, 0,3);out

16、textxy(250, 40, GAME OVER);whiled)if(GetKey(KEY_ESC)/*結(jié)束游戲按 ESC*/1 lword版本可編輯歡迎下載支持.文檔從網(wǎng)絡(luò)中收集,已重新整理排版.word版本可編輯:歡迎下載支持.break;void CloseGraph(void)/*圖形結(jié)束*/ShutDonKeyboard ();closegraph();void far interrupt Newlnt9(void)unsigned char ScanCode, temp;ScanCode=inportb(0x60);temp=inportb (0x61);outportb(0x

17、61, temp 0x80);outportb(0x61, temp & 0x7f);if(ScanCode&0x80)ScanCode&二0x7f;key_state EScanCodel=0;elsekey_sta te EScanCodel =1; key_pressedScanCode=1;outportb(0x20,0x20);void InstallKeyboard(void)int i;for(i=0;i128;i+)ke5r_state i =key_pressed li =0;01dInt9Handler=getvect (9) ;/*中斷向量值*/setvect (9, Newlnt9) ;/*中斷程序Newlnt9 地址存入指定的中斷向量表中INT 09H*/void ShutDownKeyboard(void)setvect(9, 01dint9Handler);int GetKey(int ScanCode)int

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論