#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
int main()
{
int i,j;
int n=0;
int x=0;
int y=5;
int velocity_x=1;
int velocity_y=1;
int top=0;
int bottom=10;
int left=0;
int right=20;
while(1)
{
x=x+velocity_x;
y=y+velocity_y;
system("cls");
for(i=0;i<x;i++)
printf("\n");
for(j=0;j<y;j++)
printf(" ");
printf("o\n");
for(n=0;n<=2000000;n++)
if((x==top)||(x==bottom))
velocity_x=-velocity_x;
if((y==left)||(y==right))
velocity_y=-velocity_y;
if((x==top)||(x==bottom)||(y==left)||(y==right))
{
Beep(500,500);
printf("\a");
}
}
return 0;
}
用打印语句,输出横线和竖线
这样的话要用graphics图形库了,贪吃蛇游戏实现:https://edu.csdn.net/course/detail/2766
可以用EasyX图形库,到这里https://easyx.cn安装下载,很好用。