Boa tarde, estou fazendo um jogo de labirinto em C mas estou tendo dificuldade para colocar limitações para quando entrar em uma parede "|" aparece a msg game over, ou para quando chegar no final "$" e acabar o jogo.
o codigo é este abaixo:
#include <stdio.h>
#include <ncurses.h>
#include <unistd.h>
#include <string.h>
#define lin 13
#define col 100
char mapa[lin][col];
int x=1, y=1;
void imprimir_mapa(int x, int y)
{
int i, j, mini, minj, maxi, maxj;
mini = x-3;
if(mini < 0)
{
mini=0;
}
minj = y-3;
if(minj < 0)
{
minj=0;
}
maxi = x+3;
if(maxi > 12)
{
maxi=12;
}
maxj = y+3;
if(maxj > 99)
{
maxj=99;
}
for(i=mini;i<maxi;i++)
{
for(j=minj;j<maxj;j++)
{
mvprintw(i, j, "%c", mapa[i][j]);
}
}
}
void ler_movimento()
{
char p;
p = getch();
//armazena posicao atual em variaveis temporarias (x, y)
if(p=='s')
{
x++;
}
if(p=='d')
{
y++;
}
if(p=='a')
{
y--;
}
if(p=='w')
{
x--;
}
if(mapa[x][y]=='|')
{
printw("GAME OVER"); //volta a posicao temp
}
if(mapa[x][y]=='$')
{
printw("PARABÉNS voce CHEGOU O FINAL DO LABIRINTO");
}
}
int main()
{
char p;
strcpy(mapa[0], "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
strcpy(mapa[1], "| || |||||||||||||||||||||||||||||||||||||||||||| |");
strcpy(mapa[2], "| || ||||||||||||| ||||||||||| |||||||||||||||||||| ||||||||");
strcpy(mapa[3], "| |||||||| ||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||| |||||||||| ||||||||");
strcpy(mapa[4], "|||| |||| |||||||| ||||||||||| ||||| |||||||| |||||||||| |");
strcpy(mapa[5], "|||| |||| |||||||| ||||||||||| |||||||||| |||||||||| ||||||||||||| |||||||||||| |||||||||| ||||||||");
strcpy(mapa[6], "|||| |||||||| ||||||||||| |||||||||| |||||||||| ||||||||||||| |||||||||||| |");
strcpy(mapa[7], "|||||||||||||||||| |||||| ||||| ||||||||||||| ||||||||||||||||||||||||||||||||");
strcpy(mapa[8], "||||||| ||||||||||||||||||||||||||||||||| ||||||||| |||||");
strcpy(mapa[9], "||||||| |||||||||||||||| ||||||||||| ||||||||||||||||||||||||||||||||||| ||||||||||");
strcpy(mapa[10], "||||||| |||||||||||||||| ||||||||||||||| ||||||||||| ||||||||||||| ||||||||||");
strcpy(mapa[11], "||||| ||||||||| |||||||||||||||||$||||||||||||||||| ||||||||||");
strcpy(mapa[12], "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
initscr();
while(1)
{
clear();
imprimir_mapa(x, y);
mvprintw(x,y,"O");
refresh();
ler_movimento();
usleep(50000);
}
endwin();
return 0;
}
Se alguem souber o que estou fazendo de errado e puder me avisar eu serei grato!