C語言實現飛機大戰遊戲Demo

2021-10-24 01:53:20 字數 2896 閱讀 3875

o表示玩家,w表示敵機

檔案

#ifndef console_h

#define console_h

//游標跳轉到指定位置

void

gotoxy

(int x,

int y)

; handle hout =

getstdhandle

(std_output_handle)

;// 獲取標準輸出裝置控制代碼

setconsolecursorposition

(hout, pos)

;//兩個引數分別是指定哪個窗體,具體位置

}//隱藏游標

void

hidecursor()

#endif

檔案

#include

#include

#include

#include

#include

"console.h"

/*常量定義*/

//上邊界

#define up 0

//下邊界

#define down 15

//左邊界

#define left 0

//右邊界

#define right 20

//飛機代號

#define plane 'o'

//敵機

#define enemy 'w'

//子彈代號

#define bullet '*'

//牆壁

#define wall '#'

//規定用時

#define time 20

/*結構體建立*/

//飛機結構

typedef

struct plane

plane;

//子彈結構

typedef

struct bullet

bullet;

/*全域性變數*/

//飛機

plane plane;

//敵方飛機

plane enemy;

//子彈

bullet bullet;

//得分

int score;

//是否繼續遊戲

int proceed;

//生命

int life;

//計時器

clock_t tstart,tend;

/*控制函式*/

//初始化函式

void

startup()

;//列印地圖函式

void

printmap()

;//與使用者操作無關的更新

void

updatewithoutplayer()

;//與使用者操作有關的更新

void

updatewithplayer()

;int

main()

return0;

}//初始化函式

void

startup()

//列印地圖函式

void

printmap()

else

if(i==plane.x&&j==plane.y)

else

if(i==bullet.x&&j==bullet.y)

else

if(i==enemy.x&&j==enemy.y)

else

}printf

("\n");

}printf

(,score,life,

(int

)(time-

(tend-tstart)

/clk_tck));

hidecursor()

;}//與使用者操作無關的更新

void

updatewithoutplayer()

}//敵機自動下落

if(enemy.x

else

if(enemy.x==plane.x&&enemy.y==plane.y)}}

else

//判斷是否超時

tend=

clock()

;if((tend-tstart)

/clk_tck>=time)

}//與使用者操作有關的更新

void

updatewithplayer()

break

;case

'q':

case

'q':

proceed=0;

break

;case

'a':

case

'a':

if(plane.y>left+1)

break

;case

'd':

case

'd':

if(plane.y

break

;case

'w':

case

'w':

if(plane.x>up+1)

break

;case

's':

case

's':

if(plane.x

break

;default

:break;}

}}

本程式設計時分了兩檔案,乙個是control.h,主要用來設計游標的控制函式,乙個是執行程式檔案plane.c。

C語言實現簡單的飛機大戰

定義四個函式實現飛機大戰 include include include 定義全域性變數 int high,width 定義邊界 int position x,position y 飛機位置 int bullet x,bullet y 子彈位置 int enemy x,enemy y int sco...

C語言之飛機大戰遊戲

技術原型 1 void gotoxy int x,int y 函式,該函式可以使游標去到 x,y 的位置進行列印 2 鍊錶,用於儲存狀態 3 windows.h中有非阻塞輸入,kbhit 4 隨機生成數 5 視覺暫留 6 碰撞檢測 7 清屏函式 8 設定邊界 技術路線 1 設定乙個邊界 2 維護乙個...

C語言版飛機大戰遊戲

c語言版飛機大戰,供大家參考,具體內容如下 不多說直接上 include include include include include using namespace std all the structures typedef struct frame frame all the functio...