Programme de contrôle de l'octopode 4DOF, Theraphosa-Salconi.

Dependencies:   debug mbed

CtrlBridge

  • fonction quelquonque pour communiquer avec les module
  • fonction quelquonque pour faire des recherche dans les module dispo
  • autre fonction pour jouer avec MemRegistre

Version 1.2.0

  • Ajout d'un mode de simulation pour tester le code avec seulement un contrôleur stm32
Committer:
salco
Date:
Tue Jan 31 13:15:42 2017 +0000
Revision:
41:0b5c14dda54a
Parent:
39:34d7802e8d15
Tentative de modifier les commit inutile sur debug.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
salco 35:d81f6b927932 1 /**
salco 35:d81f6b927932 2 * @file labyrinthe.cpp
salco 35:d81f6b927932 3 * @brief Regroupement de fonction pour enregistrer le millieu en 2D.
salco 35:d81f6b927932 4 * @author Salco
salco 35:d81f6b927932 5 * @version 2.00
salco 35:d81f6b927932 6 * @date 11 mars 2015
salco 35:d81f6b927932 7 */
salco 28:ac5c6350ed9a 8 #include "labyrinthe.h"
salco 28:ac5c6350ed9a 9
salco 36:474d4795aafa 10 typedef Labyrinthe::coordoner_t coordonerr;
salco 36:474d4795aafa 11 typedef Labyrinthe::case_t case_t;
salco 28:ac5c6350ed9a 12
salco 28:ac5c6350ed9a 13 Labyrinthe::Labyrinthe()
salco 28:ac5c6350ed9a 14 {
salco 28:ac5c6350ed9a 15 direction=0;
salco 28:ac5c6350ed9a 16 mapDuLabyrinthe.clear();
salco 28:ac5c6350ed9a 17 addMap(0,0);
salco 36:474d4795aafa 18 m_posX=1;
salco 36:474d4795aafa 19 m_posY=1;
salco 28:ac5c6350ed9a 20 }
salco 28:ac5c6350ed9a 21
salco 28:ac5c6350ed9a 22 Labyrinthe::~Labyrinthe()
salco 28:ac5c6350ed9a 23 {
salco 28:ac5c6350ed9a 24 }
salco 28:ac5c6350ed9a 25
salco 37:f53e9f7a14df 26 //modifie X et Y pour metre le bon formatage des coordoner et sort l'ID de la case
salco 37:f53e9f7a14df 27 //tout ca est qu'un formatage il ne garanti pas que la tuile existe
salco 37:f53e9f7a14df 28 coordonerr Labyrinthe::getCoordoner(signed char &x, signed char &y)
salco 28:ac5c6350ed9a 29 {
salco 36:474d4795aafa 30 coordonerr result = unset;
salco 37:f53e9f7a14df 31 signed char newPosX = (signed char)x;
salco 37:f53e9f7a14df 32 signed char newPosY = (signed char)y;
salco 36:474d4795aafa 33
salco 36:474d4795aafa 34 #ifdef DEGUG_LABIRINTH_GET_COORDONER
salco 36:474d4795aafa 35 debug("\n\r----------getCoordoner------\n\r");
salco 37:f53e9f7a14df 36 debug(" x: %i Y: %i\n\r",(signed char)x, (signed char)newPosY);
salco 36:474d4795aafa 37 #endif
salco 36:474d4795aafa 38
salco 36:474d4795aafa 39
salco 37:f53e9f7a14df 40 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
salco 37:f53e9f7a14df 41 newPosY = 3*((((signed char)newPosY<0)? (signed char)newPosY-2:(signed char)newPosY)/3);
salco 36:474d4795aafa 42
salco 36:474d4795aafa 43 #ifdef DEGUG_LABIRINTH_GET_COORDONER
salco 37:f53e9f7a14df 44 debug(" newPosX: %i newPosY: %i\n\r",(signed char)newPosX,(signed char)newPosY);
salco 36:474d4795aafa 45 #endif
salco 28:ac5c6350ed9a 46
salco 36:474d4795aafa 47
salco 36:474d4795aafa 48
salco 37:f53e9f7a14df 49 switch((signed char)x - (signed char)newPosX){
salco 36:474d4795aafa 50 case 0:
salco 36:474d4795aafa 51 switch(y - newPosY){
salco 36:474d4795aafa 52 case 0:
salco 36:474d4795aafa 53 result=C1;
salco 36:474d4795aafa 54 break;
salco 36:474d4795aafa 55
salco 36:474d4795aafa 56 case 1:
salco 37:f53e9f7a14df 57 result=C4;
salco 36:474d4795aafa 58 break;
salco 36:474d4795aafa 59
salco 36:474d4795aafa 60 case 2:
salco 37:f53e9f7a14df 61 result=C7;
salco 36:474d4795aafa 62 break;
salco 36:474d4795aafa 63 }
salco 36:474d4795aafa 64 break;
salco 36:474d4795aafa 65
salco 36:474d4795aafa 66 case 1:
salco 36:474d4795aafa 67 switch(y - newPosY){
salco 36:474d4795aafa 68 case 0:
salco 37:f53e9f7a14df 69 result=C2;
salco 36:474d4795aafa 70 break;
salco 36:474d4795aafa 71
salco 36:474d4795aafa 72 case 1:
salco 36:474d4795aafa 73 result=C5;
salco 36:474d4795aafa 74 break;
salco 36:474d4795aafa 75
salco 36:474d4795aafa 76 case 2:
salco 37:f53e9f7a14df 77 result=C8;
salco 36:474d4795aafa 78 break;
salco 36:474d4795aafa 79 }
salco 36:474d4795aafa 80 break;
salco 36:474d4795aafa 81
salco 36:474d4795aafa 82 case 2:
salco 36:474d4795aafa 83 switch(y - newPosY){
salco 36:474d4795aafa 84 case 0:
salco 37:f53e9f7a14df 85 result=C3;
salco 36:474d4795aafa 86 break;
salco 36:474d4795aafa 87
salco 36:474d4795aafa 88 case 1:
salco 37:f53e9f7a14df 89 result=C6;
salco 36:474d4795aafa 90 break;
salco 36:474d4795aafa 91
salco 36:474d4795aafa 92 case 2:
salco 36:474d4795aafa 93 result=C9;
salco 36:474d4795aafa 94 break;
salco 36:474d4795aafa 95 }
salco 36:474d4795aafa 96 break;
salco 36:474d4795aafa 97 }
salco 36:474d4795aafa 98
salco 37:f53e9f7a14df 99 x = (signed char)newPosX;
salco 28:ac5c6350ed9a 100 y = newPosY;
salco 36:474d4795aafa 101 /*result =(coordonerr)( 2 + newPosX);
salco 28:ac5c6350ed9a 102
salco 28:ac5c6350ed9a 103 switch(newPosY) {
salco 28:ac5c6350ed9a 104 case-1:
salco 28:ac5c6350ed9a 105 result = result + (3*2);
salco 28:ac5c6350ed9a 106 break;
salco 28:ac5c6350ed9a 107
salco 28:ac5c6350ed9a 108 case 0:
salco 28:ac5c6350ed9a 109 result = result + (3*1);
salco 28:ac5c6350ed9a 110 break;
salco 28:ac5c6350ed9a 111
salco 28:ac5c6350ed9a 112 case 1:
salco 28:ac5c6350ed9a 113 result = result + (3*0);
salco 28:ac5c6350ed9a 114 break;
salco 36:474d4795aafa 115 }*/
salco 36:474d4795aafa 116 #ifdef DEGUG_LABIRINTH_GET_COORDONER
salco 37:f53e9f7a14df 117 //debug(" newPosX: %i newPosY: %i\n\r",newPosX,newPosY);
salco 36:474d4795aafa 118 //debug("\n\r result: X: %02d Y:%02d",newPosX,newPosY);
salco 36:474d4795aafa 119 debug("\n\r result: :%02d \n\r",result);
salco 37:f53e9f7a14df 120 debug("--------------------\n\r");
salco 36:474d4795aafa 121 #endif
salco 28:ac5c6350ed9a 122
salco 28:ac5c6350ed9a 123 return result;
salco 28:ac5c6350ed9a 124 }
salco 36:474d4795aafa 125 coordonerr Labyrinthe::getCoordoner(void)
salco 28:ac5c6350ed9a 126 {
salco 36:474d4795aafa 127 coordonerr result;
salco 37:f53e9f7a14df 128 signed char newPosX = m_posX;
salco 37:f53e9f7a14df 129 signed char newPosY = m_posY;
salco 36:474d4795aafa 130
salco 36:474d4795aafa 131 result = getCoordoner(newPosX,newPosY);
salco 28:ac5c6350ed9a 132
salco 28:ac5c6350ed9a 133 return result;
salco 28:ac5c6350ed9a 134 }
salco 28:ac5c6350ed9a 135
salco 35:d81f6b927932 136 string Labyrinthe::showMap(void)
salco 28:ac5c6350ed9a 137 {
salco 28:ac5c6350ed9a 138 return showMap(m_posX,m_posY);
salco 28:ac5c6350ed9a 139 }
salco 37:f53e9f7a14df 140 string Labyrinthe::showMap(signed char x, signed char y)
salco 28:ac5c6350ed9a 141 {
salco 28:ac5c6350ed9a 142 //bool result=false;
salco 28:ac5c6350ed9a 143 string theMap;
salco 28:ac5c6350ed9a 144 theMap.clear();
salco 37:f53e9f7a14df 145 #ifdef DEBUG_LABYRINTHE_SHOW_MAP
salco 37:f53e9f7a14df 146 debug("\n\r----------showmap------\n\r");
salco 37:f53e9f7a14df 147 #endif
salco 28:ac5c6350ed9a 148 /* char newPosX = x;
salco 28:ac5c6350ed9a 149 char newPosY = y;
salco 28:ac5c6350ed9a 150
salco 28:ac5c6350ed9a 151 getCoordoner(newPosX,newPosY);
salco 28:ac5c6350ed9a 152 unsigned char templateX,templateY;
salco 28:ac5c6350ed9a 153 for(int i=0; ((i*DEFAULTLABLEIGHT)<mapDuLabyrinthe.size()) && (!result);i++)
salco 28:ac5c6350ed9a 154 {
salco 28:ac5c6350ed9a 155 templateX = (mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)])>>1;
salco 28:ac5c6350ed9a 156 templateY = ((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)])&1)<<7;
salco 28:ac5c6350ed9a 157 templateY += ((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1])>>2);
salco 28:ac5c6350ed9a 158
salco 28:ac5c6350ed9a 159 if((templateX == newPosX) && (templateY == newPosY))
salco 28:ac5c6350ed9a 160 {
salco 28:ac5c6350ed9a 161 result=true;
salco 28:ac5c6350ed9a 162 theMap.append(1,((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1])& 3));
salco 28:ac5c6350ed9a 163 }
salco 28:ac5c6350ed9a 164 }*/
salco 28:ac5c6350ed9a 165 int stringPosition = searchCoord(x,y);
salco 28:ac5c6350ed9a 166 if(stringPosition != -1) {
salco 28:ac5c6350ed9a 167 theMap.append(1,((mapDuLabyrinthe[(stringPosition)+1]>>0)& 3));
salco 28:ac5c6350ed9a 168 theMap.append(1,((mapDuLabyrinthe[(stringPosition)+2]>>6)& 3));
salco 28:ac5c6350ed9a 169 theMap.append(1,((mapDuLabyrinthe[(stringPosition)+2]>>4)& 3));
salco 28:ac5c6350ed9a 170
salco 28:ac5c6350ed9a 171 theMap.append(1,((mapDuLabyrinthe[(stringPosition)+2]>>2)& 3));
salco 28:ac5c6350ed9a 172 theMap.append(1,((mapDuLabyrinthe[(stringPosition)+2]>>0)& 3));
salco 28:ac5c6350ed9a 173 theMap.append(1,((mapDuLabyrinthe[(stringPosition)+3]>>6)& 3));
salco 28:ac5c6350ed9a 174
salco 28:ac5c6350ed9a 175 theMap.append(1,((mapDuLabyrinthe[(stringPosition)+3]>>4)& 3));
salco 28:ac5c6350ed9a 176 theMap.append(1,((mapDuLabyrinthe[(stringPosition)+3]>>2)& 3));
salco 28:ac5c6350ed9a 177 theMap.append(1,((mapDuLabyrinthe[(stringPosition)+3]>>0)& 3));
salco 28:ac5c6350ed9a 178 }
salco 35:d81f6b927932 179
salco 37:f53e9f7a14df 180 #ifdef DEBUG_LABYRINTHE_SHOW_MAP
salco 37:f53e9f7a14df 181 debug(" mapDuLabyrinthe size: %i \n\r",mapDuLabyrinthe.size());
salco 35:d81f6b927932 182 debug(" stringPosition: %i \n\r",stringPosition);
salco 35:d81f6b927932 183 if(stringPosition != -1) {
salco 37:f53e9f7a14df 184 debug(" theMap size: %i \n\r",theMap.size());
salco 36:474d4795aafa 185 debug(" (mapDuLabyrinthe[(stringPosition)+1]>>0): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+1]>>0),((mapDuLabyrinthe[(stringPosition)+1]>>0)& 3)); //c1
salco 36:474d4795aafa 186 debug(" (mapDuLabyrinthe[(stringPosition)+2]>>6): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>6),((mapDuLabyrinthe[(stringPosition)+2]>>6)& 3)); //c2
salco 36:474d4795aafa 187 debug(" (mapDuLabyrinthe[(stringPosition)+2]>>4): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>4),((mapDuLabyrinthe[(stringPosition)+2]>>4)& 3)); //c3
salco 35:d81f6b927932 188 debug(" \n\r");
salco 36:474d4795aafa 189 debug(" (mapDuLabyrinthe[(stringPosition)+2]>>2): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>2),((mapDuLabyrinthe[(stringPosition)+2]>>2)& 3)); //c4
salco 36:474d4795aafa 190 debug(" (mapDuLabyrinthe[(stringPosition)+2]>>0): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>0),((mapDuLabyrinthe[(stringPosition)+2]>>0)& 3)); //c5
salco 36:474d4795aafa 191 debug(" (mapDuLabyrinthe[(stringPosition)+3]>>6): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>6),((mapDuLabyrinthe[(stringPosition)+3]>>6)& 3)); //c6
salco 35:d81f6b927932 192 debug(" \n\r");
salco 36:474d4795aafa 193 debug(" (mapDuLabyrinthe[(stringPosition)+3]>>4): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>4),((mapDuLabyrinthe[(stringPosition)+3]>>4)& 3)); //c7
salco 36:474d4795aafa 194 debug(" (mapDuLabyrinthe[(stringPosition)+3]>>2): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>2),((mapDuLabyrinthe[(stringPosition)+3]>>2)& 3)); //c8
salco 36:474d4795aafa 195 debug(" (mapDuLabyrinthe[(stringPosition)+3]>>0): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>0),((mapDuLabyrinthe[(stringPosition)+3]>>0)& 3)); //c9
salco 35:d81f6b927932 196 debug(" \n\r");
salco 35:d81f6b927932 197 }
salco 35:d81f6b927932 198 debug("\n\r----------------------\n\r");
salco 35:d81f6b927932 199 #endif
salco 28:ac5c6350ed9a 200 return theMap;
salco 28:ac5c6350ed9a 201 }
salco 28:ac5c6350ed9a 202
salco 28:ac5c6350ed9a 203 bool Labyrinthe::updateMap(string mapUpdated)
salco 28:ac5c6350ed9a 204 {
salco 28:ac5c6350ed9a 205 return updateMap(mapUpdated,m_posX,m_posY);
salco 28:ac5c6350ed9a 206 }
salco 37:f53e9f7a14df 207 bool Labyrinthe::updateMap(string mapUpdated,signed char x, signed char y)
salco 28:ac5c6350ed9a 208 {
salco 37:f53e9f7a14df 209 #ifdef DEBUG_LABYRINTHE_GRAPHICAL_INTERFACE
salco 37:f53e9f7a14df 210 debug("\n\r----------updateMap------\n\r");
salco 37:f53e9f7a14df 211 #endif
salco 28:ac5c6350ed9a 212 bool result = true;
salco 28:ac5c6350ed9a 213 int stringPosition = searchCoord(x,y);
salco 28:ac5c6350ed9a 214
salco 28:ac5c6350ed9a 215 if(stringPosition == -1)
salco 37:f53e9f7a14df 216 result= false;
salco 28:ac5c6350ed9a 217 else {
salco 36:474d4795aafa 218 mapDuLabyrinthe[(stringPosition)+1] = ((mapDuLabyrinthe[(stringPosition)+1]) & 0xFC) | ((mapUpdated[0] &0x03)<<0);
salco 36:474d4795aafa 219 mapDuLabyrinthe[(stringPosition)+2] = ((mapDuLabyrinthe[(stringPosition)+2]) & 0x3F) | ((mapUpdated[1] &0x03)<<6);
salco 28:ac5c6350ed9a 220 mapDuLabyrinthe[(stringPosition)+2] = ((mapDuLabyrinthe[(stringPosition)+2]) & 0xCF) | ((mapUpdated[2] &0x03)<<4);
salco 28:ac5c6350ed9a 221
salco 28:ac5c6350ed9a 222 mapDuLabyrinthe[(stringPosition)+2] = ((mapDuLabyrinthe[(stringPosition)+2]) & 0xF3) | ((mapUpdated[3] &0x03)<<2);
salco 28:ac5c6350ed9a 223 mapDuLabyrinthe[(stringPosition)+2] = ((mapDuLabyrinthe[(stringPosition)+2]) & 0xFC) | ((mapUpdated[4] &0x03)<<0);
salco 37:f53e9f7a14df 224 mapDuLabyrinthe[(stringPosition)+3] = ((mapDuLabyrinthe[(stringPosition)+3]) & 0x3F) | ((mapUpdated[5] &0x03)<<6);
salco 28:ac5c6350ed9a 225
salco 37:f53e9f7a14df 226 mapDuLabyrinthe[(stringPosition)+3] = ((mapDuLabyrinthe[(stringPosition)+3]) & 0xCF) | ((mapUpdated[6] &0x03)<<4);
salco 37:f53e9f7a14df 227 mapDuLabyrinthe[(stringPosition)+3] = ((mapDuLabyrinthe[(stringPosition)+3]) & 0xF3) | ((mapUpdated[7] &0x03)<<2);
salco 37:f53e9f7a14df 228 mapDuLabyrinthe[(stringPosition)+3] = ((mapDuLabyrinthe[(stringPosition)+3]) & 0xFC) | ((mapUpdated[8] &0x03)<<0);
salco 28:ac5c6350ed9a 229 }
salco 37:f53e9f7a14df 230
salco 37:f53e9f7a14df 231 #ifdef DEBUG_LABYRINTHE_GRAPHICAL_INTERFACE
salco 37:f53e9f7a14df 232 debug(" result: %i \n\r",result?1:0);
salco 37:f53e9f7a14df 233 debug(" stringPosition: %i \n\r",stringPosition);
salco 37:f53e9f7a14df 234 if(stringPosition != -1) {
salco 37:f53e9f7a14df 235 debug(" (mapDuLabyrinthe[(stringPosition)+1]>>0): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+1]>>0),((mapDuLabyrinthe[(stringPosition)+1]>>0)& 3)); //c1
salco 37:f53e9f7a14df 236 debug(" (mapDuLabyrinthe[(stringPosition)+2]>>6): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>6),((mapDuLabyrinthe[(stringPosition)+2]>>6)& 3)); //c2
salco 37:f53e9f7a14df 237 debug(" (mapDuLabyrinthe[(stringPosition)+2]>>4): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>4),((mapDuLabyrinthe[(stringPosition)+2]>>4)& 3)); //c3
salco 37:f53e9f7a14df 238 debug(" \n\r");
salco 37:f53e9f7a14df 239 debug(" (mapDuLabyrinthe[(stringPosition)+2]>>2): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>2),((mapDuLabyrinthe[(stringPosition)+2]>>2)& 3)); //c4
salco 37:f53e9f7a14df 240 debug(" (mapDuLabyrinthe[(stringPosition)+2]>>0): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+2]>>0),((mapDuLabyrinthe[(stringPosition)+2]>>0)& 3)); //c5
salco 37:f53e9f7a14df 241 debug(" (mapDuLabyrinthe[(stringPosition)+3]>>6): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>6),((mapDuLabyrinthe[(stringPosition)+3]>>6)& 3)); //c6
salco 37:f53e9f7a14df 242 debug(" \n\r");
salco 37:f53e9f7a14df 243 debug(" (mapDuLabyrinthe[(stringPosition)+3]>>4): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>4),((mapDuLabyrinthe[(stringPosition)+3]>>4)& 3)); //c7
salco 37:f53e9f7a14df 244 debug(" (mapDuLabyrinthe[(stringPosition)+3]>>2): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>2),((mapDuLabyrinthe[(stringPosition)+3]>>2)& 3)); //c8
salco 37:f53e9f7a14df 245 debug(" (mapDuLabyrinthe[(stringPosition)+3]>>0): %i &3== %i \n\r",(mapDuLabyrinthe[(stringPosition)+3]>>0),((mapDuLabyrinthe[(stringPosition)+3]>>0)& 3)); //c9
salco 37:f53e9f7a14df 246 debug(" \n\r");
salco 37:f53e9f7a14df 247 }
salco 37:f53e9f7a14df 248 debug("\n\r----------------------\n\r");
salco 37:f53e9f7a14df 249 #endif
salco 28:ac5c6350ed9a 250
salco 28:ac5c6350ed9a 251 return result;
salco 28:ac5c6350ed9a 252 }
salco 37:f53e9f7a14df 253 bool Labyrinthe::addMap(signed char x, signed char y)
salco 28:ac5c6350ed9a 254 {
salco 28:ac5c6350ed9a 255 bool result = true;
salco 28:ac5c6350ed9a 256 x &= 0x7F; // on coupe le 8eme bit
salco 35:d81f6b927932 257 y &= 0x7F; //
salco 28:ac5c6350ed9a 258
salco 35:d81f6b927932 259 mapDuLabyrinthe.append(1,((x<<1) | (y>>6)) );//x7,x6,x5,x4,x3,x2,x1,y7
salco 37:f53e9f7a14df 260 mapDuLabyrinthe.append(1,y<<2); //y6,y5,y4,y3,y2,y1,[C1],[C1]
salco 35:d81f6b927932 261 mapDuLabyrinthe.append(2,0); //add C2-C9 vide
salco 35:d81f6b927932 262
salco 35:d81f6b927932 263 #ifdef DEBUG_LABYRINTHE_ADD_MAP
salco 35:d81f6b927932 264 debug("----addMap----\n\r");
salco 35:d81f6b927932 265 debug("x = %i \n\r",x);
salco 35:d81f6b927932 266 debug("y = %i \n\r",y);
salco 35:d81f6b927932 267 debug("((x<<1) | (y>>6)) = %i \n\r",((x<<1) | (y>>6)));
salco 37:f53e9f7a14df 268
salco 35:d81f6b927932 269 debug("-------------\n\r");
salco 35:d81f6b927932 270 #endif
salco 28:ac5c6350ed9a 271
salco 28:ac5c6350ed9a 272 return result;
salco 28:ac5c6350ed9a 273 }
salco 28:ac5c6350ed9a 274
salco 36:474d4795aafa 275 //renvoi l'ID du 4 byte de la tuile dans le string
salco 37:f53e9f7a14df 276 // renvoi -1 en cas d'erreur
salco 37:f53e9f7a14df 277 int Labyrinthe::searchCoord(signed char posX,signed char posY)
salco 28:ac5c6350ed9a 278 {
salco 28:ac5c6350ed9a 279 bool result=false;
salco 37:f53e9f7a14df 280 signed char newPosX = posX;
salco 37:f53e9f7a14df 281 signed char newPosY = posY;
salco 37:f53e9f7a14df 282 signed char templateX = 0;
salco 37:f53e9f7a14df 283 signed char templateY = 0;
salco 36:474d4795aafa 284 int i=0;
salco 37:f53e9f7a14df 285
salco 28:ac5c6350ed9a 286 //string theMap;
salco 28:ac5c6350ed9a 287 //theMap.clear();
salco 37:f53e9f7a14df 288 debug(DEBUGLABSEARCHCOORD,"------Search coord------\n\r");
salco 35:d81f6b927932 289 debug(DEBUGLABSEARCHCOORD," posX: %i posY: %i \n\r",posX,posY);
salco 35:d81f6b927932 290
salco 36:474d4795aafa 291
salco 28:ac5c6350ed9a 292 getCoordoner(newPosX,newPosY);
salco 35:d81f6b927932 293 debug(DEBUGLABSEARCHCOORD," new posX: %i new posY: %i \n\r",newPosX,newPosY);
salco 36:474d4795aafa 294
salco 35:d81f6b927932 295 debug(DEBUGLABSEARCHCOORD," map size: %i \n\r",mapDuLabyrinthe.size());
salco 36:474d4795aafa 296
salco 35:d81f6b927932 297 for( ; ((i*DEFAULTLABLEIGHT) < mapDuLabyrinthe.size()) && (!result); i++) {
salco 35:d81f6b927932 298
salco 28:ac5c6350ed9a 299 templateX = (mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)])>>1;
salco 37:f53e9f7a14df 300 templateY = (((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)])&1)<<6) + ((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1])>>2);
salco 37:f53e9f7a14df 301
salco 37:f53e9f7a14df 302 //patch pour les nombre negatif vue que originelment on est sur un 7 bit
salco 37:f53e9f7a14df 303 if(templateX & 0x40) templateX |= 0x80;
salco 37:f53e9f7a14df 304 if(templateY & 0x40) templateY |= 0x80;
salco 37:f53e9f7a14df 305
salco 36:474d4795aafa 306 //templateY += ((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1])>>2);
salco 37:f53e9f7a14df 307 debug(DEBUGLABSEARCHCOORD," mapDuLabyrinthe par1: %i mapDuLabyrinthe part2: %i \n\r",mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)],mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1]);
salco 37:f53e9f7a14df 308 debug(DEBUGLABSEARCHCOORD," templateX: %i templateY: %i \n\r",templateX,templateY);
salco 28:ac5c6350ed9a 309 if((templateX == newPosX) && (templateY == newPosY)) {
salco 28:ac5c6350ed9a 310 result=true;
salco 28:ac5c6350ed9a 311 //theMap.append(1,((mapDuLabyrinthe[(i*DEFAULTLABLEIGHT)+1])& 3));
salco 28:ac5c6350ed9a 312 }
salco 28:ac5c6350ed9a 313 }
salco 36:474d4795aafa 314 i--;
salco 35:d81f6b927932 315 debug(DEBUGLABSEARCHCOORD," templateX: %i \n\r",templateX);
salco 35:d81f6b927932 316 debug(DEBUGLABSEARCHCOORD," templateY: %i \n\r",templateY);
salco 36:474d4795aafa 317 debug(DEBUGLABSEARCHCOORD," result: %i \n\r",result?1:0);
salco 36:474d4795aafa 318 debug(DEBUGLABSEARCHCOORD," i*DEFAULTLABLEIGHT: %i \n\r",i*DEFAULTLABLEIGHT);
salco 37:f53e9f7a14df 319 debug(DEBUGLABSEARCHCOORD,"--------------------\n\r");
salco 36:474d4795aafa 320 return (result==false? -1:i*DEFAULTLABLEIGHT);
salco 28:ac5c6350ed9a 321 }
salco 28:ac5c6350ed9a 322
salco 36:474d4795aafa 323 case_t Labyrinthe::getC(coordonerr cX)
salco 28:ac5c6350ed9a 324 {
salco 28:ac5c6350ed9a 325 return getC(m_posX, m_posY, cX);
salco 28:ac5c6350ed9a 326 }
salco 36:474d4795aafa 327 /**
salco 36:474d4795aafa 328 * @param x position X.
salco 36:474d4795aafa 329 * @param y position Y.
salco 36:474d4795aafa 330 * @return
salco 36:474d4795aafa 331 */
salco 37:f53e9f7a14df 332 case_t Labyrinthe::getC(signed char x, signed char y)
salco 28:ac5c6350ed9a 333 {
salco 37:f53e9f7a14df 334 signed char newPosX = x;
salco 37:f53e9f7a14df 335 signed char newPosY = y;
salco 36:474d4795aafa 336 coordonerr maCoordoner;
salco 28:ac5c6350ed9a 337 maCoordoner=getCoordoner(newPosX,newPosY);
salco 39:34d7802e8d15 338 #if defined(DEGUG_LABIRINTH_GET_CASE)
salco 38:57d5f36a0333 339 debug("\n\rcoordonerr: %i",maCoordoner);
salco 39:34d7802e8d15 340 #endif
salco 28:ac5c6350ed9a 341 return getC(x, y, maCoordoner);
salco 28:ac5c6350ed9a 342 }
salco 36:474d4795aafa 343
salco 37:f53e9f7a14df 344 case_t Labyrinthe::getC(signed char x, signed char y, coordonerr cX)
salco 28:ac5c6350ed9a 345 {
salco 39:34d7802e8d15 346 case_t myCoordoner = pasExplorer;
salco 28:ac5c6350ed9a 347 string result = showMap(x,y);
salco 28:ac5c6350ed9a 348 if(result.size() != 0) {
salco 38:57d5f36a0333 349 myCoordoner = case_t(result[cX-1]);
salco 37:f53e9f7a14df 350 }
salco 37:f53e9f7a14df 351 return myCoordoner;
salco 37:f53e9f7a14df 352 }
salco 37:f53e9f7a14df 353 void Labyrinthe::setC(case_t value, signed char x, signed char y, coordonerr cX)
salco 37:f53e9f7a14df 354 {
salco 37:f53e9f7a14df 355 #ifdef DEGUG_LABIRINTH_SET_COORDONER
salco 37:f53e9f7a14df 356 debug("------SetC coord------\n\r");
salco 37:f53e9f7a14df 357 debug(" value: %i\n\r",value);
salco 36:474d4795aafa 358 debug("coordoner: %i\n\r",cX);
salco 37:f53e9f7a14df 359 debug(" X:%i Y:%i \n\r",x,y);
salco 37:f53e9f7a14df 360 #endif
salco 37:f53e9f7a14df 361
salco 39:34d7802e8d15 362 //if(value != error){
salco 37:f53e9f7a14df 363 string result = showMap(x,y);
salco 37:f53e9f7a14df 364
salco 39:34d7802e8d15 365 if(result.size() == 0)
salco 39:34d7802e8d15 366 {//no map found so we create new tuile
salco 39:34d7802e8d15 367 #ifdef DEGUG_LABIRINTH_SET_COORDONER
salco 39:34d7802e8d15 368 debug(" no tuile found\n\r");
salco 39:34d7802e8d15 369 #endif
salco 37:f53e9f7a14df 370 signed char newPosX = x;
salco 37:f53e9f7a14df 371 signed char newPosY = y;
salco 37:f53e9f7a14df 372
salco 37:f53e9f7a14df 373 getCoordoner(newPosX,newPosY);
salco 37:f53e9f7a14df 374 addMap(newPosX,newPosY);
salco 37:f53e9f7a14df 375 result = showMap(x,y);
salco 37:f53e9f7a14df 376 #ifdef DEGUG_LABIRINTH_SET_COORDONER
salco 37:f53e9f7a14df 377 debug(" result: %i\n\r",result.size());
salco 37:f53e9f7a14df 378 #endif
salco 39:34d7802e8d15 379 }
salco 36:474d4795aafa 380
salco 39:34d7802e8d15 381 if(result.size() != 0)
salco 39:34d7802e8d15 382 {
salco 39:34d7802e8d15 383 #ifdef DEGUG_LABIRINTH_SET_COORDONER
salco 39:34d7802e8d15 384 debug(" tuile found\n\r");
salco 39:34d7802e8d15 385 #endif
salco 39:34d7802e8d15 386 result[cX-1]=value;
salco 39:34d7802e8d15 387 updateMap(result,x,y);//on remet les case modifier dans le string==map
salco 37:f53e9f7a14df 388 }
salco 39:34d7802e8d15 389 //}
salco 37:f53e9f7a14df 390
salco 37:f53e9f7a14df 391 #ifdef DEGUG_LABIRINTH_SET_COORDONER
salco 37:f53e9f7a14df 392 debug("---------------------\n\r");
salco 37:f53e9f7a14df 393 #endif
salco 28:ac5c6350ed9a 394 }
salco 36:474d4795aafa 395 void Labyrinthe::setC(case_t value, coordonerr cX)
salco 28:ac5c6350ed9a 396 {
salco 28:ac5c6350ed9a 397 setC(value,m_posX, m_posY,cX);
salco 28:ac5c6350ed9a 398 }
salco 37:f53e9f7a14df 399 void Labyrinthe::setC(case_t value, signed char x, signed char y)
salco 28:ac5c6350ed9a 400 {
salco 37:f53e9f7a14df 401 signed char newPosX = x;
salco 37:f53e9f7a14df 402 signed char newPosY = y;
salco 36:474d4795aafa 403 coordonerr maCoordoner;
salco 28:ac5c6350ed9a 404 maCoordoner=getCoordoner(newPosX,newPosY);
salco 39:34d7802e8d15 405 #if defined(DEGUG_LABIRINTH_GET_CASE)
salco 39:34d7802e8d15 406 debug("\n\r-setcase tempo newPosX: %i, x: %i\n\r",newPosX,x);
salco 39:34d7802e8d15 407 #endif
salco 28:ac5c6350ed9a 408 setC(value,x,y,maCoordoner);
salco 28:ac5c6350ed9a 409 }
salco 36:474d4795aafa 410 void Labyrinthe::setC_Up(case_t value)
salco 28:ac5c6350ed9a 411 {
salco 28:ac5c6350ed9a 412 setC(value,m_posX, m_posY+1);
salco 28:ac5c6350ed9a 413 }
salco 36:474d4795aafa 414 void Labyrinthe::setC_Down(case_t value)
salco 28:ac5c6350ed9a 415 {
salco 28:ac5c6350ed9a 416 setC(value,m_posX, m_posY-1);
salco 28:ac5c6350ed9a 417 }
salco 36:474d4795aafa 418 void Labyrinthe::setC_Left(case_t value)
salco 28:ac5c6350ed9a 419 {
salco 28:ac5c6350ed9a 420 setC(value,m_posX-1, m_posY);
salco 28:ac5c6350ed9a 421 }
salco 36:474d4795aafa 422 void Labyrinthe::setC_Right(case_t value)
salco 28:ac5c6350ed9a 423 {
salco 28:ac5c6350ed9a 424 setC(value,m_posX+1, m_posY);
salco 35:d81f6b927932 425 }
salco 36:474d4795aafa 426 void Labyrinthe::setMyPos(case_t value)
salco 35:d81f6b927932 427 {
salco 35:d81f6b927932 428 setC(value, m_posX, m_posY);
salco 38:57d5f36a0333 429 }
salco 38:57d5f36a0333 430 char Labyrinthe::caseToChar(case_t value)
salco 38:57d5f36a0333 431 {
salco 38:57d5f36a0333 432 char result = 0;
salco 38:57d5f36a0333 433
salco 38:57d5f36a0333 434 switch(value)
salco 38:57d5f36a0333 435 {
salco 39:34d7802e8d15 436 //case error:
salco 39:34d7802e8d15 437 // result = 'X';
salco 39:34d7802e8d15 438 // break;
salco 38:57d5f36a0333 439 case pasExplorer:
salco 38:57d5f36a0333 440 result = '*';
salco 38:57d5f36a0333 441 break;
salco 38:57d5f36a0333 442 case explorer:
salco 38:57d5f36a0333 443 result = 'E';
salco 38:57d5f36a0333 444 break;
salco 38:57d5f36a0333 445 case mur:
salco 38:57d5f36a0333 446 result = 'M';
salco 38:57d5f36a0333 447 break;
salco 38:57d5f36a0333 448 case vide:
salco 38:57d5f36a0333 449 result = 'V';
salco 38:57d5f36a0333 450 break;
salco 38:57d5f36a0333 451 }
salco 38:57d5f36a0333 452 return result;
salco 38:57d5f36a0333 453 }
salco 38:57d5f36a0333 454 void Labyrinthe::moveFoward(char dir)
salco 38:57d5f36a0333 455 {
salco 38:57d5f36a0333 456 switch(dir)
salco 38:57d5f36a0333 457 {
salco 38:57d5f36a0333 458 case UP:
salco 38:57d5f36a0333 459 //m_posX+=0;
salco 38:57d5f36a0333 460 m_posY++;
salco 38:57d5f36a0333 461 break;
salco 38:57d5f36a0333 462 case DOWN:
salco 38:57d5f36a0333 463 //m_posX+=0;
salco 38:57d5f36a0333 464 m_posY--;
salco 38:57d5f36a0333 465 break;
salco 38:57d5f36a0333 466 case LEFT:
salco 38:57d5f36a0333 467 m_posX--;
salco 38:57d5f36a0333 468 //m_posY+=0;
salco 38:57d5f36a0333 469 break;
salco 38:57d5f36a0333 470 case RIGHT:
salco 38:57d5f36a0333 471 m_posX++;
salco 38:57d5f36a0333 472 //m_posY+=0;
salco 38:57d5f36a0333 473 break;
salco 38:57d5f36a0333 474 }
salco 38:57d5f36a0333 475 }
salco 38:57d5f36a0333 476 void Labyrinthe::moveBackward(char dir)
salco 38:57d5f36a0333 477 {
salco 38:57d5f36a0333 478 switch(dir)
salco 38:57d5f36a0333 479 {
salco 38:57d5f36a0333 480 case UP:
salco 38:57d5f36a0333 481 //m_posX+=0;
salco 38:57d5f36a0333 482 m_posY--;
salco 38:57d5f36a0333 483 break;
salco 38:57d5f36a0333 484 case DOWN:
salco 38:57d5f36a0333 485 //m_posX+=0;
salco 38:57d5f36a0333 486 m_posY++;
salco 38:57d5f36a0333 487 break;
salco 38:57d5f36a0333 488 case LEFT:
salco 38:57d5f36a0333 489 m_posX++;
salco 38:57d5f36a0333 490 //m_posY+=0;
salco 38:57d5f36a0333 491 break;
salco 38:57d5f36a0333 492 case RIGHT:
salco 38:57d5f36a0333 493 m_posX--;
salco 38:57d5f36a0333 494 //m_posY+=0;
salco 38:57d5f36a0333 495 break;
salco 38:57d5f36a0333 496 }
salco 38:57d5f36a0333 497 }
salco 38:57d5f36a0333 498 void Labyrinthe::moveToLeft(char dir)
salco 38:57d5f36a0333 499 {
salco 38:57d5f36a0333 500 switch(dir)
salco 38:57d5f36a0333 501 {
salco 38:57d5f36a0333 502 case UP:
salco 38:57d5f36a0333 503 m_posX--;
salco 38:57d5f36a0333 504 //m_posY+=0;
salco 38:57d5f36a0333 505 break;
salco 38:57d5f36a0333 506 case DOWN:
salco 38:57d5f36a0333 507 m_posX++;
salco 38:57d5f36a0333 508 //m_posY+=0;
salco 38:57d5f36a0333 509 break;
salco 38:57d5f36a0333 510 case LEFT:
salco 38:57d5f36a0333 511 //m_posX+=0;
salco 38:57d5f36a0333 512 m_posY--;
salco 38:57d5f36a0333 513 break;
salco 38:57d5f36a0333 514 case RIGHT:
salco 38:57d5f36a0333 515 //m_posX+=0;
salco 38:57d5f36a0333 516 m_posY++;
salco 38:57d5f36a0333 517 break;
salco 38:57d5f36a0333 518 }
salco 38:57d5f36a0333 519 }
salco 38:57d5f36a0333 520 void Labyrinthe::moveToRight(char dir)
salco 38:57d5f36a0333 521 {
salco 38:57d5f36a0333 522 switch(dir)
salco 38:57d5f36a0333 523 {
salco 38:57d5f36a0333 524 case UP:
salco 38:57d5f36a0333 525 m_posX++;
salco 38:57d5f36a0333 526 //m_posY+=0;
salco 38:57d5f36a0333 527 break;
salco 38:57d5f36a0333 528 case DOWN:
salco 38:57d5f36a0333 529 m_posX--;
salco 38:57d5f36a0333 530 //m_posY+=0;
salco 38:57d5f36a0333 531 break;
salco 38:57d5f36a0333 532 case LEFT:
salco 38:57d5f36a0333 533 //m_posX+=0;
salco 38:57d5f36a0333 534 m_posY++;
salco 38:57d5f36a0333 535 break;
salco 38:57d5f36a0333 536 case RIGHT:
salco 38:57d5f36a0333 537 //m_posX+=0;
salco 38:57d5f36a0333 538 m_posY--;
salco 38:57d5f36a0333 539 break;
salco 38:57d5f36a0333 540 }
salco 38:57d5f36a0333 541 }
salco 38:57d5f36a0333 542 case_t Labyrinthe::getC_Foward(char dir)
salco 38:57d5f36a0333 543 {
salco 39:34d7802e8d15 544 case_t result = pasExplorer;//error;
salco 38:57d5f36a0333 545
salco 38:57d5f36a0333 546 switch(dir)
salco 38:57d5f36a0333 547 {
salco 38:57d5f36a0333 548 case UP:
salco 39:34d7802e8d15 549 #if defined(DEGUG_LABIRINTH_GET_CASE)
salco 38:57d5f36a0333 550 debug("m_posX:%i m_posY+1:%i\n\r",m_posX,m_posY+1);
salco 39:34d7802e8d15 551 #endif
salco 38:57d5f36a0333 552 result = getC(m_posX,m_posY+1);
salco 39:34d7802e8d15 553 #if defined(DEGUG_LABIRINTH_GET_CASE)
salco 38:57d5f36a0333 554 debug("result:%i",result);
salco 39:34d7802e8d15 555 #endif
salco 38:57d5f36a0333 556 break;
salco 38:57d5f36a0333 557 case DOWN:
salco 38:57d5f36a0333 558 result = getC(m_posX,m_posY-1);
salco 38:57d5f36a0333 559 break;
salco 38:57d5f36a0333 560 case LEFT:
salco 38:57d5f36a0333 561 result = getC(m_posX-1,m_posY);
salco 38:57d5f36a0333 562 break;
salco 38:57d5f36a0333 563 case RIGHT:
salco 38:57d5f36a0333 564 result = getC(m_posX+1,m_posY);
salco 38:57d5f36a0333 565 break;
salco 38:57d5f36a0333 566 }
salco 38:57d5f36a0333 567 return result;
salco 38:57d5f36a0333 568 }
salco 38:57d5f36a0333 569 case_t Labyrinthe::getC_Backward(char dir)
salco 38:57d5f36a0333 570 {
salco 39:34d7802e8d15 571 case_t result = mur;// error;
salco 38:57d5f36a0333 572
salco 38:57d5f36a0333 573 switch(dir)
salco 38:57d5f36a0333 574 {
salco 38:57d5f36a0333 575 case UP:
salco 38:57d5f36a0333 576 result = getC(m_posX,m_posY-1);
salco 38:57d5f36a0333 577 break;
salco 38:57d5f36a0333 578 case DOWN:
salco 38:57d5f36a0333 579 result = getC(m_posX,m_posY+1);
salco 38:57d5f36a0333 580 break;
salco 38:57d5f36a0333 581 case LEFT:
salco 38:57d5f36a0333 582 result = getC(m_posX+1,m_posY);
salco 38:57d5f36a0333 583 break;
salco 38:57d5f36a0333 584 case RIGHT:
salco 38:57d5f36a0333 585 result = getC(m_posX-1,m_posY);
salco 38:57d5f36a0333 586 break;
salco 38:57d5f36a0333 587 }
salco 38:57d5f36a0333 588 return result;
salco 38:57d5f36a0333 589 }
salco 38:57d5f36a0333 590 case_t Labyrinthe::getC_ToLeft(char dir)
salco 38:57d5f36a0333 591 {
salco 39:34d7802e8d15 592 case_t result = mur;//error;
salco 38:57d5f36a0333 593
salco 38:57d5f36a0333 594 switch(dir)
salco 38:57d5f36a0333 595 {
salco 38:57d5f36a0333 596 case UP:
salco 38:57d5f36a0333 597 result = getC(m_posX-1,m_posY);
salco 38:57d5f36a0333 598 break;
salco 38:57d5f36a0333 599 case DOWN:
salco 38:57d5f36a0333 600 result = getC(m_posX+1,m_posY);
salco 38:57d5f36a0333 601 break;
salco 38:57d5f36a0333 602 case LEFT:
salco 38:57d5f36a0333 603 result = getC(m_posX,m_posY-1);
salco 38:57d5f36a0333 604 break;
salco 38:57d5f36a0333 605 case RIGHT:
salco 38:57d5f36a0333 606 result = getC(m_posX,m_posY+1);
salco 38:57d5f36a0333 607 break;
salco 38:57d5f36a0333 608 }
salco 38:57d5f36a0333 609 return result;
salco 38:57d5f36a0333 610 }
salco 38:57d5f36a0333 611 case_t Labyrinthe::getC_ToRight(char dir)
salco 38:57d5f36a0333 612 {
salco 39:34d7802e8d15 613 case_t result = pasExplorer;//error;
salco 38:57d5f36a0333 614
salco 38:57d5f36a0333 615 switch(dir)
salco 38:57d5f36a0333 616 {
salco 38:57d5f36a0333 617 case UP:
salco 38:57d5f36a0333 618 result = getC(m_posX+1,m_posY);
salco 38:57d5f36a0333 619 break;
salco 38:57d5f36a0333 620 case DOWN:
salco 38:57d5f36a0333 621 result = getC(m_posX-1,m_posY);
salco 38:57d5f36a0333 622 break;
salco 38:57d5f36a0333 623 case LEFT:
salco 38:57d5f36a0333 624 result = getC(m_posX,m_posY+1);
salco 38:57d5f36a0333 625 break;
salco 38:57d5f36a0333 626 case RIGHT:
salco 38:57d5f36a0333 627 result = getC(m_posX,m_posY-1);
salco 38:57d5f36a0333 628 break;
salco 38:57d5f36a0333 629 }
salco 38:57d5f36a0333 630 return result;
salco 38:57d5f36a0333 631 }
salco 38:57d5f36a0333 632
salco 38:57d5f36a0333 633
salco 38:57d5f36a0333 634 void Labyrinthe::turnBack(void)
salco 38:57d5f36a0333 635 {
salco 38:57d5f36a0333 636 switch(direction)
salco 38:57d5f36a0333 637 {
salco 38:57d5f36a0333 638 case UP:
salco 38:57d5f36a0333 639 direction = DOWN;
salco 38:57d5f36a0333 640 break;
salco 38:57d5f36a0333 641 case DOWN:
salco 38:57d5f36a0333 642 direction = UP;
salco 38:57d5f36a0333 643 break;
salco 38:57d5f36a0333 644 case LEFT:
salco 38:57d5f36a0333 645 direction = RIGHT;
salco 38:57d5f36a0333 646 break;
salco 38:57d5f36a0333 647 case RIGHT:
salco 38:57d5f36a0333 648 direction = LEFT;
salco 38:57d5f36a0333 649 break;
salco 38:57d5f36a0333 650 }
salco 38:57d5f36a0333 651
salco 38:57d5f36a0333 652 }
salco 38:57d5f36a0333 653 void Labyrinthe::turnLeft(void)
salco 38:57d5f36a0333 654 {
salco 38:57d5f36a0333 655 switch(direction)
salco 38:57d5f36a0333 656 {
salco 38:57d5f36a0333 657 case UP:
salco 38:57d5f36a0333 658 direction = LEFT;
salco 38:57d5f36a0333 659 break;
salco 38:57d5f36a0333 660 case DOWN:
salco 38:57d5f36a0333 661 direction = RIGHT;
salco 38:57d5f36a0333 662 break;
salco 38:57d5f36a0333 663 case LEFT:
salco 38:57d5f36a0333 664 direction = DOWN;
salco 38:57d5f36a0333 665 break;
salco 38:57d5f36a0333 666 case RIGHT:
salco 38:57d5f36a0333 667 direction = UP;
salco 38:57d5f36a0333 668 break;
salco 38:57d5f36a0333 669 }
salco 38:57d5f36a0333 670 }
salco 38:57d5f36a0333 671 void Labyrinthe::turnRight(void)
salco 38:57d5f36a0333 672 {
salco 38:57d5f36a0333 673 switch(direction)
salco 38:57d5f36a0333 674 {
salco 38:57d5f36a0333 675 case UP:
salco 38:57d5f36a0333 676 direction = RIGHT;
salco 38:57d5f36a0333 677 break;
salco 38:57d5f36a0333 678 case DOWN:
salco 38:57d5f36a0333 679 direction = LEFT;
salco 38:57d5f36a0333 680 break;
salco 38:57d5f36a0333 681 case LEFT:
salco 38:57d5f36a0333 682 direction = UP;
salco 38:57d5f36a0333 683 break;
salco 38:57d5f36a0333 684 case RIGHT:
salco 38:57d5f36a0333 685 direction = DOWN;
salco 38:57d5f36a0333 686 break;
salco 38:57d5f36a0333 687 }
salco 39:34d7802e8d15 688 }
salco 39:34d7802e8d15 689
salco 39:34d7802e8d15 690
salco 39:34d7802e8d15 691 void Labyrinthe::getXY_Foward(signed char &x, signed char &y,char dir)
salco 39:34d7802e8d15 692 {
salco 39:34d7802e8d15 693 switch(direction)
salco 39:34d7802e8d15 694 {
salco 39:34d7802e8d15 695 case UP:
salco 39:34d7802e8d15 696 x = m_posX;
salco 39:34d7802e8d15 697 y = m_posY+1;
salco 39:34d7802e8d15 698 break;
salco 39:34d7802e8d15 699 case DOWN:
salco 39:34d7802e8d15 700 x = m_posX;
salco 39:34d7802e8d15 701 y = m_posY-1;
salco 39:34d7802e8d15 702 break;
salco 39:34d7802e8d15 703 case LEFT:
salco 39:34d7802e8d15 704 x = m_posX-1;
salco 39:34d7802e8d15 705 y = m_posY;
salco 39:34d7802e8d15 706 break;
salco 39:34d7802e8d15 707 case RIGHT:
salco 39:34d7802e8d15 708 x = m_posX+1;
salco 39:34d7802e8d15 709 y = m_posY;
salco 39:34d7802e8d15 710 break;
salco 39:34d7802e8d15 711 }
salco 39:34d7802e8d15 712 }
salco 39:34d7802e8d15 713
salco 39:34d7802e8d15 714 void Labyrinthe::getXY_Backward(signed char &x, signed char &y,char dir)
salco 39:34d7802e8d15 715 {
salco 39:34d7802e8d15 716 switch(direction)
salco 39:34d7802e8d15 717 {
salco 39:34d7802e8d15 718 case UP:
salco 39:34d7802e8d15 719 x = m_posX;
salco 39:34d7802e8d15 720 y = m_posY-1;
salco 39:34d7802e8d15 721 break;
salco 39:34d7802e8d15 722 case DOWN:
salco 39:34d7802e8d15 723 x = m_posX;
salco 39:34d7802e8d15 724 y = m_posY+1;
salco 39:34d7802e8d15 725 break;
salco 39:34d7802e8d15 726 case LEFT:
salco 39:34d7802e8d15 727 x = m_posX+1;
salco 39:34d7802e8d15 728 y = m_posY;
salco 39:34d7802e8d15 729 break;
salco 39:34d7802e8d15 730 case RIGHT:
salco 39:34d7802e8d15 731 x = m_posX-1;
salco 39:34d7802e8d15 732 y = m_posY;
salco 39:34d7802e8d15 733 break;
salco 39:34d7802e8d15 734 }
salco 39:34d7802e8d15 735 }
salco 39:34d7802e8d15 736
salco 39:34d7802e8d15 737 void Labyrinthe::getXY_Left(signed char &x, signed char &y, char dir)
salco 39:34d7802e8d15 738 {
salco 39:34d7802e8d15 739 switch(direction)
salco 39:34d7802e8d15 740 {
salco 39:34d7802e8d15 741 case UP:
salco 39:34d7802e8d15 742 x = m_posX-1;
salco 39:34d7802e8d15 743 y = m_posY;
salco 39:34d7802e8d15 744 break;
salco 39:34d7802e8d15 745 case DOWN:
salco 39:34d7802e8d15 746 x = m_posX+1;
salco 39:34d7802e8d15 747 y = m_posY;
salco 39:34d7802e8d15 748 break;
salco 39:34d7802e8d15 749 case LEFT:
salco 39:34d7802e8d15 750 x = m_posX;
salco 39:34d7802e8d15 751 y = m_posY-1;
salco 39:34d7802e8d15 752 break;
salco 39:34d7802e8d15 753 case RIGHT:
salco 39:34d7802e8d15 754 x = m_posX;
salco 39:34d7802e8d15 755 y = m_posY+1;
salco 39:34d7802e8d15 756 break;
salco 39:34d7802e8d15 757 }
salco 39:34d7802e8d15 758 }
salco 39:34d7802e8d15 759
salco 39:34d7802e8d15 760 void Labyrinthe::getXY_Right(signed char &x, signed char &y, char dir)
salco 39:34d7802e8d15 761 {
salco 39:34d7802e8d15 762 switch(direction)
salco 39:34d7802e8d15 763 {
salco 39:34d7802e8d15 764 case UP:
salco 39:34d7802e8d15 765 x = m_posX+1;
salco 39:34d7802e8d15 766 y = m_posY;
salco 39:34d7802e8d15 767 break;
salco 39:34d7802e8d15 768 case DOWN:
salco 39:34d7802e8d15 769 x = m_posX-1;
salco 39:34d7802e8d15 770 y = m_posY;
salco 39:34d7802e8d15 771 break;
salco 39:34d7802e8d15 772 case LEFT:
salco 39:34d7802e8d15 773 x = m_posX;
salco 39:34d7802e8d15 774 y = m_posY+1;
salco 39:34d7802e8d15 775 break;
salco 39:34d7802e8d15 776 case RIGHT:
salco 39:34d7802e8d15 777 x = m_posX;
salco 39:34d7802e8d15 778 y = m_posY-1;
salco 39:34d7802e8d15 779 break;
salco 39:34d7802e8d15 780 }
salco 39:34d7802e8d15 781 }