五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

c語(yǔ)言飛機(jī)游戲

2023-03-06 16:08 作者:李氵青水  | 我要投稿

#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

#include <windows.h>


// 全局變量

int position_x,position_y; // 飛機(jī)位置

int bullet_x,bullet_y; // 子彈位置

int enemy_x,enemy_y; // 敵機(jī)位置

int high,width; //? 游戲畫(huà)面尺寸

int score; // 得分

int blood; //生命值


void gotoxy(int x,int y)? //光標(biāo)移動(dòng)到(x,y)位置

{

? ? HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);

? ? COORD pos;

? ? pos.X = x;

? ? pos.Y = y;

? ? SetConsoleCursorPosition(handle,pos);

}


void HideCursor() // 用于隱藏光標(biāo)

{

CONSOLE_CURSOR_INFO cursor_info = {1, 0};? // 第二個(gè)值為0表示隱藏光標(biāo)

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);

}



void startup() // 數(shù)據(jù)初始化

{

high = 20;

width = 30;

position_x = high/2;

position_y = width/2;

bullet_x = -2;

bullet_y = position_y;

enemy_x = 0;

enemy_y = position_y;

score = 0;

blood = 3;


HideCursor(); // 隱藏光標(biāo)

}


void show()? // 顯示畫(huà)面

{

gotoxy(0,0);? // 光標(biāo)移動(dòng)到原點(diǎn)位置,以下重畫(huà)清屏

int i,j;

for (i=0;i<high;i++)

{

for (j=0;j<width;j++)

{

if ((i==position_x) && (j==position_y))

printf("*");? //? ?輸出飛機(jī)*

else if ((i==enemy_x) && (j==enemy_y))

printf("@");? //? ?輸出敵機(jī)@

else if ((i==bullet_x) && (j==bullet_y))

printf("|");? //? ?輸出子彈|

else

printf(" ");? //? ?輸出空格

}

printf("\n");

}

printf("得分:%d\n",score);

printf("生命值:%d\n",blood);

}


void updateWithoutInput()? // 與用戶輸入無(wú)關(guān)的更新

{

if (bullet_x>-1)

bullet_x--;?

if ((bullet_x==enemy_x) && (bullet_y==enemy_y))? // 子彈擊中敵機(jī)

{

score++;? ? ? ? ? ? ? ? // 分?jǐn)?shù)加1

enemy_x = -1;? ? ? ? ? ?// 產(chǎn)生新的飛機(jī)

enemy_y = rand()%width;

bullet_x = -2;? ? ? ? ? // 子彈無(wú)效

}

if (enemy_x>high)? ?// 敵機(jī)跑出顯示屏幕

{

enemy_x = -1;? ? ? ? ? ?// 產(chǎn)生新的飛機(jī)

enemy_y = rand()%width;

}

// 用來(lái)控制敵機(jī)向下移動(dòng)的速度。每隔幾次循環(huán),才移動(dòng)一次敵機(jī)

// 這樣修改的話,用戶按鍵交互速度還是保持很快,但我們NPC的移動(dòng)顯示可以降速

static int speed = 0;??

if (speed<20)

speed++;

if (speed == 20)

{

enemy_x++;

if ((enemy_x==position_x) && (enemy_y==position_y))? // 敵機(jī)撞擊飛機(jī)

{

blood--;? ?// 生命值減1

if (blood<0)

exit(0);

}

speed = 0;

}

}


void updateWithInput()? // 與用戶輸入有關(guān)的更新

{

char input;

if(kbhit())? // 判斷是否有輸入

{

input = getch();? // 根據(jù)用戶的不同輸入來(lái)移動(dòng),不必輸入回車

if (input == 'a')? ?

position_y--;? // 位置左移

if (input == 'd')

position_y++;? // 位置右移

if (input == 'w')

position_x--;? // 位置上移

if (input == 's')

position_x++;? // 位置下移

if (input == ' ')? // 發(fā)射子彈

{

bullet_x = position_x-1;? // 發(fā)射子彈的初始位置在飛機(jī)的正上方

bullet_y = position_y;

}

}

}


int main()

{

startup();? // 數(shù)據(jù)初始化

while (1) //? 游戲循環(huán)執(zhí)行

{

show();? // 顯示畫(huà)面

updateWithoutInput();? // 與用戶輸入無(wú)關(guān)的更新

updateWithInput();? // 與用戶輸入有關(guān)的更新

}

return 0;

}


c語(yǔ)言飛機(jī)游戲的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
福州市| 内江市| 孟村| 合肥市| 施秉县| 金平| 基隆市| 蒙山县| 洱源县| 顺平县| 玉门市| 东兰县| 黄平县| 柏乡县| 临沧市| 宕昌县| 洞口县| 桂东县| 漯河市| 咸宁市| 台前县| 开封市| 长乐市| 慈利县| 阳东县| 湛江市| 三门峡市| 镇平县| 七台河市| 乌兰察布市| 高密市| 宜黄县| 襄汾县| 杭州市| 新绛县| 延寿县| 通州区| 安徽省| 海南省| 招远市| 色达县|