1 Star 0 Fork 0

Plan-B/我的仓库

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
shuangrenfantan1.0.cpp 1.60 KB
一键复制 编辑 原始数据 按行查看 历史
Plan-B 提交于 2019-06-24 12:16 . 双人反弹1.0
#include <conio.h>
#include <graphics.h>
#define High 480 // 游戏画面尺寸
#define Width 640
// 全局变量
int ball1_x,ball1_y; // 小球的坐标
int ball2_x,ball2_y; // 小球的速度
int radius; // 小球的半径
void startup() // 数据初始化
{
ball1_x = Width/3;
ball1_y = High/3;
ball2_x = Width*2/3;
ball2_y = High*2/3;
radius = 20;
initgraph(Width,High);
BeginBatchDraw();
}
void clean() // 消除画面
{
setcolor(BLACK);
setfillcolor(BLACK);
fillcircle(ball1_x, ball1_y, radius);
fillcircle(ball2_x, ball2_y, radius);
}
void show() // 显示画面
{
setcolor(GREEN);
setfillcolor(GREEN);
fillcircle(ball1_x, ball1_y, radius); // 绘制绿圆
setcolor(RED);
setfillcolor(RED);
fillcircle(ball2_x, ball2_y, radius); // 绘制绿圆
FlushBatchDraw();
// 延时
Sleep(3);
}
void updateWithoutInput() // 与用户输入无关的更新
{
}
void updateWithInput() // 与用户输入有关的更新
{
char input;
if (kbhit())
{
input = getch();
int step = 10;
if (input == 'a')
ball1_x-=step;
if (input == 'd')
ball1_x+=step;
if (input == 'w')
ball1_y-=step;
if (input == 's')
ball1_y+=step;
if (input == '4')
ball2_x-=step;
if (input == '6')
ball2_x-=step;
if (input == '8')
ball2_y-=step;
if (input == '5')
ball2_y+=step;
}
}
void gameover()
{
EndBatchDraw();
closegraph();
}
int main()
{
startup(); // 数据初始化
while (1) // 游戏循环执行
{
clean(); // 把之前绘制的内容取消
updateWithoutInput(); // 与用户输入无关的更新
updateWithInput(); // 与用户输入有关的更新
show(); // 显示新画面
}
gameover(); // 游戏结束、后续处理
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/songguanhao/laozis_warehouse.git
git@gitee.com:songguanhao/laozis_warehouse.git
songguanhao
laozis_warehouse
我的仓库
master

搜索帮助

Cb406eda 1850385 E526c682 1850385