switch (direction) {
case 'W':
case 'w':
if (map[perosnX-1][personY]==' ') {
temp=map[perosnX-1][personY];
map[perosnX-1][personY]=map[perosnX][personY];
map[perosnX][personY]=temp;
perosnX--;
}else if (map[perosnX-1][personY]==map[boxX][boxY]&&map[boxX-1][boxY]==' ')
{
temp=map[boxX][boxY];
map[boxX][boxY]=map[perosnX][personY];
map[perosnX][personY]=' ';
map[boxX-1][boxY]=temp;
perosnX--,boxX--;
}
break;
case 'S':
case 's':
if (map[perosnX+1][personY]==' ') {
temp=map[perosnX+1][personY];
map[perosnX+1][personY]=map[perosnX][personY];
map[perosnX][personY]=temp;
perosnX++;
}else if (map[perosnX+1][personY]==map[boxX][boxY]&&map[boxX+1][boxY]==' ')
{
temp=map[boxX][boxY];
map[boxX][boxY]=map[perosnX][personY];
map[perosnX][personY]=' ';
map[boxX+1][boxY]=temp;
perosnX++,boxX++;
}
break;
case 'A':
case 'a':
if (map[perosnX][personY-1]==' ') {
temp=map[perosnX][personY-1];
map[perosnX][personY-1]=map[perosnX][personY];
map[perosnX][personY]=temp;
personY--;
}else if (map[perosnX][personY-1]==map[boxX][boxY]&&map[boxX][boxY-1]==' ')
{
temp=map[boxX][boxY];
map[boxX][boxY]=map[perosnX][personY];
map[perosnX][personY]=' ';
map[boxX][boxY-1]=temp;
personY--,boxY--;
}
break;
case 'D':
case 'd':
if (map[perosnX][personY+1]==' ') {
temp=map[perosnX][personY+1];
map[perosnX][personY+1]=map[perosnX][personY];
map[perosnX][personY]=temp;
personY++;
}else if (map[perosnX][personY+1]==map[boxX][boxY]&&map[boxX][boxY+1]==' ')
{
temp=map[boxX][boxY];
map[boxX][boxY]=map[perosnX][personY];
map[perosnX][personY]=' ';
map[boxX][boxY+1]=temp;
personY++,boxY++;
}
break;
case 'Q':
case 'q':
return 0;
default:
break;
} |
|