Posez votre question Signaler

Tetris semblait easy-target a codé en C....

casers 49Messages postés 18 novembre 2007Date d'inscription - Dernière réponse le 5 avril 2008 à 20:56
Bonjour,
Tot d'abort je tien a remercier "le père" qui avait été d'une inestimable aide pour mon dernier tp auquel j'ai eu une bonne note.
Maintenant je suis de nouveau en galere avec un prog qui devrai faire tourner tetris.
Ici ce trouve le sous programme sensé produire la rotation d'une piece dans le tableau de jeu principale. L'algorithme me semble sans erreur ( et je ne m'attend en aucun cas que vous tentiez de le comprendre.
Mais j'ai encore une foi vu avec le debugger un truc allucinant. Je met en gras les element de mon allucination.
Dans un premier temps j'insere dans mon tab des valeur, puis dans un second temps j'obtien des valeur completement differente de ce tableau(???!!!). Quelqu'un pourrait m'expliquer comment cela peut etre possible si je ne touche pas au tableau et avec seuelement trois ligne de difference entre le moment ou j'injecte les valeur et celui ou je les ressort.....
Merci du fond du coeur pour l'aide.
Casers Cpadawan
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "Constantes.h"
void RotationPiece(int MatricePlateau[LIGN_PLATEAU][COL_PLATEAU], int sens)
{
// Pour fair tourner une piece nous avons inséré dans celleci un element
// speciale "ELEMENT_PIVOT", celui-ci représente le centre de rotation de
// la piece.
// Dans un premier temps on controle que les elements dynamique de la piece
// peuvent tourner.
// Ensuite on insere dans un tableau les coordonnées des element dynamique
// que l'on doit deplacer.
// Puis finalement on les replace dans la matrice principale en les fesant
// relativement a l'emplacement de l'element pivot.
// L'algorithme de rotation sera expliqué dans l'Architecture Logiciel.
int comp = 0, comp1 = 0, Rotation = 1;
int comp2 = 0, comp3 = 0, comp4 = 1;
int tab[4][1];
int LiPivot = 0, CoPivot = 0;
int LiPiece = 0, CoPiece = 0;
// Initialisation Tableau de sauvegarde.
for ( comp1 = 0; comp1 <= 1; comp1++)
for ( comp = 1; comp <= 4; comp++)
tab[comp1][comp] = 0;
// Recherche et sauvegarde des coordonnées de l'element pivot.
for ( comp1 = 0; comp1 <= LONG_COL; comp1++)
{
for ( comp = 1; comp <= LONG_LIGNE; comp++)
if (MatricePlateau[comp1][comp] == ELEMENT_PIVOT)
{
LiPivot = comp1 ;
CoPivot = comp ;
}
}
// Recherche et sauvegarde des coordonnées des elements dynamiques.
for ( comp2 = 0; comp2 <= LONG_COL; comp2++)
{
for ( comp3 = 1; comp3 <= LONG_LIGNE; comp3++)
if (MatricePlateau[comp2][comp3] == ELEMENT_DYNAMIQUE)
{
tab[comp4][0] = comp2 ;
tab[comp4][1] = comp3 ;

comp4++;
}
}
// Test de Rotation.
for ( comp4 = 1; comp4 <= 4; comp4++)
{
// Changement de variable afin de facilité la lecture.
LiPiece = tab[comp4][0];
CoPiece = tab[comp4][1];

if (sens)
{
if (CoPivot == CoPiece)
{
if (!(MatricePlateau[LiPivot][LiPiece - LiPivot + CoPivot] == ELEMENT_NEUTRE
|| MatricePlateau[LiPivot][LiPiece - LiPivot + CoPivot] == ELEMENT_DYNAMIQUE))
Rotation = 0 ;
}
else if (LiPivot == LiPiece)
{
if (!(MatricePlateau[CoPiece - CoPivot + LiPivot][CoPivot] == ELEMENT_DYNAMIQUE ||
MatricePlateau[CoPiece - CoPivot + LiPivot][CoPivot] == ELEMENT_NEUTRE))
Rotation = 0;
}
else
{
if ( !(LiPiece + CoPiece - LiPivot - CoPivot == 0 ))
{
if (!(MatricePlateau[LiPivot - (LiPiece - LiPivot)][CoPiece] == ELEMENT_DYNAMIQUE ||
MatricePlateau[LiPivot - (LiPiece - LiPivot)][CoPiece] == ELEMENT_NEUTRE))
Rotation = 0;
}
else if ( LiPiece + CoPiece - LiPivot - CoPivot == 0)
{
if (!(MatricePlateau[LiPiece][CoPivot - (CoPiece - CoPivot)] == ELEMENT_DYNAMIQUE ||
MatricePlateau[LiPiece][CoPivot - (CoPiece - CoPivot)] == ELEMENT_NEUTRE))
Rotation = 0;
}
}
}
else
{
if (CoPivot == CoPiece)
{
if(!(MatricePlateau[CoPiece - CoPivot + LiPivot][CoPivot] == ELEMENT_DYNAMIQUE ||
MatricePlateau[CoPiece - CoPivot + LiPivot][CoPivot] == ELEMENT_NEUTRE))
Rotation = 0;
}
else if (LiPivot == LiPiece)
{
if (!(MatricePlateau[LiPivot][LiPiece - LiPivot + CoPivot] == ELEMENT_DYNAMIQUE ||
MatricePlateau[LiPivot][LiPiece - LiPivot + CoPivot] == ELEMENT_NEUTRE))
Rotation = 0;
}
else
{
if ( !(LiPiece + CoPiece == 0 ))
{
if (! (MatricePlateau[LiPiece][CoPivot - (CoPiece - CoPivot)] == ELEMENT_DYNAMIQUE ||
MatricePlateau[LiPiece][CoPivot - (CoPiece - CoPivot)] == ELEMENT_NEUTRE))
Rotation = 0;
}
else if ( LiPiece + CoPiece == 0)
{
if (! (MatricePlateau[LiPivot - (LiPiece - LiPivot)][CoPiece] == ELEMENT_DYNAMIQUE ||
MatricePlateau[LiPivot - (LiPiece - LiPivot)][CoPiece] == ELEMENT_NEUTRE))
Rotation = 0;
}
}
}
}
if (Rotation)
{
for ( comp4 = 1; comp4 <= 4; comp4++)
{
LiPiece = tab[comp4][0];
CoPiece = tab[comp4][1];
if (sens)
{
if (CoPivot == CoPiece)
{
MatricePlateau[LiPiece][CoPiece] = ELEMENT_NEUTRE ;
MatricePlateau[LiPivot][LiPiece - LiPivot + CoPivot] = ELEMENT_DYNAMIQUE ;
}
else if (LiPivot == LiPiece)
{
MatricePlateau[LiPiece][CoPiece] = ELEMENT_NEUTRE ;
MatricePlateau[CoPiece - CoPivot + LiPivot][CoPivot] = ELEMENT_DYNAMIQUE ;
}
else
{
if ( !(LiPiece + CoPiece == 0 ))
{
MatricePlateau[LiPiece][CoPiece] = ELEMENT_NEUTRE ;
MatricePlateau[LiPivot - (LiPiece - LiPivot)][CoPiece] = ELEMENT_DYNAMIQUE ;
}
else if ( LiPiece + CoPiece == 0)
{
MatricePlateau[LiPiece][CoPiece] = ELEMENT_NEUTRE ;
MatricePlateau[LiPiece][CoPivot - (CoPiece - CoPivot)] = ELEMENT_DYNAMIQUE ;
}
}
}
else
{
if (CoPivot == CoPiece)
{
MatricePlateau[LiPiece][CoPiece] = ELEMENT_NEUTRE ;
MatricePlateau[CoPiece - CoPivot + LiPivot][CoPivot] = ELEMENT_DYNAMIQUE ;
}
else if (LiPivot == LiPiece)
{
MatricePlateau[LiPiece][CoPiece] = ELEMENT_NEUTRE ;
MatricePlateau[LiPivot][LiPiece - LiPivot + CoPivot] = ELEMENT_DYNAMIQUE ;
}
else
{
if ( !(LiPiece + CoPiece - LiPivot - CoPivot == 0 ))
{
MatricePlateau[LiPiece][CoPiece] = ELEMENT_NEUTRE ;
MatricePlateau[LiPiece][CoPivot - (CoPiece - CoPivot)] = ELEMENT_DYNAMIQUE ;
}
else if ( LiPiece + CoPiece - LiPivot - CoPivot == 0)
{
MatricePlateau[LiPiece][CoPiece] = ELEMENT_NEUTRE ;
MatricePlateau[LiPivot - (LiPiece - LiPivot)][CoPiece] = ELEMENT_DYNAMIQUE ;
}
}
}
}
}
}
Lire la suite 

Tetris semblait easy-target a codé en C »

2 réponses
Réponse
+0
moins plus
Bonjour

Heureux d'avoir pu te rendre service

tu écris en dehors de ton tableau !
int tab[4][1]; le premier indice peut aller de 0 à 3, de second de 0 à.. 0.
Tu aurais dû définir int tab[5][2];
Ajouter un commentaire
Réponse
+0
moins plus
salut j'ai un problème comment tester dans l'algorithme de kruskal en c si il a un cycle entre les sommets
Ajouter un commentaire
Ce document intitulé « Tetris semblait easy-target a codé en C.... » issu de CommentCaMarche (www.commentcamarche.net) est mis à disposition sous les termes de la licence Creative Commons. Vous pouvez copier, modifier des copies de cette page, dans les conditions fixées par la licence, tant que cette note apparaît clairement.
Dossier à la une
Passage au tout numérique : quel coût pour les particuliers ?