BastatDoreau / Mbed 2 deprecated MoveYourTetris

Dependencies:   mbed APDS_9960 mbed-rtos

Dependents:   MoveYourTetris_OK

Revision:
11:c37922a0a915
Parent:
10:9ef3f520ff6c
Child:
12:7afdbc7465ac
--- a/src/cMatrice.cpp	Thu Apr 07 15:24:07 2016 +0000
+++ b/src/cMatrice.cpp	Sun Apr 10 17:46:03 2016 +0000
@@ -13,19 +13,19 @@
     _lig = l;
     _col = c;
     _matrice = new unsigned char*[_lig];
-	for(unsigned char i = 0; i < _lig; i++){
-		_matrice[i] = new unsigned char[_col];
-	}
-	clear();
+    for(unsigned char i = 0; i < _lig; i++) {
+        _matrice[i] = new unsigned char[_col];
+    }
+    clear();
 }
 
 // DESTRUCTEUR
 cMatrice::~cMatrice()
 {
-	for(unsigned char i = 0; i < _lig; i++){
-		delete[] _matrice[i];
-		delete[] _matrice;	
-	}
+    for(unsigned char i = 0; i < _lig; i++) {
+        delete[] _matrice[i];
+        delete[] _matrice;
+    }
 }
 
 // GETTER
@@ -34,22 +34,30 @@
     return _matrice[l][c];
 }
 
