fin de la création du tableau en C avec les pommes et le serpent
This commit is contained in:
@@ -9,34 +9,54 @@
|
|||||||
#define LIGNES 40
|
#define LIGNES 40
|
||||||
#define COLONNES 60
|
#define COLONNES 60
|
||||||
#define NBR_POMME 5
|
#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));
|
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;
|
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;
|
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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user