#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
int main()
{
int i, j;
int x = 0;
int y = 5; //小球的坐标
int v_x = 1;
int v_y = 1;//小球每次移动的单位
int left = 0;
int right = 10;
int top = 0;
int bottom = 10;//界面的大小
while (1)
{
x = x + v_x;
y = y + v_y;
system("cls");//清屏函数
for (i = 0; i < x; i++)
printf("\n");
for (j = 0; j < y; j++)
printf(" ");
printf("o");
printf("\n");
Sleep(500);
if ((x == top) || (x == bottom))
{
printf("\a");//这个函数是碰到就会发出声音
v_x = -v_x;//若小球碰到边界,将移动的单位变为负的,就可以反弹回去
}
if ((y == left) || (y == right))
v_y = -v_y;//同上
}
system("pause");
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main(void)
{
int i, j;
int x = 10;
int y = 20;
char input;
while (1)
{
system("cls");
for (i = 0; i < x; i++)
printf("\n");
for (j = 0; j < y; j++)
printf(" ");
printf(" *\n");
for (j = 0; j < y; j++)
printf(" ");
printf("*****\n");
for (j = 0; j < y; j++)
printf(" ");
printf(" * *\n");
if (_kbhit())
{
input = getchar();
if (input == 'a')
y--;
if (input == 's')
x++;
if (input == 'd')
y++;
if (input == 'w')
x--;
}
}
return 0;
}