使用c语言写一个会动的小人
#include <>
#include <>
#include <> // 用于延时函数Sleep
void clear_screen() {
system("cls"); // 清空屏幕
}
void delay(int milliseconds) {
Sleep(milliseconds); // 延时函数
}
int main() {
int position = 0; // 小人的初始位置
while (1) {
clear_screen(); // 清空屏幕
// 绘制小人
printf(" ");
for (int i = 0; i < position; i++) {
printf(" ");
}
printf("O\n");
for (int i = 0; i < position; i++) {
printf(" ");
}
printf("/|\\\n");
for (int i = 0; i < position; i++) {
printf(" ");
}
printf("/ \\\n");
delay(100); // 延时100毫秒
position++; // 更新小人的位置
if (position >= 40) {
position = 0; // 小人到达屏幕边缘后回到起始位置
}
}
return 0;
}