1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
string sMotTrouve = "";
string sPositionPremiereLettre = "";
int iPosCar = 0;
//Nombre de lignes du tableau 2 dimensionel
for(int i = 0; i < m_oMatrice.GetNbLignes(); i++)
{
//Nombre de colonnes du tableau 2 dimensionel
for(int j = 0; j < m_oMatrice.GetNbColonnes(); j++)
//On trouve la premiere lettre de sNom recu en parametre
while(sMotTrouve.data() !=sNom.data() )
{
if(sNom[iPosCar] == m_oMatrice.GetCaractere(i,j))
{
//On ajoute le premier caractere
sMotTrouve += m_oMatrice.GetCaractere(i,j);
iPosCar++;
//On verifie si le deuxieme caractere est aux alentours
if(GetSens(sNom,i ,j,iPosCar))
{
//On rajoute les autres caracteres
sPositionPremiereLettre +=i + "," +j;
sMotTrouve += m_oMatrice.GetCaractere(i,j);
}
}
}
}
}
char GetCaractere(int iLigne, int iColonne)
{
return m_Vecteur[iLigne][iColonne];
}
bool CMotMystere::GetSens(string &sNom, int &i , int &j, int &iPosCar)
{
bool bATrouveLettre=false;
if(sNom[iPosCar] == m_oMatrice.GetCaractere(i+1,j) )
{
bATrouveLettre=true;
m_sChaineDirection = "Direction Ouest-Est : OE";
}
else if(sNom[iPosCar] == m_oMatrice.GetCaractere(i-1,j) && i > 0 )
{
bATrouveLettre=true;
m_sChaineDirection = "Direction Est-Ouest : EO";
}
else if(sNom[iPosCar] == m_oMatrice.GetCaractere(i,j+1) )
{
bATrouveLettre=true;
m_sChaineDirection = "Direction Nord-Sud : NS";
}
else if(sNom[iPosCar] == m_oMatrice.GetCaractere(i,j-1) && j > 0 )
{
bATrouveLettre=true;
m_sChaineDirection = "Direction Sud-Nord : SN";
}
else if(sNom[iPosCar] == m_oMatrice.GetCaractere(i+1,j+1))
{
bATrouveLettre=true;
m_sChaineDirection = "Direction Nord-Ouest-Sud-Est : NOSE";
}
else if(sNom[iPosCar] == m_oMatrice.GetCaractere(i-1,j+1) && i > 0)
{
bATrouveLettre=true;
m_sChaineDirection = "Direction Nord-Est-Sud-Ouest : NESO";
}
else if(sNom[iPosCar] == m_oMatrice.GetCaractere(i+1,j-1) && j >0)
{
bATrouveLettre=true;
m_sChaineDirection = "Direction Nord-Ouest-Sud-Est : NOSE";
}
else if(sNom[iPosCar] == m_oMatrice.GetCaractere(i-1,j-1) && j >0 && i >0)
{
bATrouveLettre=true;
m_sChaineDirection = "Direction Nord-Est-Sud-Ouest : NESO";
}
return bATrouveLettre;
} |
Partager