#include<iostream>
#define N 10
using namespace std;
void init(int(*p)[N]);
void show(int(*a)[N]);
void move(int arr[N][N]);
int arr[N][N] = { 0 };
void init(int (*p)[N]) {
*(*(p + 0) + 0) = 1;
}
void show(int (*a)[N])
{
for (size_t i = 0; i < N; i++)
{
for (size_t j = 0; j < N; j++)
{
cout << *(*(a + i) + j) << " ";
}
cout << endl;
}
}
void move(int arr[N][N]) {
int imove = 0;
int jmove = 0;
int temp;
char keybord_input;
while (true)
{
if (imove==N-1&&jmove==N-1)
{
show(arr);
cout << "出来了,哈哈哈哈!" << endl;
break;
}
else
{
cin >> keybord_input;
switch (keybord_input)
{
case 'a':
if (jmove - 1 >= 0)
{
temp = arr[imove][jmove];
arr[imove][jmove] = arr[imove][jmove - 1];
arr[imove][jmove - 1] = temp;
jmove--;
}
break;
case 's':
if (imove + 1 <N)
{
temp = arr[imove][jmove];
arr[imove][jmove] = arr[imove + 1][jmove];
arr[imove + 1][jmove] = temp;
imove++;
}
break;
case 'd':
if (jmove + 1 < N)
{
temp = arr[imove][jmove];
arr[imove][jmove] = arr[imove][jmove + 1];
arr[imove][jmove + 1] = temp;
jmove++;
}
break;
case 'w':
if (imove - 1 >= 0)
{
temp = arr[imove][jmove];
arr[imove][jmove] = arr[imove - 1][jmove];
arr[imove - 1][jmove] = temp;
imove--;
}
break;
default:
cout << "输入无效,请重新输入" << endl;
break;
}
show(arr);
}
}
}
int main(int argc, char *argv[])
{
init(arr);
show(arr);
move(arr);
system("pause");
return 0;
}
走迷宫手动无障碍版
猜你喜欢
转载自blog.csdn.net/haku_yyf/article/details/79505127
今日推荐
周排行