1 Star 0 Fork 0

維克多 / Cpp Course

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ball.cpp 1.89 KB
一键复制 编辑 原始数据 按行查看 历史
維克多 提交于 2020-10-15 23:28 . add ball.cpp.
#include<stdio.h>
#include<stdlib.h> //system("cls");
#include<windows.h> //Sleep(50)
int main() {
int i, j;
int x = 2, y = 2;
int velocity_x = 1;
int velocity_y = 1;
int top = 0; //x上边界
int bottom = 24 - 3; //x下边界
int left = 0; //y左边界
int right = 80 - 2; //y右边界
while (1) { //每运行一次输出一个静态图像
//通过变换由x,y表示小球o的的位置,每次输出不一样的图像,形成动画
if (x == top || x == bottom) //遇见边界,速度方向掉头
velocity_x = -velocity_x;
if (y == left || y == right) //遇见边界,速度方向掉头
velocity_y = -velocity_y;
x += velocity_x; //小球位置:多少回车
y += velocity_y; //小球位置:多少空格
system("cls"); //清屏
for (i = 1; i <= x; i++) { //循环完x个回车
if (i == 1) {
printf("----------------------------------------\
---------------------------------------");
putchar('\n');
}
else {
printf("| \
|");
putchar('\n');
}
}
for (j = 1; j <= y; j++) { //循环完y个空格
if (j == 1) {
putchar('|');
}
else
putchar(' ');
}
putchar('o'); //输出指定位置的形状‘O ’
for (i = y + 1; i <= right; i++) { //循环完o之后的个空格
if (i == right) {
putchar('|');
}
else
putchar(' ');
}
putchar('\n');
for (i = x + 1; i <= bottom; i++) { //循环完o之后的回车
if (i == bottom) {
printf("----------------------------------------\
---------------------------------------");
putchar('\n');
}
else
printf("| \
|");
putchar('\n');
}
Sleep(50); //让速度慢下来,数值越大,小球运动越慢。
}
return 0;
}
C++
1
https://gitee.com/ggfvictor/cpp-course.git
git@gitee.com:ggfvictor/cpp-course.git
ggfvictor
cpp-course
Cpp Course
master

搜索帮助