fin de la fonction qui agrandie le serpent lorqu'il mange une pomme

This commit is contained in:
2023-12-19 11:19:47 +01:00
parent e726ecd02b
commit 3b0599777b
4 changed files with 28 additions and 20 deletions

View File

@@ -28,36 +28,44 @@ void augmentation_serpent (struct adresse* pointeur) {
/* augmentation de la taille du serpent */ /* augmentation de la taille du serpent */
*taille_serpent = *taille_serpent + 1; *taille_serpent = *taille_serpent + 1;
/* création d'un nouveau tableau */ /* création d'un nouveau tableau */
corps_serpent2 = malloc( *taille_serpent * sizeof(int*)); corps_serpent2 = malloc( *taille_serpent * sizeof(int*));
for ( i = 0; i < *taille_serpent; i++) { for ( i = 0; i < *taille_serpent; i++) {
corps_serpent2 = malloc( 2 * sizeof(int)); corps_serpent2[i] = malloc( 2 * sizeof(int));
} }
printf("%hu\n", *taille_serpent);
/* attributions des anciennes cases du corps dans le nouveau tableau et ajout de la nouvelle tête au bonne endroit*/ /* attributions des anciennes cases du corps dans le nouveau tableau et ajout de la nouvelle tête au bonne endroit*/
for ( i = 0 ; i < *indice_queue; i++) { for ( i = 0 ; i < *indice_queue; i++) {
corps_serpent2[i] = corps_serpent[i] ; corps_serpent2[i][0]= corps_serpent[i][0] ;
corps_serpent2[i][1]= corps_serpent[i][1] ;
} }
corps_serpent2[*indice_queue][0] = tete[0]; corps_serpent2[*indice_queue][0] = tete[0];
corps_serpent2[*indice_queue][1] = tete[1]; corps_serpent2[*indice_queue][1] = tete[1];
for ( i = *indice_queue ; i < *taille_serpent - 1; i++) { for ( i = *indice_queue ; i < *taille_serpent - 1; i++) {
corps_serpent2[i+1] = corps_serpent[i]; corps_serpent2[i+1][0] = corps_serpent[i][0];
corps_serpent2[i+1][1] = corps_serpent[i][1];
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

BIN
snake/lancement Executable file

Binary file not shown.

View File

@@ -44,22 +44,10 @@ void supp_queue( struct adresse* pointeur, unsigned char* retard ) {
*retard = *retard + 2; *retard = *retard + 2;
printf("[%hhu]\n", *retard);
if (*retard >0 ) {
augmentation_serpent(pointeur);
*retard = *retard - 1;
}else{
/* apparition de la nouvelle pomme */ /* apparition de la nouvelle pomme */
ligne_pomme = rand() % 40; ligne_pomme = rand() % 40;
colonne_pomme = rand() % 60; colonne_pomme = rand() % 60;
@@ -78,8 +66,20 @@ void supp_queue( struct adresse* pointeur, unsigned char* retard ) {
RemplirRectangle(20*(colonne_pomme + 1),20*(ligne_pomme + 1),20,20); RemplirRectangle(20*(colonne_pomme + 1),20*(ligne_pomme + 1),20,20);
} }
if (*retard >0 ) {
augmentation_serpent(pointeur);
*retard = *retard - 1;
printf("[%hhu]\n", *retard);
} }