-unsigned char cMatrice::getCol(){
-	return _col;	
+unsigned char cMatrice::getCol()
+{
+    return _col;
 }
 
-unsigned char cMatrice::getLig(){
-	return _lig;
+unsigned char cMatrice::getLig()
+{
+    return _lig;
 }
 
+cForme* cMatrice::get_pForme()
+{
+    return _pForme;
+}
 // SETTER
 
-void cMatrice::setCol(unsigned char c){
-	_col = c;
+void cMatrice::setCol(unsigned char c)
+{
+    _col = c;
 }
 
-void cMatrice::setLig(unsigned char l){
-	_lig = l;
+void cMatrice::setLig(unsigned char l)
+{
+    _lig = l;
 }
 
 
@@ -60,11 +68,12 @@
 //  c: Couleur
 void cMatrice::afficherForme(cForme* f, unsigned char c)
 {
-	_pForme = f;
-// Changement de couleur des Leds
+    _pForme = f;
+    // Changement de couleur des Leds
     for (int i = 0; i < 4; i++) {
+        _pForme->getLed(i).setCouleur(c);
         _matrice[_pForme->getLed(i).getPositionX()][_pForme->getLed(i).getPositionY()] = c;
-        _pForme->getLed(i).setCouleur(c);
+
     }
 }
 
@@ -73,25 +82,133 @@
 //  Nettoyage de la matrice, passage à 0 de la valeur de chaque Led
 void cMatrice::clear()
 {
-	for(unsigned char i = 0; i < _lig; i++){
-		for(unsigned char j = 0; j < _col; j++){
-			_matrice[i][j] = LED_NOIR;
-		}
-	}
-	_matrice[0][0] = LED_ROUGE;
+    for(unsigned char i = 0; i < _lig; i++) {
+        for(unsigned char j = 0; j < _col; j++) {
+            _matrice[i][j] = LED_NOIR;
+        }
+    }
+    _matrice[0][0] = LED_ROUGE;
 }
 
-int cMatrice::updateMatrice()
+void cMatrice::updateMatrice()
 {
-	
-	// On éteint les leds de la pièce
-	for (int i = 0; i < 4; i++) {
+    // On éteint les leds de la pièce
+    for (int i = 0; i < 4; i++) {
         _matrice[_pForme->getLed(i).getOldPositionX()][_pForme->getLed(i).getOldPositionY()] = LED_NOIR;
     }
     // Affichage de la nouvelle position
-    afficherForme(_pForme, _pForme->getLed(1).getCouleur());
+    afficherForme(_pForme, _pForme->getLed(0).getCouleur());
     ///////////////////////////////////////////////////////////////////////////////////////////////
     // Controle de la collision avec les bords
     ///////////////////////////////////////////////////////////////////////////////////////////////
-    return 1;
 }
+
+unsigned char cMatrice::verificationMvt(unsigned char c)
+{
+    unsigned char result = 0;
+    Serial pc(USBTX, USBRX);
+    /*unsigned char position[4][2]= {0};
+    unsigned char positionXMin = 7;
+    unsigned char positionXMax = 0;
+    unsigned char positionYMax = 0;
+
+    //on cherche la coordonnées de la/les LED(s) de la pièce la/les plus basse(s)
+    for (int i = 0; i < 4; i++) {
+        if(_pForme->getLed(i).getPositionX() > position[i][0]) {
+            position[i][0] = _pForme->getLed(i).getPositionX();
+        }
+        if(_pForme->getLed(i).getPositionY() > position[i][1]) {
+            position[i][1] = _pForme->getLed(i).getPositionY();
+        }
+    }
+
+    for (int i = 0; i < 4; i++) {
+        if(position[i][0] > positionXMax) {
+            positionXMax = position[i][0];
+        } else if(position[i][0] < positionXMin) {
+            positionXMin = position[i][0];
+        }
+        if (position[i][1] > positionYMax) {
+            positionYMax = position[i][1];
+        }
+    }
+        pc.printf("Xmin= %d, Xmax= %d, Ymax = %d \n", positionXMin, positionXMax, positionYMax);
+    */
+    //POUR UN L
+    if(_pForme->getTypeForme() == 4) {
+
+        switch(_pForme->getOrientation()) {
+                //En orientation de base:
+            case 1: {
+                //Si la LED en dessous de la LED 0 est noire
+                if(_matrice[_pForme->getLed(0).getPositionX()][_pForme->getLed(0).getPositionY() + 1] == LED_NOIR) {
+                    //Et si la LED en dessous de la LED 2 est noire
+                    if(_matrice[_pForme->getLed(2).getPositionX()][_pForme->getLed(2).getPositionY() + 1] == LED_NOIR) {
+                        //Et si la LED en dessous de la LED 3 est noire
+                        if(_matrice[_pForme->getLed(3).getPositionX()][_pForme->getLed(3).getPositionY() + 1] == LED_NOIR) {
+                            //alors on peut descendre la piece
+                            result = 1;
+                        }
+                    }
+                }
+                break;
+            }
+            //En orientation 2:
+            case 2: {
+                //Si la LED en dessous de la LED 0 est noire
+                if(_matrice[_pForme->getLed(0).getPositionX()][_pForme->getLed(0).getPositionY() + 1] == LED_NOIR) {
+                    //Et si la LED en dessous de la LED 3 est noire
+                    if(_matrice[_pForme->getLed(3).getPositionX()][_pForme->getLed(3).getPositionY() + 1] == LED_NOIR) {
+                        //alors on peut descendre la piece
+                        result = 1;
+                    }
+
+                }
+                break;
+            }
+            //En orientation 3:
+            case 3: {
+                //Si la LED en dessous de la LED 1 est noire
+                if(_matrice[_pForme->getLed(1).getPositionX()][_pForme->getLed(1).getPositionY() + 1] == LED_NOIR) {
+                    //Et si la LED en dessous de la LED 2 est noire
+                    if(_matrice[_pForme->getLed(2).getPositionX()][_pForme->getLed(2).getPositionY() + 1] == LED_NOIR) {
+                        //Et si la LED en dessous de la LED 3 est noire
+                        if(_matrice[_pForme->getLed(3).getPositionX()][_pForme->getLed(3).getPositionY() + 1] == LED_NOIR) {
+                            //alors on peut descendre la piece
+                            result = 1;
+                        }
+                    }
+                }
+                break;
+            }
+            //En orientation 4:
+            case 4: {
+                //Si la LED en dessous de la LED 0 est noire
+                if(_matrice[_pForme->getLed(0).getPositionX()][_pForme->getLed(0).getPositionY() + 1] == LED_NOIR) {
+                    //Et si la LED en dessous de la LED 1 est noire
+                    if(_matrice[_pForme->getLed(1).getPositionX()][_pForme->getLed(1).getPositionY() + 1] == LED_NOIR) {
+                        //alors on peut descendre la piece
+                        result = 1;
+                    }
+                }
+                break;
+            }
+        }
+    }
+
+
+    pc.printf("%d\n", result);
+
+
+
+
+    /* switch(c) {
+             //si c'est un déplacement vers le bas
+         case 'b': {
+     if(
+             break;
+         }
+
+     }*/
+    return result;
+}