Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed APDS_9960 mbed-rtos
Revision 40:08490d120ec4, committed 2016-04-24
- Comitter:
- Willheisen
- Date:
- Sun Apr 24 22:11:55 2016 +0000
- Parent:
- 38:418278e5eb6b
- Commit message:
- VERSION FINALE
Changed in this revision
--- a/src/cCollision.cpp Sun Apr 24 21:35:57 2016 +0000
+++ b/src/cCollision.cpp Sun Apr 24 22:11:55 2016 +0000
@@ -10,9 +10,13 @@
}
+// Descritpion: Détecte du bord droit de la matrice
+//Entrées: f: pièce à tester, m: matrice à tester
+// Sortie : booléen
+// False : Pas de collision
+// True Collision
bool cCollision::bordDroit(cForme &f)
{
-
for(unsigned char j = 0; j < 4; j++) { // On parcourt les leds
if(f.getLed(j).getPositionX() == 7) { // Pour chaque led, si elle est en bout de colonne (droite)
return true; // COLLISION PRESENTE
@@ -21,6 +25,11 @@
return false; // PAS DE COLLISION
}
+// Descritpion: Détecte du bord gauche de la matrice
+//Entrées: f: pièce à tester, m: matrice à tester
+// Sortie : booléen
+// False : Pas de collision
+// True Collision
bool cCollision::bordGauche(cForme &f)
{
for(unsigned char j = 0; j < 4; j++) { // On parcourt les leds
@@ -31,6 +40,11 @@
return false; // PAS DE COLLISION
}
+// Descritpion: Détecte du bas de la matrice
+//Entrées: f: pièce à tester, m: matrice à tester
+// Sortie : booléen
+// False : Pas de collision
+// True Collision
bool cCollision::bordBas(cForme &f, cMatrice &m)
{
bool res = false;
@@ -43,31 +57,19 @@
}
-// Descritpion:
-// Détecte une collision autour de la pièce courante
-// Sortie :
-// False : Pas de collision
-// True Collision
-//
-
-
-
-
-
+// Descritpion: Détection d'une pièce sous la pièce courante
+//Entrées: f: pièce à tester, m: matrice à tester
+// Sortie : booléen
+// False : Pas de collision
+// True Collision
bool cCollision::pieceBas(cForme &f, cMatrice &m)
{
unsigned char test = 1;
-
for(unsigned char i = 0; i < 4; i++) {
- //pc.printf("//////////////////////\n", i);
- //pc.printf("I = %d\n", i);
if(m.getValTab(f.getLed(i).getPositionX(), f.getLed(i).getPositionY() + 1) != LED_NOIR) { // SI la led sous la led courante n'est pas noire
- //pc.printf("Collision__\n", i);
test = 1;
for(unsigned char j = 0; j < 4; j++) {
- // pc.printf("J = %d\n", j);
if(f.getLed(i).getPositionY() + 1 == f.getLed(j).getPositionY() && f.getLed(i).getPositionX() == f.getLed(j).getPositionX()) {
- // pc.printf("liberation__\n", i);
test = 0;
}
}
@@ -76,29 +78,22 @@
}
}
}
-
return false;
}
-// Descritpion:
-// Détecte une collision autour de la pièce courante
-// Sortie :
-// False : Pas de collision
-// True Collision
-//
+// Descritpion: Détection d'une pièce à gauche de la pièce courante
+//Entrées: f: pièce à tester, m: matrice à tester
+// Sortie : booléen
+// False : Pas de collision
+// True Collision
bool cCollision::pieceGauche( cForme &f, cMatrice &m)
{
unsigned char test = 1;
for(unsigned char i = 0; i < 4; i++) {
- //pc.printf("//////////////////////\n", i);
- //pc.printf("I = %d\n", i);
if(m.getValTab(f.getLed(i).getPositionX() - 1, f.getLed(i).getPositionY()) != LED_NOIR) { // SI la led sous la led courante n'est pas noire
- //pc.printf("Collision__\n", i);
test = 1;
for(unsigned char j = 0; j < 4; j++) {
- // pc.printf("J = %d\n", j);
if(f.getLed(i).getPositionX() - 1 == f.getLed(j).getPositionX() && f.getLed(i).getPositionY() == f.getLed(j).getPositionY()) {
- // pc.printf("liberation__\n", i);
test = 0;
}
}
@@ -107,28 +102,22 @@
}
}
}
-
return false;
}
-// Descritpion:
-// Détecte une collision autour de la pièce courante
-// Sortie :
-// False : Pas de collision
-// True Collision
-//
+
+// Descritpion: Détection d'une pièce à droite de la pièce courante
+//Entrées: f: pièce à tester, m: matrice à tester
+// Sortie : booléen
+// False : Pas de collision
+// True Collision
bool cCollision::pieceDroite(cForme &f, cMatrice &m)
{
unsigned char test = 1;
for(unsigned char i = 0; i < 4; i++) {
- //pc.printf("//////////////////////\n", i);
- //pc.printf("I = %d\n", i);
- if(m.getValTab(f.getLed(i).getPositionX() + 1, f.getLed(i).getPositionY()) != LED_NOIR) { // SI la led sous la led courante n'est pas noire
- //pc.printf("Collision__\n", i);
+ if(m.getValTab(f.getLed(i).getPositionX() + 1, f.getLed(i).getPositionY()) != LED_NOIR) { // SI la led sous la led courante n'est pas noire
test = 1;
for(unsigned char j = 0; j < 4; j++) {
- // pc.printf("J = %d\n", j);
if(f.getLed(i).getPositionX() + 1 == f.getLed(j).getPositionX() && f.getLed(i).getPositionY() == f.getLed(j).getPositionY()) {
- // pc.printf("liberation__\n", i);
test = 0;
}
}
@@ -137,6 +126,5 @@
}
}
}
-
return false;
}
\ No newline at end of file
--- a/src/cJeu.cpp Sun Apr 24 21:35:57 2016 +0000
+++ b/src/cJeu.cpp Sun Apr 24 22:11:55 2016 +0000
@@ -275,7 +275,6 @@
{
int _mvt = 0;
bool perdu = false;
- Serial pc(USBTX, USBRX);
cCollision col;
/*La boucle suivante correspond à une "manche" du jeu:
On crée une nouvelle pièce.
@@ -288,7 +287,6 @@
while(!perdu) {
//On crée une nouvelle pièce.
nouvellePiece();
- pc.printf("Nouvelle piece\n");
//Si celle-ci ne peut pas descendre, c'est que la matrice est remplie donc que le joueur a perdu.
if(col.pieceBas(*_ptrForme, *_mat) == true) {
//On colore toute la matrice en bleue
@@ -326,48 +324,37 @@
} else {
_mvt = 0;
}
- pc.printf("Valeur envoyee = %d\n", _mvt);
//Selon la valeur du mouvement, on effectue le mouvement de la pièce correspondant.
//A chaque fois, on test de non-collision est fait avant de faire le mouvement.
switch(_mvt) {
case 1: {
- pc.printf("Rotation...");
if(col.pieceBas(*_ptrForme, *_mat) == false && col.bordBas(*_ptrForme, *_mat) == false) {
_ptrForme->rotationHoraire();
- pc.printf("Ok\n");
}
break;
}
case 2: {
- pc.printf("Deplacement Bas..");
while(col.pieceBas(*_ptrForme, *_mat) == false && col.bordBas(*_ptrForme, *_mat) == false) {
_ptrForme->deplacementBas();
_mat->updateMatrice();
_spi.envoyerMatrice(*_mat);
}
- pc.printf("Ok\n");
break;
}
case 3: {
- pc.printf("Deplacement Gauche...");
if(col.pieceGauche(*_ptrForme, *_mat) == false && col.bordGauche(*_ptrForme) == false) {
_ptrForme->deplacementGauche();
- pc.printf("Ok\n");
}
break;
}
case 4: {
- pc.printf("Deplacement Droite...\n");
if(col.pieceDroite(*_ptrForme, *_mat) == false && col.bordDroit(*_ptrForme) == false) {
_ptrForme->deplacementDroite();
- pc.printf("Ok\n");
}
break;
}
default: {
- pc.printf("Deplacement Bas...");
_ptrForme->deplacementBas();
- pc.printf("Ok\n");
break;
}
}
@@ -376,11 +363,8 @@
_spi.envoyerMatrice(*_mat);
}
delete _ptrForme;
- pc.printf("Suppression du pointeur\n");
//On regarde si des lignes sont complètes
while(ligneComplete()==1){
- pc.printf("Ligne complete\n");
- pc.printf("score: %d\n", _score);
_spi.envoyerMatrice(*_mat);
wait(0.5);
}
--- a/src/cMatrice.cpp Sun Apr 24 21:35:57 2016 +0000
+++ b/src/cMatrice.cpp Sun Apr 24 22:11:55 2016 +0000
@@ -116,7 +116,6 @@
//Sorties: aucune.
void cMatrice::messageAccueil()
{
- Serial pc (USBTX, USBRX);
int i, j;
//On efface tout le tableau 2D qui ca contenir le message
for(i=0; i<8 ; i++) {
@@ -329,17 +328,6 @@
j++;
matriceMessage[2][j] = coul;
matriceMessage[5][j] = coul;
- pc.printf("j=%d\n", j);
- for(i=6; i>0 ; i--) {
- for(int k=0; k<=j; k++) {
- if(matriceMessage[i][k]) {
- pc.printf("X");
- } else {
- pc.printf(" ");
- }
- }
- pc.printf("\n");
- }
//On "colle" les 16 premières colonnes du message sur la matrice
for(unsigned char i = 0; i < _col; i++) {
for(unsigned char j = 0; j < _lig; j++) {
@@ -353,8 +341,6 @@
//Sorties: aucune.
void cMatrice::decalerMatrice()
{
- Serial pc (USBTX, USBRX);
- int i, j;
for(unsigned char i = 0; i < _col; i++) {
for(unsigned char j = 0; j < _lig; j++) {
_matrice[i][j] = matriceMessage[i][j+decalage];
--- a/src/cSPI.cpp Sun Apr 24 21:35:57 2016 +0000
+++ b/src/cSPI.cpp Sun Apr 24 22:11:55 2016 +0000
@@ -78,31 +78,23 @@
//Sorties: aucune.
void cSPI::envoyerMatrice(cMatrice & mat)
{
- Serial pc(USBTX, USBRX);
_cs = 0;
wait_ms(1);
for(unsigned char i = 0; i < mat.getCol(); i++) {
for(unsigned char j = 0; j < mat.getLig()/2; j ++) {
_spi.write(mat.getValTab(i, j));
if(mat.getValTab(i, j)) {
- pc.printf("1|");
} else {
- pc.printf("0|");
}
}
- pc.printf("\n");
}
- pc.printf("\n");
for(unsigned char i = 0; i < mat.getCol(); i++) {
for(unsigned char j = mat.getLig()/2; j < mat.getLig(); j ++) {
_spi.write(mat.getValTab(i, j));
if(mat.getValTab(i, j)) {
- pc.printf("1|");
} else {
- pc.printf("0|");
}
}
- pc.printf("\n");
}
wait_ms(1);
_cs = 1;