BastatDoreau / Mbed 2 deprecated MoveYourTetris

Dependencies:   mbed APDS_9960 mbed-rtos

Dependents:   MoveYourTetris_OK

src/cMatrice.cpp

Committer:
clementdoreau
Date:
2016-04-20
Revision:
29:95469b25e187
Parent:
28:e932eb039271
Child:
30:c647da947bd9

File content as of revision 29:95469b25e187:

#include "cMatrice.h"
#include <algorithm>

// CONSTRUCTEURS

cMatrice::cMatrice()
{
    _lig = 0;
    _col = 0;
}

cMatrice::cMatrice(unsigned int c, unsigned int l)
{
    _lig = l;
    _col = c;
    _matrice = new unsigned int*[_lig];
    for(unsigned int i = 0; i < _lig; i++) {
        _matrice[i] = new unsigned int[_col];
    }
    clear();
}

// DESTRUCTEUR
cMatrice::~cMatrice()
{
    for(unsigned int i = 0; i < _lig; i++) {
        delete[] _matrice[i];
        delete[] _matrice;
    }
}

// GETTER
unsigned int cMatrice::getValTab(unsigned int l, unsigned int c)
{
    return _matrice[l][c];
}

unsigned int cMatrice::getCol()
{
    return _col;
}

unsigned int cMatrice::getLig()
{
    return _lig;
}

cForme* cMatrice::get_pForme()
{
    return _pForme;
}
// SETTER

void cMatrice::setCol(unsigned int c)
{
    _col = c;
}

void cMatrice::setLig(unsigned int l)
{
    _lig = l;
}
void cMatrice::setValTab(unsigned int l, unsigned int c, unsigned int coul)
{
    _matrice [l][c] = coul;
}

// METHODES

//      Paramètres:
//  f: Forme à afficher
//  c: Couleur
void cMatrice::afficherForme(cForme* f, unsigned int c)
{
    _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;

    }
}


//      Description:
//  Nettoyage de la matrice, passage à 0 de la valeur de chaque Led
void cMatrice::clear()
{
    for(unsigned int i = 0; i < _lig; i++) {
        for(unsigned int j = 0; j < _col; j++) {
            _matrice[i][j] = LED_NOIR;
        }
    }
    //////////////////////////////////////////////////////////////////////////////////////
    _matrice[0][0] = LED_ROUGE;
    //_matrice[8][0] = LED_ROUGE;
}

void cMatrice::updateMatrice()
{
    // 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(0).getCouleur());
    ///////////////////////////////////////////////////////////////////////////////////////////////
    // Controle de la collision avec les bords
    ///////////////////////////////////////////////////////////////////////////////////////////////
}