fin de la création du tableau en C avec les pommes et le serpent

This commit is contained in:
2023-11-23 21:02:33 +01:00
parent 7c7c395721
commit d4e2cd3b2b

View File

@@ -9,34 +9,54 @@
#define LIGNES 40
#define COLONNES 60
#define NBR_POMME 5
#define TAILLE_SERPENT 10
int main(void) {
int* plateau(void) {
int tableau[LIGNES][COLONNES] = {0}, ligne_pomme, colonne_pomme, indice, indice2, compteur = 0 ;
int tableau[LIGNES][COLONNES] = {0}, ligne_pomme, colonne_pomme, i, i2, compteur = 0 ;
srand(time(NULL));
for ( indice = 0; indice < NBR_POMME; indice++) {
/* 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() % 60;
ligne_pomme = rand() % 40;
colonne_pomme = rand() % 60;
compteur += 1;
/* teste pour faire apparaitre exactement 5 pommes */
while (tableau[ligne_pomme][colonne_pomme] == 2) {
ligne_pomme = rand() % 40;
colonne_pomme = rand() % 60;
}
/* le chiffre definit une pomme */
tableau[ligne_pomme][colonne_pomme] = 2;
}
for ( indice = 0; indice < LIGNES; indice++) {
for ( indice2 = 0; indice2 < COLONNES; indice2++) {
printf("%d", tableau[indice][indice2]);
}
}
printf("\n%d", compteur);
return EXIT_SUCCESS;
return tableau;
}