69,372
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
void main()
{
char *c = "☆";
char *b = "★";
char *space = " ";
int x = 0;
int y = 0;
int oldx = 0;
int oldy = 0;
COORD pos = {0, 0};
// SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
for(int j=0; j<4; j++)
{
for(int i=0; i<10; i++)
{
if(j == 0 || j == 3)
printf("%s", c);
else if(i == 0 || i == 9)
printf("%s", c);
else
printf("%s", space);
}
printf("\n");
}
while(true)
{
COORD icoord = {oldx, oldy};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), icoord);
printf("%s", c);
icoord.X = x;
icoord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), icoord);
printf("%s", b);
oldx = x;
oldy = y;
switch (x)
{
case 0:
if( y != 0)
y--;
else
x += 2;
break;
case 18:
if( y == 3)
x -= 2;
if( y <= 2)
y++;
break;
default:
if(y == 3)
x -= 2;
if(y == 0)
x += 2;
}
Sleep(100);
}
}