Ok.....
I will help one more time. Anything more than this and I might as well write the program for you.
Just for kicks you can alter the structure approach I used and instead use bit masks to represent directions.
Code:
#define DIR_NORTH 0x01
#define DIR_SOUTH 0x02
#define DIR_EAST 0x04
#define DIR_WEST 0x08
#define DIR_ALL (NORTH) | (SOUTH) | (EAST) | (WEST)
And just in case your teacher wont let you use bit masks you can look at this map in memory and use a different approach.
1 1 1 1 1 1 1 1 1 1 1 1
1 0 1 0 0 0 0 0 0 0 0 0
1 0 1 0 0 0 0 0 0 0 0 1
1 2 1 1 1 1 0 1 1 1 1 1
1 0 0 0 0 1 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1
0 = empty
1 = wall
2 = player position
Code:
#define PLAYER_PIECE 0x02
....
int offset=iMapWidth+2;
int x=0,y=0;
for (int i=1;i<iMapHeight-2;i+=2)
{
for (int j=1;j<iMapWidth-2;j+=2)
{
int offsetLeft=offset-1;
int offsetUp=offset-iMapWidth;
int offsetDown=offset+iMapWidth;
int offsetRight=offset+1;
if (Map[offsetLeft]) DrawLine(x,y,x,y+iCellSize);
if (Map[offsetRight) DrawLine(x+iCellSize,y,x+iCellSize,y+iCellSize);
if (Map[offsetUp)) DrawLine(x,y,x+iCellSize,y);
if (Map[offsetDown) DrawLine(x,y+iCellSize,x+iCellSize,y+iCellSize);
if (Map[offset]==PLAYER_PIECE) DrawCircle(x,y,iCellSize/2);
x+=iCellSize;
}
x=0;
y+=iCellSize;
}
...
You could use both methods and use the above routine to instead use bitwise operations to compute the directions and save them in another map. Then it would be easier to check for directions.
Code:
bool MoveLeft(int px,int py,int iMapWidth,int &outOffset)
{
//Bail on error
if ((px-1)<1) return true;
int offset=py*iMapWidth_px;
if ((DirectionMap[offset-1] & DIR_EAST) == DIR_EAST)
{
return true; //Cannot move here
}
else outOffset=offset-1;
return false;
}
No matter what limits your teacher puts on the project, I could code this. It would just be uglier and less efficient the more tools they took away from me.
So stick it to your teacher and code this using several methods. Make it look easy.