Ho scritto qualche riga di codice, magari puoi prendere qualche spunto:
#include <stdio.h>
#include <string.h>
#include <windows.h>
#define GIALLO 14
#define ROSSO 12
#define DEFAULT 7
#define B 254 // CARATTERE "BLOCCO"
#define V 179 // CARATTERE "|"
#define O 45 // CARATTERE "-"
#define D 47 // CARATTERE "/"
#define S 92 // CARATTERE "\"
#define X 120 // CARATTERE "x"
#define M 6
#define N 18
typedef struct stanza_
{
char *nome;
unsigned int i;
unsigned int j;
} stanza;
void cambia_colore(int colore)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colore);
}
void stampa_mappa(int m[2 * M + 1][2 * M + 1], stanza *p)
{
for(unsigned int i = 0; i < 2 * M + 1; ++i)
{
for(unsigned int j = 0; j < 2 * M + 1; ++j)
{
cambia_colore(m[i][j] != B ? GIALLO : (i == p->i && j == p->j ? ROSSO : DEFAULT));
printf("%c", m[i][j] ? m[i][j] : ' ');
}
printf("\n");
}
cambia_colore(DEFAULT);
}
int main()
{
int m[2 * M + 1][2 * M + 1] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, B, O, B, 0, 0, 0, B, 0, 0, 0},
{0, 0, D, 0, 0, 0, S, 0, 0, V, 0, 0, 0},
{0, B, 0, 0, 0, 0, 0, B, O, B, O, B, 0},
{0, V, 0, 0, 0, 0, D, 0, S, 0, D, 0, 0},
{0, B, O, B, 0, B, 0, 0, 0, B, 0, 0, 0},
{0, V, X, 0, 0, 0, 0, 0, 0, 0, S, 0, 0},
{0, B, 0, B, 0, 0, 0, 0, 0, 0, 0, B, 0},
{0, 0, S, 0, 0, 0, 0, 0, 0, 0, D, 0, 0},
{0, 0, 0, B, 0, B, 0, 0, 0, B, 0, 0, 0},
{0, 0, 0, 0, 0, 0, S, 0, D, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, B, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; //MAPPA
stanza v[N] = {{"S1" , 1, 3},
{"S2" , 1, 5},
{"S3" , 1, 9},
{"S4" , 3, 1},
{"S5" , 3, 7},
{"S6" , 3, 9},
{"S7" , 3, 11},
{"S8" , 5, 1},
{"S9" , 5, 3},
{"S10", 5, 5},
{"S11", 5, 9},
{"S12", 7, 1},
{"S13", 7, 3},
{"S14", 7, 11},
{"S15", 9, 3},
{"S16", 9, 5},
{"S17", 9, 9},
{"S18", 11, 7}}; //VETTORE STANZE
stanza *p = &v[2]; //STANZA CORRENTE
//-----------------------------------------------------------------------------------
stanza *m2[2 * M + 1][2 * M + 1] = {NULL};
for(unsigned int k = 0; k < N; ++k)
{
m2[v[k].i][v[k].j] = &v[k];
}
char str[200];
while(1)
{
stampa_mappa(m, p);
printf(" SEI NELLA STANZA %s -> ", p->nome);
gets(str);
if(!strcmp(str, "S"))
{
if(m[p->i + 1][p->j])
{
p = m2[p->i + 2][p->j];
}
}
else if(!strcmp(str, "E"))
{
if(m[p->i][p->j + 1])
{
p = m2[p->i][p->j + 2];
}
}
else if(!strcmp(str, "N"))
{
if(m[p->i - 1][p->j])
{
p = m2[p->i - 2][p->j];
}
}
else if(!strcmp(str, "O"))
{
if(m[p->i][p->j - 1])
{
p = m2[p->i][p->j - 2];
}
}
else if(!strcmp(str, "SE"))
{
if(m[p->i + 1][p->j + 1] && m[p->i + 1][p->j + 1] != D)
{
p = m2[p->i + 2][p->j + 2];
}
}
else if(!strcmp(str, "NE"))
{
if(m[p->i - 1][p->j + 1] && m[p->i - 1][p->j + 1] != S)
{
p = m2[p->i - 2][p->j + 2];
}
}
else if(!strcmp(str, "NO"))
{
if(m[p->i - 1][p->j - 1] && m[p->i - 1][p->j - 1] != D)
{
p = m2[p->i - 2][p->j - 2];
}
}
else if(!strcmp(str, "SO"))
{
if(m[p->i + 1][p->j - 1] && m[p->i + 1][p->j - 1] != S)
{
p = m2[p->i + 2][p->j - 2];
}
}
else if(!strcmp(str, "ESCI"))
{
break;
}
system("CLS");
}
return 0;
}
I comandi validi, come si può vedere dal codice, sono: S, SE, E, NE, N, NO, O, SO, ESCI.
Se hai qualche dubbio chiedi pure.