最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

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

第一次用C語言寫的小游戲

2023-07-15 00:31 作者:testuniversity  | 我要投稿

#include<graphics.h>

#include<conio.h>

#include<stdio.h>

int main()

{

float width, height, gravity;

float ball_x, ball_y, ball_vy, radius;

float rect_left_x, rect_top_y, rect_width, rect_height,rect_vx;

int score = 0;


width = 600;

height = 400;

gravity = 0.6;

initgraph(width, height);

radius = 20;

ball_x = width / 4;

ball_y = height - radius;

ball_vy = 0;


rect_height = 100;

rect_width = 20;

rect_left_x = width * 3 / 4;

rect_top_y = height - rect_height;

rect_vx = -3;


while (1)

{

if (_kbhit())

{

char input = _getch();

if (input == ' ')

{

ball_vy = -17;

}

}


ball_vy = ball_vy + gravity;

ball_y = ball_y + ball_vy;

if (ball_y >= height - radius)

{

ball_vy = 0;

ball_y = height - radius;

}


rect_left_x = rect_left_x + rect_vx;

if (rect_left_x <= 0)

{

rect_left_x = width;

score = score + 1;

rect_height = rand() % int(height / 4) + height / 4;

rect_vx = rand() / float(RAND_MAX) * 4 - 7;

}


if ((rect_left_x <= ball_x + radius)

&& (rect_left_x + rect_width >= ball_x - radius)

&& (height - rect_height <= ball_y + radius))

{

Sleep(100);

score = 0;

}


cleardevice();

fillcircle(ball_x, ball_y, radius);


fillrectangle(rect_left_x, height - rect_height, rect_left_x +

rect_width, height);

TCHAR s[20];

_stprintf(s, _T("%d"), score);

settextstyle(40, 0, _T("宋體"));

outtextxy(50, 30, s);

Sleep(10);

}

closegraph();

return 0;

}

第一次用C語言寫的小游戲的評論 (共 條)

分享到微博請遵守國家法律
台东县| 同仁县| 太仓市| 福安市| 商南县| 来安县| 镇沅| 乌拉特中旗| 苍南县| 北流市| 三江| 武平县| 尖扎县| 江城| 天津市| 穆棱市| 南昌县| 保康县| 桂阳县| 增城市| 德庆县| 自贡市| 安乡县| 长沙县| 华安县| 扬中市| 肇州县| 金溪县| 宁海县| 青阳县| 宜兴市| 文安县| 礼泉县| 永兴县| 翁源县| 溆浦县| 石门县| 新余市| 新绛县| 简阳市| 庐江县|