Alexandre Salconi-Denis / Mbed 2 deprecated ProjetOctopode

Dependencies:   debug mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers labyrinthe.cpp Source File

labyrinthe.cpp

Go to the documentation of this file.
00001 /**
00002   * @file       labyrinthe.cpp
00003   * @brief      Regroupement de fonction pour enregistrer le millieu en 2D.
00004   * @author     Salco
00005   * @version    2.00
00006   * @date       11 mars 2015
00007   */
00008 #include "labyrinthe.h"
00009 
00010 typedef Labyrinthe::coordoner_t coordonerr;
00011 typedef Labyrinthe::case_t case_t;
00012 
00013 Labyrinthe::Labyrinthe()
00014 {
00015     direction=0;
00016     mapDuLabyrinthe.clear();
00017     addMap(0,0);
00018     m_posX=1;
00019     m_posY=1;
00020 }
00021 
00022 Labyrinthe::~Labyrinthe()
00023 {
00024 }
00025 
00026 //modifie X et Y pour metre le bon formatage des coordoner et sort l'ID de la case
00027 //tout ca est qu'un formatage il ne garanti pas que la tuile existe
00028 coordonerr Labyrinthe::getCoordoner(signed char &x, signed char &y) 
00029 {
00030     coordonerr result = unset;
00031     signed char newPosX = (signed char)x;
00032     signed char newPosY = (signed char)y;
00033     
00034     #ifdef DEGUG_LABIRINTH_GET_COORDONER
00035     debug("\n\r----------getCoordoner------\n\r");
00036     debug(" x: %i Y: %i\n\r",(signed char)x, (signed char)newPosY);
00037     #endif
00038     
00039         
00040     newPosX = 3*((((signed char)newPosX<0)? (signed char)newPosX-2:(signed char)newPosX)/3); // je veux le nobre de fois quil a fait un tours et donc seulment les entier
00041     newPosY = 3*((((signed char)newPosY<0)? (signed char)newPosY-2:(signed char)newPosY)/3);
00042     
00043     #ifdef DEGUG_LABIRINTH_GET_COORDONER
00044     debug(" newPosX: %i newPosY: %i\n\r",(signed char)newPosX,(signed char)newPosY);
00045     #endif
00046 
00047     
00048     
00049     switch((signed char)x - (signed char)newPosX){
00050         case 0:
00051             switch(y - newPosY){
00052                 case 0:
00053                     result=C1;
00054                     break;
00055                 
00056                 case 1:
00057                     result=C4;
00058                     break;
00059                 
00060                 case 2:
00061                     result=C7;
00062                     break;
00063                 }
00064         break;
00065         
00066         case 1:
00067             switch(y - newPosY){
00068                 case 0:
00069                     result=C2;
00070                     break;
00071                 
00072                 case 1:
00073                     result=C5;
00074                     break;
00075                 
00076                 case 2:
00077                     result=C8;
00078                     break;
00079                 }
00080         break;
00081         
00082         case 2:
00083             switch(y - newPosY){
00084                 case 0:
00085                     result=C3;
00086                     break;
00087                 
00088                 case 1:
00089                     result=C6;
00090                     break;
00091                 
00092                 case 2:
00093                     result=C9;
00094                     break;
00095                 }
00096         break;       
00097         }
00098     
00099     x = (signed char)newPosX;
00100     y = newPosY;
00101     /*result =(coordonerr)( 2 + newPosX);
00102 
00103     switch(newPosY) {
00104         case-1:
00105             result = result + (3*2);
00106             break;
00107 
00108         case 0:
00109             result = result + (3*1);
00110             break;
00111 
00112         case 1:
00113             result = result + (3*0);
00114             break;
00115     }*/
00116     #ifdef DEGUG_LABIRINTH_GET_COORDONER
00117     //debug(" newPosX: %i newPosY: %i\n\r",newPosX,newPosY);
00118     //debug("\n\r result: X: %02d   Y:%02d",newPosX,newPosY);
00119     debug("\n\r result: :%02d \n\r",result);
00120     debug("--------------------\n\r");
00121     #endif
00122 
00123     return result;
00124 }
00125 coordonerr Labyrinthe::getCoordoner(void)
00126 {
00127     coordonerr result;
00128     signed char newPosX = m_posX;
00129     signed char newPosY = m_posY;
00130     
00131     result = getCoordoner(newPosX,newPosY);
00132 
00133     return result;
00134 }
00135 
00136 string Labyrinthe::showMap(void) 
00137 {
00138     return showMap(m_posX,m_posY);
00139 }
00140 string Labyrinthe::showMap(signed char x, signed char y)
00141 {
00142     //bool result=false;
00143     string theMap;
00144     theMap.clear();
00145     #ifdef DEBUG_LABYRINTHE_SHOW_MAP
00146     debug("\n\r----------showmap------\n\r");
00147     #endif
00148     /* char newPosX = x;
00149      char newPosY = y;
00150 
00151      getCoordoner(newPosX,newPosY);
00152      unsigned char templateX,templateY;
00153      for(int i=0; ((i*DEFAULTLABLEIGHT)<mapDuLabyrinthe.size()) && (!result);i++)
00154      {
00155         templateX = (mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)])>>1;
00156         templateY = ((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)])&1)<<7;
00157         templateY += ((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1])>>2);
00158 
00159         if((templateX == newPosX) && (templateY == newPosY))
00160         {
00161             result=true;
00162             theMap.append(1,((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1])& 3));
00163             }
00164      }*/
00165     int stringPosition = searchCoord(x,y);
00166     if(stringPosition != -1) {
00167         theMap.append(1,((mapDuLabyrinthe[(stringPosition)+1]>>0)& 3));
00168         theMap.append(1,((mapDuLabyrinthe[(stringPosition)+2]>>6)& 3));
00169         theMap.append(1,((mapDuLabyrinthe[(stringPosition)+2]>>4)& 3));
00170 
00171         theMap.append(1,((mapDuLabyrinthe[(stringPosition)+2]>>2)& 3));
00172         theMap.append(1,((mapDuLabyrinthe[(stringPosition)+2]>>0)& 3));
00173         theMap.append(1,((mapDuLabyrinthe[(stringPosition)+3]>>6)& 3));
00174 
00175         theMap.append(1,((mapDuLabyrinthe[(stringPosition)+3]>>4)& 3));
00176         theMap.append(1,((mapDuLabyrinthe[(stringPosition)+3]>>2)& 3));
00177         theMap.append(1,((mapDuLabyrinthe[(stringPosition)+3]>>0)& 3));
00178     }
00179     
00180     #ifdef DEBUG_LABYRINTHE_SHOW_MAP
00181     debug(" mapDuLabyrinthe size: %i \n\r",mapDuLabyrinthe.size());
00182     debug("  stringPosition: %i \n\r",stringPosition); 
00183     if(stringPosition != -1) {
00184         debug(" theMap size: %i \n\r",theMap.size());
00185         debug("  (mapDuLabyrinthe[(stringPosition)+1]>>0): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+1]>>0),((mapDuLabyrinthe[(stringPosition)+1]>>0)& 3)); //c1
00186         debug("  (mapDuLabyrinthe[(stringPosition)+2]>>6): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>6),((mapDuLabyrinthe[(stringPosition)+2]>>6)& 3)); //c2
00187         debug("  (mapDuLabyrinthe[(stringPosition)+2]>>4): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>4),((mapDuLabyrinthe[(stringPosition)+2]>>4)& 3)); //c3
00188         debug("  \n\r");
00189         debug("  (mapDuLabyrinthe[(stringPosition)+2]>>2): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>2),((mapDuLabyrinthe[(stringPosition)+2]>>2)& 3)); //c4
00190         debug("  (mapDuLabyrinthe[(stringPosition)+2]>>0): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>0),((mapDuLabyrinthe[(stringPosition)+2]>>0)& 3)); //c5
00191         debug("  (mapDuLabyrinthe[(stringPosition)+3]>>6): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>6),((mapDuLabyrinthe[(stringPosition)+3]>>6)& 3)); //c6
00192         debug("  \n\r");
00193         debug("  (mapDuLabyrinthe[(stringPosition)+3]>>4): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>4),((mapDuLabyrinthe[(stringPosition)+3]>>4)& 3)); //c7
00194         debug("  (mapDuLabyrinthe[(stringPosition)+3]>>2): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>2),((mapDuLabyrinthe[(stringPosition)+3]>>2)& 3)); //c8
00195         debug("  (mapDuLabyrinthe[(stringPosition)+3]>>0): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>0),((mapDuLabyrinthe[(stringPosition)+3]>>0)& 3)); //c9
00196         debug("  \n\r");
00197     }
00198     debug("\n\r----------------------\n\r");
00199     #endif
00200     return theMap;
00201 }
00202 
00203 bool Labyrinthe::updateMap(string mapUpdated)
00204 {
00205     return updateMap(mapUpdated,m_posX,m_posY);
00206 }
00207 bool Labyrinthe::updateMap(string mapUpdated,signed char x, signed char y)
00208 {
00209     #ifdef DEBUG_LABYRINTHE_GRAPHICAL_INTERFACE
00210     debug("\n\r----------updateMap------\n\r");
00211     #endif
00212     bool result = true;
00213     int stringPosition = searchCoord(x,y);
00214 
00215     if(stringPosition == -1)
00216         result= false; 
00217     else {
00218         mapDuLabyrinthe[(stringPosition)+1] = ((mapDuLabyrinthe[(stringPosition)+1]) & 0xFC) | ((mapUpdated[0] &0x03)<<0); 
00219         mapDuLabyrinthe[(stringPosition)+2] = ((mapDuLabyrinthe[(stringPosition)+2]) & 0x3F) | ((mapUpdated[1] &0x03)<<6); 
00220         mapDuLabyrinthe[(stringPosition)+2] = ((mapDuLabyrinthe[(stringPosition)+2]) & 0xCF) | ((mapUpdated[2] &0x03)<<4);
00221 
00222         mapDuLabyrinthe[(stringPosition)+2] = ((mapDuLabyrinthe[(stringPosition)+2]) & 0xF3) | ((mapUpdated[3] &0x03)<<2);
00223         mapDuLabyrinthe[(stringPosition)+2] = ((mapDuLabyrinthe[(stringPosition)+2]) & 0xFC) | ((mapUpdated[4] &0x03)<<0);
00224         mapDuLabyrinthe[(stringPosition)+3] = ((mapDuLabyrinthe[(stringPosition)+3]) & 0x3F) | ((mapUpdated[5] &0x03)<<6);
00225 
00226         mapDuLabyrinthe[(stringPosition)+3] = ((mapDuLabyrinthe[(stringPosition)+3]) & 0xCF) | ((mapUpdated[6] &0x03)<<4);
00227         mapDuLabyrinthe[(stringPosition)+3] = ((mapDuLabyrinthe[(stringPosition)+3]) & 0xF3) | ((mapUpdated[7] &0x03)<<2);
00228         mapDuLabyrinthe[(stringPosition)+3] = ((mapDuLabyrinthe[(stringPosition)+3]) & 0xFC) | ((mapUpdated[8] &0x03)<<0);
00229     }
00230     
00231      #ifdef DEBUG_LABYRINTHE_GRAPHICAL_INTERFACE
00232     debug(" result: %i \n\r",result?1:0);
00233     debug("  stringPosition: %i \n\r",stringPosition); 
00234     if(stringPosition != -1) {
00235         debug("  (mapDuLabyrinthe[(stringPosition)+1]>>0): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+1]>>0),((mapDuLabyrinthe[(stringPosition)+1]>>0)& 3)); //c1
00236         debug("  (mapDuLabyrinthe[(stringPosition)+2]>>6): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>6),((mapDuLabyrinthe[(stringPosition)+2]>>6)& 3)); //c2
00237         debug("  (mapDuLabyrinthe[(stringPosition)+2]>>4): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>4),((mapDuLabyrinthe[(stringPosition)+2]>>4)& 3)); //c3
00238         debug("  \n\r");
00239         debug("  (mapDuLabyrinthe[(stringPosition)+2]>>2): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>2),((mapDuLabyrinthe[(stringPosition)+2]>>2)& 3)); //c4
00240         debug("  (mapDuLabyrinthe[(stringPosition)+2]>>0): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>0),((mapDuLabyrinthe[(stringPosition)+2]>>0)& 3)); //c5
00241         debug("  (mapDuLabyrinthe[(stringPosition)+3]>>6): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>6),((mapDuLabyrinthe[(stringPosition)+3]>>6)& 3)); //c6
00242         debug("  \n\r");
00243         debug("  (mapDuLabyrinthe[(stringPosition)+3]>>4): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>4),((mapDuLabyrinthe[(stringPosition)+3]>>4)& 3)); //c7
00244         debug("  (mapDuLabyrinthe[(stringPosition)+3]>>2): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>2),((mapDuLabyrinthe[(stringPosition)+3]>>2)& 3)); //c8
00245         debug("  (mapDuLabyrinthe[(stringPosition)+3]>>0): %i &3== %i  \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>0),((mapDuLabyrinthe[(stringPosition)+3]>>0)& 3)); //c9
00246         debug("  \n\r");
00247     }
00248     debug("\n\r----------------------\n\r");
00249     #endif
00250 
00251     return result;
00252 }
00253 bool Labyrinthe::addMap(signed char x, signed char y)
00254 {
00255     bool result = true;
00256     x &= 0x7F; // on coupe le 8eme bit
00257     y &= 0x7F; //
00258 
00259     mapDuLabyrinthe.append(1,((x<<1) | (y>>6)) );//x7,x6,x5,x4,x3,x2,x1,y7
00260     mapDuLabyrinthe.append(1,y<<2);              //y6,y5,y4,y3,y2,y1,[C1],[C1]
00261     mapDuLabyrinthe.append(2,0);                 //add C2-C9 vide
00262     
00263     #ifdef DEBUG_LABYRINTHE_ADD_MAP
00264     debug("----addMap----\n\r");
00265     debug("x = %i \n\r",x);
00266     debug("y = %i \n\r",y);
00267     debug("((x<<1) | (y>>6)) = %i \n\r",((x<<1) | (y>>6)));
00268     
00269     debug("-------------\n\r");
00270     #endif
00271 
00272     return result;
00273 }
00274 
00275 //renvoi l'ID du 4 byte de la tuile dans le string
00276 // renvoi -1 en cas d'erreur
00277 int Labyrinthe::searchCoord(signed char posX,signed char posY)
00278 {
00279     bool result=false;
00280     signed char newPosX = posX;
00281     signed char newPosY = posY;
00282     signed char templateX = 0;
00283     signed char templateY = 0;
00284     int i=0;
00285     
00286     //string theMap;
00287     //theMap.clear();
00288     debug(DEBUGLABSEARCHCOORD,"------Search coord------\n\r");
00289     debug(DEBUGLABSEARCHCOORD," posX: %i posY: %i \n\r",posX,posY);
00290     
00291     
00292     getCoordoner(newPosX,newPosY);
00293     debug(DEBUGLABSEARCHCOORD," new posX: %i new posY: %i \n\r",newPosX,newPosY);
00294     
00295     debug(DEBUGLABSEARCHCOORD," map size: %i \n\r",mapDuLabyrinthe.size());
00296     
00297     for( ; ((i*DEFAULTLABLEIGHT) < mapDuLabyrinthe.size()) && (!result); i++) {
00298        
00299         templateX = (mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)])>>1;
00300         templateY = (((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)])&1)<<6) + ((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1])>>2);
00301         
00302         //patch pour les nombre negatif vue que originelment on est sur un 7 bit
00303         if(templateX & 0x40) templateX |= 0x80;
00304         if(templateY & 0x40) templateY |= 0x80;
00305         
00306         //templateY += ((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1])>>2);
00307         debug(DEBUGLABSEARCHCOORD," mapDuLabyrinthe par1: %i mapDuLabyrinthe part2: %i \n\r",mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)],mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1]);
00308         debug(DEBUGLABSEARCHCOORD," templateX: %i templateY: %i \n\r",templateX,templateY);
00309         if((templateX == newPosX) && (templateY == newPosY)) {
00310             result=true;
00311             //theMap.append(1,((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1])& 3));
00312         }
00313     }
00314     i--;
00315     debug(DEBUGLABSEARCHCOORD," templateX: %i \n\r",templateX);
00316     debug(DEBUGLABSEARCHCOORD," templateY: %i \n\r",templateY);
00317     debug(DEBUGLABSEARCHCOORD," result: %i \n\r",result?1:0);
00318     debug(DEBUGLABSEARCHCOORD," i*DEFAULTLABLEIGHT: %i \n\r",i*DEFAULTLABLEIGHT); 
00319     debug(DEBUGLABSEARCHCOORD,"--------------------\n\r");
00320     return (result==false? -1:i*DEFAULTLABLEIGHT);
00321 }
00322 
00323 case_t Labyrinthe::getC(coordonerr cX)
00324 {
00325  return  getC(m_posX, m_posY, cX);
00326 }
00327 /**
00328 * @param x position X.
00329 * @param y position Y.
00330 * @return 
00331 */
00332 case_t Labyrinthe::getC(signed char x, signed char y)
00333 {
00334     signed char newPosX = x;
00335     signed char newPosY = y;
00336     coordonerr maCoordoner;
00337     maCoordoner=getCoordoner(newPosX,newPosY);
00338     #if defined(DEGUG_LABIRINTH_GET_CASE)
00339     debug("\n\rcoordonerr: %i",maCoordoner);
00340     #endif
00341  return  getC(x, y, maCoordoner);
00342 }
00343 
00344 case_t Labyrinthe::getC(signed char x, signed char y, coordonerr cX)
00345 {
00346     case_t myCoordoner = pasExplorer;
00347     string result = showMap(x,y);
00348     if(result.size() != 0) {
00349         myCoordoner = case_t(result[cX-1]);
00350     }
00351     return myCoordoner;
00352 }
00353 void Labyrinthe::setC(case_t value, signed char x, signed char y, coordonerr cX)
00354 {
00355     #ifdef DEGUG_LABIRINTH_SET_COORDONER
00356         debug("------SetC coord------\n\r");
00357         debug(" value: %i\n\r",value);
00358         debug("coordoner: %i\n\r",cX);
00359         debug("  X:%i Y:%i \n\r",x,y);
00360         #endif
00361     
00362     //if(value != error){
00363         string result = showMap(x,y);
00364         
00365         if(result.size() == 0) 
00366         {//no map found so we create new tuile
00367             #ifdef DEGUG_LABIRINTH_SET_COORDONER
00368             debug(" no tuile found\n\r");
00369             #endif
00370             signed char newPosX = x;
00371             signed char newPosY = y;   
00372             
00373             getCoordoner(newPosX,newPosY);
00374             addMap(newPosX,newPosY);
00375             result = showMap(x,y);
00376             #ifdef DEGUG_LABIRINTH_SET_COORDONER
00377             debug(" result: %i\n\r",result.size());
00378             #endif
00379        }
00380         
00381         if(result.size() != 0)
00382         {   
00383             #ifdef DEGUG_LABIRINTH_SET_COORDONER
00384             debug(" tuile found\n\r");
00385             #endif
00386             result[cX-1]=value;
00387             updateMap(result,x,y);//on remet les case modifier dans le string==map
00388         }
00389     //}
00390         
00391      #ifdef DEGUG_LABIRINTH_SET_COORDONER
00392         debug("---------------------\n\r");
00393         #endif
00394 }
00395 void Labyrinthe::setC(case_t value, coordonerr cX)
00396 {
00397     setC(value,m_posX, m_posY,cX);
00398 }
00399 void Labyrinthe::setC(case_t value, signed char x, signed char y)
00400 {
00401     signed char newPosX = x;
00402     signed char newPosY = y;
00403     coordonerr maCoordoner;
00404     maCoordoner=getCoordoner(newPosX,newPosY);
00405     #if defined(DEGUG_LABIRINTH_GET_CASE)
00406     debug("\n\r-setcase tempo newPosX: %i, x: %i\n\r",newPosX,x);
00407     #endif
00408     setC(value,x,y,maCoordoner);
00409 }
00410 void Labyrinthe::setC_Up(case_t value)
00411 {
00412     setC(value,m_posX, m_posY+1);
00413 }
00414 void Labyrinthe::setC_Down(case_t value)
00415 {
00416     setC(value,m_posX, m_posY-1);
00417 }
00418 void Labyrinthe::setC_Left(case_t value)
00419 {
00420     setC(value,m_posX-1, m_posY);
00421 }
00422 void Labyrinthe::setC_Right(case_t value)
00423 {
00424     setC(value,m_posX+1, m_posY);
00425 }
00426 void Labyrinthe::setMyPos(case_t value)
00427 {
00428     setC(value, m_posX, m_posY);
00429 }
00430 char Labyrinthe::caseToChar(case_t value)
00431 {
00432     char result = 0;
00433     
00434     switch(value)
00435     {
00436      //case error:
00437      //   result = 'X';
00438      //   break;   
00439      case pasExplorer:
00440         result = '*';
00441         break; 
00442      case explorer:
00443         result = 'E';
00444         break;
00445      case mur:
00446         result = 'M';
00447         break;
00448      case vide:
00449         result = 'V';
00450         break;       
00451     }
00452     return result;
00453 }
00454 void Labyrinthe::moveFoward(char dir)
00455 {
00456     switch(dir)
00457     {
00458         case UP:
00459             //m_posX+=0;
00460             m_posY++;
00461             break;
00462         case DOWN:
00463             //m_posX+=0;
00464             m_posY--;
00465             break;
00466         case LEFT:
00467             m_posX--;
00468             //m_posY+=0;
00469             break;
00470         case RIGHT:
00471             m_posX++;
00472             //m_posY+=0;
00473             break;
00474     }
00475 }
00476 void Labyrinthe::moveBackward(char dir)
00477 {
00478     switch(dir)
00479     {
00480         case UP:
00481             //m_posX+=0;
00482             m_posY--;
00483             break;
00484         case DOWN:
00485             //m_posX+=0;
00486             m_posY++;
00487             break;
00488         case LEFT:
00489             m_posX++;
00490             //m_posY+=0;
00491             break;
00492         case RIGHT:
00493             m_posX--;
00494             //m_posY+=0;
00495             break;
00496     }    
00497 }
00498 void Labyrinthe::moveToLeft(char dir)
00499 {
00500     switch(dir)
00501     {
00502         case UP:
00503             m_posX--;
00504             //m_posY+=0;
00505             break;
00506         case DOWN:
00507             m_posX++;
00508             //m_posY+=0;
00509             break;
00510         case LEFT:
00511             //m_posX+=0;
00512             m_posY--;
00513             break;
00514         case RIGHT:
00515             //m_posX+=0;
00516             m_posY++;
00517             break;
00518     }    
00519 }
00520 void Labyrinthe::moveToRight(char dir)
00521 {
00522     switch(dir)
00523     {
00524         case UP:
00525             m_posX++;
00526             //m_posY+=0;
00527             break;
00528         case DOWN:
00529             m_posX--;
00530             //m_posY+=0;
00531             break;
00532         case LEFT:
00533             //m_posX+=0;
00534             m_posY++;
00535             break;
00536         case RIGHT:
00537             //m_posX+=0;
00538             m_posY--;
00539             break;
00540     }    
00541 }
00542 case_t Labyrinthe::getC_Foward(char dir)
00543 {
00544     case_t result = pasExplorer;//error;
00545     
00546     switch(dir)
00547     {
00548         case UP:
00549             #if defined(DEGUG_LABIRINTH_GET_CASE)
00550             debug("m_posX:%i  m_posY+1:%i\n\r",m_posX,m_posY+1);
00551             #endif
00552             result = getC(m_posX,m_posY+1);
00553              #if defined(DEGUG_LABIRINTH_GET_CASE)
00554             debug("result:%i",result);
00555             #endif
00556             break;
00557         case DOWN:
00558             result = getC(m_posX,m_posY-1);
00559             break;
00560         case LEFT:
00561             result = getC(m_posX-1,m_posY);
00562             break;
00563         case RIGHT:
00564             result = getC(m_posX+1,m_posY);
00565             break;
00566     }
00567     return result;
00568 }
00569 case_t Labyrinthe::getC_Backward(char dir)
00570 {
00571     case_t result = mur;// error;
00572     
00573     switch(dir)
00574     {
00575         case UP:
00576             result = getC(m_posX,m_posY-1);
00577             break;
00578         case DOWN:
00579             result = getC(m_posX,m_posY+1);
00580             break;
00581         case LEFT:
00582             result = getC(m_posX+1,m_posY);
00583             break;
00584         case RIGHT:
00585             result = getC(m_posX-1,m_posY);
00586             break;
00587     }
00588     return result;  
00589 }
00590 case_t Labyrinthe::getC_ToLeft(char dir)
00591 {
00592     case_t result = mur;//error;
00593     
00594     switch(dir)
00595     {
00596         case UP:
00597             result = getC(m_posX-1,m_posY);
00598             break;
00599         case DOWN:
00600             result = getC(m_posX+1,m_posY);
00601             break;
00602         case LEFT:
00603             result = getC(m_posX,m_posY-1);
00604             break;
00605         case RIGHT:
00606             result = getC(m_posX,m_posY+1);
00607             break;
00608     }
00609     return result;   
00610 }
00611 case_t Labyrinthe::getC_ToRight(char dir)
00612 {
00613     case_t result = pasExplorer;//error;
00614     
00615     switch(dir)
00616     {
00617         case UP:
00618             result = getC(m_posX+1,m_posY);
00619             break;
00620         case DOWN:
00621             result = getC(m_posX-1,m_posY);
00622             break;
00623         case LEFT:
00624             result = getC(m_posX,m_posY+1);
00625             break;
00626         case RIGHT:
00627             result = getC(m_posX,m_posY-1);
00628             break;
00629     }
00630     return result;    
00631 }
00632    
00633    
00634 void Labyrinthe::turnBack(void)
00635 {
00636     switch(direction)
00637     {
00638         case UP:
00639             direction = DOWN;
00640             break;
00641         case DOWN:
00642             direction = UP;
00643             break;
00644         case LEFT:
00645             direction = RIGHT;
00646             break;
00647         case RIGHT:
00648             direction = LEFT;
00649             break;
00650     }
00651 
00652 }
00653 void Labyrinthe::turnLeft(void)
00654 {
00655     switch(direction)
00656     {
00657         case UP:
00658             direction = LEFT;
00659             break;
00660         case DOWN:
00661             direction = RIGHT;
00662             break;
00663         case LEFT:
00664             direction = DOWN;
00665             break;
00666         case RIGHT:
00667             direction = UP;
00668             break;
00669     }
00670 }
00671 void Labyrinthe::turnRight(void)
00672 {
00673     switch(direction)
00674     {
00675         case UP:
00676             direction = RIGHT;
00677             break;
00678         case DOWN:
00679             direction = LEFT;
00680             break;
00681         case LEFT:
00682             direction = UP;
00683             break;
00684         case RIGHT:
00685             direction = DOWN;
00686             break;
00687     }
00688 }
00689 
00690 
00691 void Labyrinthe::getXY_Foward(signed char &x, signed char &y,char dir)
00692 {
00693     switch(direction)
00694     {
00695         case UP:
00696             x = m_posX;
00697             y = m_posY+1;
00698             break;
00699         case DOWN:
00700             x = m_posX;
00701             y = m_posY-1;
00702             break;
00703         case LEFT:
00704             x = m_posX-1;
00705             y = m_posY;
00706             break;
00707         case RIGHT:
00708             x = m_posX+1;
00709             y = m_posY;
00710             break;
00711     }
00712 }
00713 
00714 void Labyrinthe::getXY_Backward(signed char &x, signed char &y,char dir)
00715 {
00716     switch(direction)
00717     {
00718         case UP:
00719             x = m_posX;
00720             y = m_posY-1;
00721             break;
00722         case DOWN:
00723             x = m_posX;
00724             y = m_posY+1;
00725             break;
00726         case LEFT:
00727             x = m_posX+1;
00728             y = m_posY;
00729             break;
00730         case RIGHT:
00731             x = m_posX-1;
00732             y = m_posY;
00733             break;
00734     }
00735 }
00736 
00737 void Labyrinthe::getXY_Left(signed char &x, signed char &y, char dir)
00738 {
00739     switch(direction)
00740     {
00741         case UP:
00742             x = m_posX-1;
00743             y = m_posY;
00744             break;
00745         case DOWN:
00746             x = m_posX+1;
00747             y = m_posY;
00748             break;
00749         case LEFT:
00750             x = m_posX;
00751             y = m_posY-1;
00752             break;
00753         case RIGHT:
00754             x = m_posX;
00755             y = m_posY+1;
00756             break;
00757     }
00758 }
00759 
00760 void Labyrinthe::getXY_Right(signed char &x, signed char &y, char dir)
00761 {
00762     switch(direction)
00763     {
00764         case UP:
00765             x = m_posX+1;
00766             y = m_posY;
00767             break;
00768         case DOWN:
00769             x = m_posX-1;
00770             y = m_posY;
00771             break;
00772         case LEFT:
00773             x = m_posX;
00774             y = m_posY+1;
00775             break;
00776         case RIGHT:
00777             x = m_posX;
00778             y = m_posY-1;
00779             break;
00780     }
00781 }