suppression de la constante TAILLE_CASE pour que lecran sadapte a limage directement pour pas faire de probleme de dimension en ajoutant des variable de types int img_w et image_h ainsi que hauteur_image et largeur_img qui sont representer par l_case et h_case (je l'ai appeler img_w car ça peut porter a confusion en francais vu quil y a longueu et largeur donc jai choisi w pour width et pas img_l). Ainsi quune correction dans affichage.c : j'ai retire -1 dans les lignes avec src_x et src_y car sinon il y a un decalage donc comme ca le num 1 correspond bien au morceau dimage 1

This commit is contained in:
2025-12-05 21:17:40 +01:00
parent a3ae70648b
commit 1ca9ee8f1d
5 changed files with 35 additions and 23 deletions
+13 -12
View File
@@ -4,11 +4,11 @@
#include "config.h" #include "config.h"
void init_affichage(int nb_ligne,int nb_colonne){ void init_affichage(int largeur_img, int hauteur_img){
InitialiserGraphique(); InitialiserGraphique();
/*La fenetre vass faire la taille de la grille*/ /*La fenetre vass faire la taille de la grille*/
CreerFenetre(100, 100, nb_colonne * TAILLE_CASE, (nb_ligne * TAILLE_CASE)+60); CreerFenetre(100, 100, largeur_img, hauteur_img + 60);
} }
void charger_image_source(char *nom_fichier) { void charger_image_source(char *nom_fichier) {
@@ -22,7 +22,7 @@ void charger_image_source(char *nom_fichier) {
ChoisirEcran(0); ChoisirEcran(0);
} }
void afficher_plateau(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_colonne,int coups){ void afficher_plateau(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_colonne,int coups, int l_case, int h_case){
int i,j; int i,j;
int x, y; int x, y;
int num; int num;
@@ -33,32 +33,33 @@ void afficher_plateau(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_col
/*Compteur de coups*/ /*Compteur de coups*/
ChoisirCouleurDessin(CouleurParNom("white")); ChoisirCouleurDessin(CouleurParNom("white"));
sprintf(text_coups,"Coups : %d",coups); sprintf(text_coups,"Coups : %d",coups);
/*Comme la taille de l'écran chage y n'est pas fixe*/ /* On place le texte en bas de l'image */
EcrireTexte(10,nb_ligne*TAILLE_CASE + 40, text_coups,2); EcrireTexte(10, nb_ligne*h_case + 40, text_coups, 2);
for (i = 0; i < nb_ligne; i++){ for (i = 0; i < nb_ligne; i++){
for(j = 0; j < nb_colonne; j++){ for(j = 0; j < nb_colonne; j++){
/*Calcul en pixel de la taille d'une case*/ /*Calcul en pixel de la taille d'une case*/
num = grille[i][j]; num = grille[i][j];
x = j * TAILLE_CASE; /* Calcul dynamique de la position */
y = i * TAILLE_CASE; x = j * l_case;
y = i * h_case;
/*Ici on saute la case vide du taquin*/ /*Ici on saute la case vide du taquin*/
if (num == 0) { if (num == 0) {
ChoisirCouleurDessin(CouleurParNom("black")); ChoisirCouleurDessin(CouleurParNom("black"));
RemplirRectangle(x, y, TAILLE_CASE, TAILLE_CASE); RemplirRectangle(x, y, l_case, h_case);
continue; continue;
} }
src_x = ((num - 1) % nb_colonne) * TAILLE_CASE; src_x = (num % nb_colonne) * l_case;
src_y = ((num - 1) / nb_colonne) * TAILLE_CASE; src_y = (num / nb_colonne) * h_case;
CopierZone(1, 0, src_x, src_y, TAILLE_CASE, TAILLE_CASE, x, y); CopierZone(1, 0, src_x, src_y, l_case, h_case, x, y);
/*ET on ecrit le numéro dans un rectagle*/ /*ET on ecrit le numéro dans un rectagle*/
ChoisirCouleurDessin(CouleurParNom("black")); ChoisirCouleurDessin(CouleurParNom("black"));
DessinerRectangle(x, y, TAILLE_CASE, TAILLE_CASE); DessinerRectangle(x, y, l_case, h_case);
} }
} }
} }
+2 -2
View File
@@ -2,9 +2,9 @@
#define AFFICHAGE_H #define AFFICHAGE_H
#include "config.h" #include "config.h"
void init_affichage(int nb_ligne,int nb_colonne); void init_affichage(int largeur_img, int hauteur_img);
void fermer_affichage(void); void fermer_affichage(void);
void charger_image_source(char *nom_fichier); void charger_image_source(char *nom_fichier);
void afficher_plateau(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_colonne,int coups); void afficher_plateau(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_colonne,int coups, int l_case, int h_case);
#endif #endif
+1 -1
View File
@@ -2,6 +2,6 @@
#define CONFIG_H #define CONFIG_H
/*La grille doit être en 3 et 8 */ /*La grille doit être en 3 et 8 */
#define MAX_TAILLE 8 #define MAX_TAILLE 8
#define TAILLE_CASE 60
#endif #endif
+18 -7
View File
@@ -9,6 +9,10 @@ int main(void){
int grille[MAX_TAILLE][MAX_TAILLE]; int grille[MAX_TAILLE][MAX_TAILLE];
int ligne=0, colonne=0, touche, coups; int ligne=0, colonne=0, touche, coups;
char *nom_image = NULL; char *nom_image = NULL;
int img_w = 0, img_h = 0;
int l_case = 0, h_case = 0;
int choix_image_fait = 0; int choix_image_fait = 0;
int choix_lignes_fait = 0; int choix_lignes_fait = 0;
int choix_colonne_fait = 0; int choix_colonne_fait = 0;
@@ -46,14 +50,17 @@ int main(void){
if(touche == XK_1 || touche == XK_KP_1) { if(touche == XK_1 || touche == XK_KP_1) {
nom_image = "image1.png"; nom_image = "image1.png";
img_w = 400; img_h = 400;
choix_image_fait = 1; choix_image_fait = 1;
} }
else if(touche == XK_2 || touche == XK_KP_2) { else if(touche == XK_2 || touche == XK_KP_2) {
nom_image = "image2.png"; nom_image = "image2.png";
img_w = 400; img_h = 400;
choix_image_fait = 2; choix_image_fait = 2;
} }
else if(touche == XK_3 || touche == XK_KP_3) { else if(touche == XK_3 || touche == XK_KP_3) {
nom_image = "image3.png"; nom_image = "image3.png";
img_w = 400; img_h = 400;
choix_image_fait = 3; choix_image_fait = 3;
} }
else if(touche == XK_q || touche == XK_Q) { else if(touche == XK_q || touche == XK_Q) {
@@ -131,11 +138,14 @@ int main(void){
} }
} }
/* CALCUL AUTO des tailles*/
l_case = img_w / colonne;
h_case = img_h / ligne;
FermerGraphique(); FermerGraphique();
init_affichage(ligne,colonne); /* On met la taille de l'image pour créer la fenêtre */
init_affichage(img_w, img_h);
charger_image_source(nom_image); charger_image_source(nom_image);
@@ -144,7 +154,7 @@ int main(void){
melanger_plateau(grille,ligne,colonne); melanger_plateau(grille,ligne,colonne);
afficher_plateau(grille,ligne,colonne,coups); afficher_plateau(grille,ligne,colonne,coups, l_case, h_case);
while(jeu_fini == 0){ while(jeu_fini == 0){
@@ -160,7 +170,7 @@ int main(void){
/* Déplacement +on affiche la nouvelle grille */ /* Déplacement +on affiche la nouvelle grille */
if (deplacer(grille,ligne,colonne,touche) == 1) { if (deplacer(grille,ligne,colonne,touche) == 1) {
coups++; coups++;
afficher_plateau(grille,ligne,colonne,coups); afficher_plateau(grille,ligne,colonne,coups, l_case, h_case);
/*On vérifie si on a gagner */ /*On vérifie si on a gagner */
if(verifier_victoire(grille,ligne,colonne) == 1 ){ if(verifier_victoire(grille,ligne,colonne) == 1 ){
jeu_fini = 1; jeu_fini = 1;
@@ -171,7 +181,8 @@ int main(void){
if (jeu_fini == 1){ if (jeu_fini == 1){
ChoisirCouleurDessin(CouleurParNom("white")); ChoisirCouleurDessin(CouleurParNom("white"));
RemplirRectangle(50,150,300,100); /* pense à utiliser img_w pour la largeur du rectangle blanc */
RemplirRectangle(50,150, img_w - 100,100);
ChoisirCouleurDessin(CouleurParNom("red")); ChoisirCouleurDessin(CouleurParNom("red"));
EcrireTexte(60,200,"Bravo",2); EcrireTexte(60,200,"Bravo",2);
BIN
View File
Binary file not shown.