I have been making a game to walk through mazes and solve them for a college project.
I have been trying to make my character move and, oddly it was working perfectly for like 20 minutes with the character moving and the steps counting. After that, it just stopped working and the code was the same. Was it a problem with the compiler (DEV C++) or the code is faulty?
W, A, S, D is for moving but everytime i press one, the character does not move and just spams steps: 0 for every click.
What I have tried:
The main part (player is a ascii character; ex/ey are the coordinates of the entrance; sx/sy are the coordinates of the end) :
steps=0;
do
{
do
{
key=getch();
printf("steps: %d", steps);
if(key=='w')
{
steps+=1;
if(*(lab+pointerpoint(ex, ey-2))==track)
{
system("cls");
*(lab+pointerpoint(ex, ey))=track;
*(lab+pointerpoint(ex, ey-2))=player;
printlab();
}
else
{
steps-=1;
continue;
}
}
if(key=='s')
{
steps+=1;
if(*(lab+pointerpoint(ex, ey+2))==track)
{
system("cls");
*(lab+pointerpoint(ex, ey))=track;
*(lab+pointerpoint(ex, ey+2))=player;
printlab();
}
else
{
steps-=1;
continue;
}
}
if(key=='a')
{
steps+=1;
if(*(lab+pointerpoint(ex-2, ey))==track)
{
system("cls");
*(lab+pointerpoint(ex, ey))=track;
*(lab+pointerpoint(ex-2, ey))=player;
printlab();
}
else
{
steps-=1;
continue;
}
}
if(key=='d')
{
steps+=1;
if(*(lab+pointerpoint(ex+1, ey))==track)
{
system("cls");
*(lab+pointerpoint(ex, ey))=track;
*(lab+pointerpoint(ex+2, ey))=player;
printlab();
}
else
{
steps-=1;
continue;
}
}
} while( *(lab+pointerpoint(ex, ey)) != *(lab+pointerpoint(sx, sy)) );
} while(key!='q');
void labgen(int x, int y)
{
if(N%2==0)
N++;
sx=N-1;
sy=N;
maze = (char *)malloc(sizeof(char)*N*N+sizeof(char));
*(maze+pointerpoint(N, N)+1)='\0';
int i=0;
for( ; i<N*N ; i++)
{
*(maze+i)=wall;
}
*(lab+pointerpoint(ex, ey))=player;
*(lab+pointerpoint(ex, ey+1))=track;
*(lab+pointerpoint(sx, sy))=track;
nextblock(ex, ey+1);
}
char point(int x, int y)
{
if(x<1||y<1||x>N||y>N) return '0';
int point = N*(y-1)+x -1;
return *(lab+point);
}
int pointerpoint(int x, int y)
{
int point = N*(y-1)+x -1;
return point;
}