C++++语言画一个机器人来回走动的待机动画
时间: 2023-05-18 10:05:27 浏览: 50
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
void gotoxy(int x, int y) {
COORD pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
int main() {
int x = 10, y = 10;
int direction = 1;
while (1) {
gotoxy(x, y);
printf(" O \n");
gotoxy(x, y + 1);
printf(" /|\\ \n");
gotoxy(x, y + 2);
printf(" / \\ \n");
Sleep(500);
gotoxy(x, y);
printf(" O \n");
gotoxy(x, y + 1);
printf(" /|\\ \n");
gotoxy(x, y + 2);
printf(" / \\ \n");
if (direction == 1) {
x++;
if (x == 70) {
direction = -1;
}
} else {
x--;
if (x == 10) {
direction = 1;
}
}
system("cls");
}
return 0;
}