绕圈跑,有点类似贪吃蛇问题
//程序做什么,运行一下就知道了,问题是我想他是一个挨着一个移动,不是两个中间隔个空格,想了好长时间,实在无奈#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
int main()
{
char face[30][30];
for (int i = 0; i < 30; i++) //初始化界面
{
for (int j = 0; j < 30; j++)
{
if (i == 0 || i == 29 || j == 0 || j == 29)
face[i][j] = '#';
else
face[i][j] = ' ';
if (i>10 && j == 28 && i != 29) face[i][j] = '*';
printf("%c", face[i][j]);
}
printf("\n");
}
while (1)
{
for (int i = 0; i < 30; i++)
{
for (int j = 0; j < 30; j++)
{
if (face[i][j] == '*')
{
if (face[1][1] == '*') { system("pause"); exit(0); }
else{
if (i == 1 && j % 2 == 0){ face[i][j - 1] = '*'; face[i][j] = ' '; }
else{
if (i == 28 && j % 2 == 1){ face[i][j - 1] = '*'; face[i][j] = ' '; }
else{
if (j % 2 == 0) { face[i - 1][j] = '*'; face[i][j] = ' '; }
else{
if (j % 2 == 1) { face[i + 1][j] = '*'; face[i][j] = ' '; i = i + 1; }
}
}
}
}
}
}
}
for (int i = 0; i < 30; i++)
{
for (int j = 0; j < 30; j++)
printf("%c", face[i][j]);
printf("\n");
}
Sleep(10);
system("cls");
}
getchar();
}