diff --git a/graphique/fenetre.c b/graphique/fenetre.c index e9bfba9..a80c373 100644 --- a/graphique/fenetre.c +++ b/graphique/fenetre.c @@ -1,14 +1,93 @@ #include <stdlib.h> #include <graph.h> +#include "/export/home/an23/keraudre/SAE11_2023/prog/plateau_init.c" int main (void) { + couleur green, white, yellow, red; + + int** tableau = plateau_init(); + + int i, j; + + InitialiserGraphique(); - CreerFenetre(10,10,500,500); - EcrireTexte(10,100,"Hello World !",2); + CreerFenetre(10,10,1550,910); + + /* tracer du plateau de jeux*/ + + DessinerRectangle(15,15,1320,880); + + /* remplisage du fond d'écran */ + + white = CouleurParComposante(255,255,255); + ChoisirCouleurDessin(white); + RemplirRectangle(0,0,1550,910); + + + + /* remplissage du plateau de jeux avec les couleur adéquate */ + + + for (i = 0; i < LIGNES; i++) { + for (j = 0; j < COLONNES; j++) { + + if ( tableau[i][j] == 0) { + + green = CouleurParComposante(0,255,30); + ChoisirCouleurDessin(green); + RemplirRectangle(15*(j+1),15*(i+1),22,20); + + } + if ( tableau[i][j] == 1) { + + yellow = CouleurParComposante(255,255,0); + ChoisirCouleurDessin(yellow); + RemplirRectangle(15*(j+1),15*(i+1),22,20); + + } + + if ( tableau[i][j] == 2) { + + red = CouleurParComposante(255,0,0); + ChoisirCouleurDessin(red); + RemplirRectangle(15*(j+1),15*(i+1),22,20); + } + + } + } + + + for ( i = 0; i < LIGNES; i++) { + for ( j = 0; j < COLONNES; j++) { + + printf("%d", tableau[i][j]); + + } + printf("\n"); + + } + printf("\n"); + + + + for ( i = 0; i < LIGNES; i++) { + + free(tableau[i]); + } + + free(tableau); + + + + + Touche(); FermerGraphique(); + + + return EXIT_SUCCESS; } diff --git a/prog/plateauinit.c b/prog/plateau_init.c similarity index 73% rename from prog/plateauinit.c rename to prog/plateau_init.c index e77f80a..9c099ee 100644 --- a/prog/plateauinit.c +++ b/prog/plateau_init.c @@ -11,13 +11,25 @@ #define NBR_POMME 5 #define TAILLE_SERPENT 10 -int* plateauinit(void) { +int** plateau_init(void) { + + int ligne_pomme, colonne_pomme, i; + + int ** tableau = NULL; - int tableau[LIGNES][COLONNES] = {0}, ligne_pomme, colonne_pomme, i, i2, compteur = 0 ; 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 */ @@ -50,11 +62,12 @@ int* plateauinit(void) { } - /* le chiffre definit une pomme */ + /* le chiffre "2" definit une pomme */ tableau[ligne_pomme][colonne_pomme] = 2; } +