C語言 雙人格鬥小遊戲 原始碼

2021-10-25 07:43:23 字數 3831 閱讀 2166

蕪湖

程式介紹:【c語言】實現雙人控制的戰鬥小遊戲

/*--------------------------------------

project: 雙人小遊戲

anthor: llz

操作 移動 逆、順時針旋轉 發射子彈

玩家1 4568 7 9 0

玩家2 adws q e 空格

--------------------------------*/

#include

#include

#include

#include

#define high 20

// 遊戲畫面尺寸

#define width 100

// 全域性變數

int position_x,position_y,p_x,p_y,turn_a,turn_b,num_a,num_b,num_max,life_a =

10,life_b =10;

// 飛機位置

int canvas[high]

[width]=;

// 二維陣列儲存遊戲畫布中對應的元素

// 0為空格,1為飛機*,2為子彈|,3為敵機@

int next[8]

[2]=

,,,,

,,,}

;//從右 右下 下 左下

int bullet_a[21]

[4];

int bullet_b[21]

[4];

//a b玩家子彈20發;

void

gotoxy

(int x,

int y)

//游標移動到(x,y)位置

void

startup()

// 資料初始化

void

show()

// 顯示畫面

if(canvas[i]

[j]==0)

printf

(" ");

// 輸出空格

else

if(canvas[i]

[j]==1)

printf

("n");

// 輸出飛機a

else

if(canvas[i]

[j]==2)

printf

("@");

// 輸出飛機b

else

if(canvas[i]

[j]==3)

printf

("o");

// 輸出子彈o

else

if(canvas[i]

[j]==4)

printf

("o");

// 輸出飛機a指向

else

if(canvas[i]

[j]==5)

printf

("o");

// 輸出飛機b指向

}printf

("\n");

}printf

("a:");

for( i =

1; i <=

10; i++)if

( i <= life_a)

printf

("■");

else

printf

(" ");

printf

("\nb: ");

for( i =

1; i <=

10; i++)if

( i <= life_b)

printf

("■");

else

printf

(" ");

}void

updatewithoutinput()

// 與使用者輸入無關的更新

else

if( bullet_a[i][3

]==0|| bullet_a[i][3

]== width -1)

if( bullet_b[i][2

]==0|| bullet_b[i][2

]== high -1)

else

if( bullet_b[i][3

]==0|| bullet_b[i][3

]== width -1)

canvas[ bullet_a[i][2

]][ bullet_a[i][3

]]=0

; canvas[ bullet_b[i][2

]][ bullet_b[i][3

]]=0

; bullet_a[i][2

]+= bullet_a[i][0

];bullet_a[i][3

]+= bullet_a[i][1

];bullet_b[i][2

]+= bullet_b[i][0

];bullet_b[i][3

]+= bullet_b[i][1

];canvas[ bullet_a[i][2

]][ bullet_a[i][3

]]=3

; canvas[ bullet_b[i][2

]][ bullet_b[i][3

]]=3

;}for(k=

1;k<=num_max;k++)}

if(((p_x==bullet_a[k][2

])&&(p_y==bullet_a[k][3

]))||

((p_x==bullet_b[k][2

])&&(p_y==bullet_b[k][3

])))

// 敵機撞到我機}}

}void

updatewithinput()

// 與使用者輸入有關的更新

else

if(input ==

'd'&& position_yelse

if(input ==

'w'&& position_x >1)

else

if(input ==

's'&& position_x < high -2)

else

if(input ==

' '&& num_a <=20)

// 發射子彈

else

if(input ==

'q')

// 炮彈換方向

else

if(input ==

'e')

// 炮彈換方向

else

if(input ==

'4'&& position_y>1)

else

if(input ==

'6'&& p_yelse

if(input ==

'8'&& p_x >1)

else

if(input ==

'5'&& p_x < high -2)

else

if(input ==

'0'&& num_b <=20)

// 發射子彈

else

if(input ==

'7')

// 炮彈換方向

else

if(input ==

'9')

// 炮彈換方向 }}

intmain()

return0;

}

c語言遊戲原始碼 C語言打字遊戲原始碼

到大街上,還是會羨慕那些情侶,但是依然相信舔狗一無所有,渣男滿載而歸。網易雲熱評 include include include include define max 51 第一測試字母的最大長度void help void start char str str max 1 0 給字串最後加上結束符...

c 推箱子小遊戲原始碼

include using namespace std 地圖資料 int map 10 10 重新整理介面 void show 人物移動 void mov string direction 座標類 struct sxy xy 獲取座標 sxy getxy 是否結束遊戲 bool isgameover...

C 雙人槍戰小遊戲(案列修改)

原案列 修改後 include include include include pragma warning disable 4996 using namespace std int siz 20 handle hout getstdhandle std output handle coord co...