From 7e105c12d6ce6c881d013ca9b8b08d397708c338 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Sun, 30 Nov 2025 16:16:27 +0100 Subject: [PATCH] Le programme permet maintenant d'affichier un ecran qui fait la taille d'une grille 4*4 --- Makefile | 9 ++++++--- affichage.c | 28 +++++++++++++++++++++++++--- affichage.h | 2 ++ config.h | 9 +++++++++ main.c | 13 +++++++++---- partie.c | 14 ++++++++++++++ partie.h | 9 +++++++++ 7 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 config.h create mode 100644 partie.c create mode 100644 partie.h diff --git a/Makefile b/Makefile index c2ce303..d302451 100644 --- a/Makefile +++ b/Makefile @@ -6,15 +6,18 @@ CFLAGS = -Wall \ LIBS = -lgraph EXE = taquin OFILES = main.o \ - affichage.o + affichage.o \ + partie.o ### BUT PAR DEFAUT ### but : ${EXE} ### REGLES ESSENTIELLES ### -affichage.o : affichage.h +affichage.o : affichage.h config.h -main.o : affichage.h +partie.o : partie.h config.h + +main.o : affichage.h partie.h config.h ${EXE} : ${OFILES} $(CC) $(CFLAGS) -o ${EXE} ${OFILES} ${LIBS} diff --git a/affichage.c b/affichage.c index d3c38d7..9fdf9cf 100644 --- a/affichage.c +++ b/affichage.c @@ -1,13 +1,35 @@ +#include #include "affichage.h" #include +#include "config.h" + void init_affichage(void){ InitialiserGraphique(); - CreerFenetre(100, 100, 800, 600); + /*La fenetre vass faire la taille de la grille*/ + CreerFenetre(100, 100, NB_COLS * TAILLE_CASE, NB_LIGNES * TAILLE_CASE); } +void afficher_plateau(int grille[NB_LIGNES][NB_COLS]){ + int i,j,x,y; + char texte[10]; + EffacerEcran(CouleurParNom("white")); + for (i = 0; i < NB_LIGNES; i++){ + for(j = 0; j < NB_COLS; j++){ + /*Calcul en pixel de la taille d'une case*/ + x = j * TAILLE_CASE; + y = i * TAILLE_CASE; + /*Ici on saute la case vide du taquin*/ + if (grille[i][j] == 0) continue; + /*ET on ecrit le numéro dans un rectagle*/ + ChoisirCouleurDessin(CouleurParNom("black")); + DessinerRectangle(x, y, TAILLE_CASE, TAILLE_CASE); + sprintf(texte, "%d", grille[i][j]); + EcrireTexte(x + 40, y + 60, texte, 2); + } + } +} void fermer_affichage(void){ - - FermerGraphique(); + FermerGraphique(); } diff --git a/affichage.h b/affichage.h index 7802388..8701263 100644 --- a/affichage.h +++ b/affichage.h @@ -1,8 +1,10 @@ #ifndef AFFICHAGE_H #define AFFICHAGE_H +#include "config.h" void init_affichage(void); void fermer_affichage(void); +void afficher_plateau(int grille[NB_LIGNES][NB_COLS]); #endif diff --git a/config.h b/config.h new file mode 100644 index 0000000..99128d8 --- /dev/null +++ b/config.h @@ -0,0 +1,9 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#define NB_LIGNES 4 +#define NB_COLS 4 + +#define TAILLE_CASE 100 + +#endif diff --git a/main.c b/main.c index 2555130..a71595d 100644 --- a/main.c +++ b/main.c @@ -1,15 +1,20 @@ +#include #include "affichage.h" -#include #include +#include "config.h" +#include "partie.h" int main(void){ - int k; + int grille[NB_LIGNES][NB_COLS],touche; + init_affichage(); + initialiser_plateau(grille); + afficher_plateau(grille); while(1){ if (ToucheEnAttente()){ - k = Touche(); - if (k == XK_q)break; + touche = Touche(); + if (touche == XK_q)break; } diff --git a/partie.c b/partie.c new file mode 100644 index 0000000..76d4528 --- /dev/null +++ b/partie.c @@ -0,0 +1,14 @@ +#include "partie.h" +void initialiser_plateau(int grille[NB_LIGNES][NB_COLS]){ + int i, j; + int compteur = 1; + + for (i = 0; i < NB_LIGNES; i++){ + for(j = 0; j < NB_COLS; j++){ + grille[i][j] = compteur; + compteur++; + } + } + /*On laisse la dernière case du tableu vide pour le taquin*/ + grille[NB_LIGNES - 1 ][NB_COLS - 1] = 0; +} diff --git a/partie.h b/partie.h new file mode 100644 index 0000000..0ee530b --- /dev/null +++ b/partie.h @@ -0,0 +1,9 @@ +#ifndef PARTIE_H +#define PARTIE_H + +#include "config.h" + +void initialiser_plateau(int grille[NB_LIGNES][NB_COLS]); + + +#endif