怎样用一维数组做啊
aide吧
全部回复
仅看楼主
level 2
平凡平淡Z 楼主
#include <iostream>
using namespace std;
#include <conio.h> //console io
int main()
{
//定义了一个地图数组
char arr[11][11]={
1,1,1,1,1,1,1,1,1,1,1,
1,1,2,1,1,1,1,1,1,1,1,
1,1,2,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,
1,1,1,2,1,0,1,1,2,1,1,
1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1
};
int posx=5;
int posy=5;
while(true)
{
system("cls");
for (int i=0;i<11;i++)
{
for (int j=0;j<11;j++)
{
if (arr[i][j]==1)
{
cout<<"□";
}else if (arr[i][j]==0)
{
cout<<"★";
}else if (arr[i][j]==2)
{
cout<<"■";
}
}
cout<<endl;
}
int tp;
//cin>>tp;
tp=_getch();//从键盘上获取一个按键字符,要使用此命令请包涵 <conio.h> 头文件
int tx=posx,ty=posy;
switch (tp)
{
case 'w':
case 'W':
ty=posy-1;
break;
case 's':
case 'S':
ty=posy+1;
break;
case 'A':
case 'a':
tx=posx-1;
break;
case 'D':
case 'd':
tx=posx+1;
break;
}
if (tx>=0&&tx<11&&ty>=0&&ty<11&& arr[ty][tx]==1)
{
arr[posy][posx]=1;
posx=tx;posy=ty;
arr[ty][tx]=0;
}
}
system("pause");
return 0;
}
2017年10月19日 15点10分 1
level 13
你定义了一个二维数组,但数据却是一维数组
2017年10月19日 23点10分 2
1