Avancement dans l'affichage graphique du tableau, mais bug rencontré dans les valeurs du tableau

This commit is contained in:
2023-11-24 01:32:37 +01:00
parent b61b2de79a
commit dc9ba3e4fe
2 changed files with 97 additions and 5 deletions

75
prog/plateau_init.c Normal file
View File

@@ -0,0 +1,75 @@
/* Création du plateau de jeu avec les pastilles et le serpent
written by Yann KERAUDREN and Titouan LERICHE*/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define LIGNES 40
#define COLONNES 60
#define NBR_POMME 5
#define TAILLE_SERPENT 10
int** plateau_init(void) {
int ligne_pomme, colonne_pomme, i;
int ** tableau = NULL;
srand(time(NULL));
/* allocation du tableau dans le tas */
tableau = calloc(LIGNES, sizeof(int));
for ( i = 0; i < LIGNES; i++) {
tableau[i] = calloc(COLONNES, sizeof(int));
}
/* positionnement du serpent */
for (i = 0; i < TAILLE_SERPENT; i++) {
tableau[((LIGNES/2)-5)+i][COLONNES/2] = 1;
}
/* positionnement alétoire des pommes */
for ( i = 0; i < NBR_POMME; i++) {
ligne_pomme = rand() % 40;
colonne_pomme = rand() % 60;
/* teste pour faire apparaitre exactement 5 pommes */
while (tableau[ligne_pomme][colonne_pomme] == 2) {
ligne_pomme = rand() % 40;
colonne_pomme = rand() % 60;
}
/* le chiffre "2" definit une pomme */
tableau[ligne_pomme][colonne_pomme] = 2;
}
return tableau;
}