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

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

@ -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;
}

@ -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;
}