#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int width;
int high;
int ball_x;
int ball_y;
int ball_vx;
int ball_vy;
void startup() {
width = 20;
high = 10;
ball_x = 0;
ball_y = width / 2;
ball_vx = 1;
ball_vy = 1;
}
void show()
{
int j;
int i;
system("cls");
for (i = 0; i <= high; i++) {
for (j = 0; j <= width; j++) {
if (i == ball_x && j == ball_y)
printf("G");
else if (j == width)
printf("|");
else if (i == high)
printf("-");
else
printf(" ");
}
printf("\n");
}
Sleep(500);
}
void update()
{
ball_x += ball_vx;
ball_y += ball_vy;
if (ball_x == high || ball_x == 0)
ball_vx = -ball_vx;
if (ball_y == width || ball_y == 0)
ball_vy = -ball_vy;
}
int main()
{
startup();
while (1) {
show();
update();
}
}
简单的弹弹墙小游戏
最新推荐文章于 2021-06-10 03:16:59 发布