avancement sur les déplacement du serpent

This commit is contained in:
2023-12-14 01:07:57 +01:00
parent d3e69dec40
commit fd0c4a36a8
11 changed files with 256 additions and 134 deletions

View File

@@ -14,10 +14,12 @@ struct adresse* plateau_init(void) {
int ligne_pomme, colonne_pomme, i;
unsigned char* tete = NULL;
unsigned char* queue = NULL;
unsigned int* indice_queue = NULL;
unsigned int* taille_serpent = NULL;
unsigned int** corps_serpent = NULL;
int** plateau = NULL;
@@ -27,19 +29,28 @@ struct adresse* plateau_init(void) {
srand(time(NULL));
/* allocation du pointeur */
pointeur = malloc(sizeof( struct adresse));
/* allocation du tableau tete et queue */
tete = malloc(2*sizeof(unsigned char));
queue = malloc(2*sizeof(unsigned char));
indice_queue = malloc(sizeof(unsigned int));
/* allocation du tableau dans le tas */
/* allocation du plateau dans le tas */
plateau = calloc(LIGNES, sizeof(int*));
@@ -49,9 +60,26 @@ struct adresse* plateau_init(void) {
}
/* allocation du corps du serpent */
corps_serpent = malloc(TAILLE_SERPENT * sizeof(unsigned int*));
for ( i = 0; i < TAILLE_SERPENT; i++) {
corps_serpent[i] = malloc( 2 * sizeof(unsigned int));
}
/* allocation de la taille du serpent */
taille_serpent = malloc(sizeof(unsigned int));
/* positionnement du serpent et marquage de la tete et la queue */
tete[0] = ((LIGNES/2)+(TAILLE_SERPENT/2)-1);
@@ -59,13 +87,14 @@ struct adresse* plateau_init(void) {
queue[0] = ((LIGNES/2)-(TAILLE_SERPENT/2));
queue[1] = COLONNES/2;
for (i = 0; i < TAILLE_SERPENT ; i++) {
plateau[((LIGNES/2)-5)+i][COLONNES/2] = 1;
corps_serpent[i][0] = ((LIGNES/2)-5) + i;
corps_serpent[i][1] = COLONNES/2;
}
@@ -96,11 +125,15 @@ struct adresse* plateau_init(void) {
}
*taille_serpent = TAILLE_SERPENT;
*indice_queue = 0;
pointeur -> plateau = plateau;
pointeur -> tete = tete;
pointeur -> queue = queue;
pointeur -> indice_queue = indice_queue;
pointeur -> corps_serpent = corps_serpent;
pointeur -> taille_serpent = taille_serpent;