2025-11-30 16:16:27 +01:00
|
|
|
#include <stdio.h>
|
2025-11-29 20:25:05 +01:00
|
|
|
#include "affichage.h"
|
|
|
|
|
#include <graph.h>
|
2025-11-30 16:16:27 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
|
2025-11-29 20:25:05 +01:00
|
|
|
|
2025-12-05 21:17:40 +01:00
|
|
|
void init_affichage(int largeur_img, int hauteur_img){
|
2025-11-29 20:25:05 +01:00
|
|
|
|
|
|
|
|
InitialiserGraphique();
|
2025-11-30 16:16:27 +01:00
|
|
|
/*La fenetre vass faire la taille de la grille*/
|
2025-12-05 21:17:40 +01:00
|
|
|
CreerFenetre(100, 100, largeur_img, hauteur_img + 60);
|
2025-11-29 20:25:05 +01:00
|
|
|
}
|
2025-12-02 00:38:32 +01:00
|
|
|
|
|
|
|
|
void charger_image_source(char *nom_fichier) {
|
|
|
|
|
ChoisirEcran(1);
|
|
|
|
|
|
|
|
|
|
EffacerEcran(CouleurParNom("black"));
|
|
|
|
|
|
|
|
|
|
/* On charge l'image. On force sa taille pour qu'elle remplisse bien le jeu */
|
|
|
|
|
ChargerImageFond(nom_fichier);
|
|
|
|
|
|
|
|
|
|
ChoisirEcran(0);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-05 21:17:40 +01:00
|
|
|
void afficher_plateau(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_colonne,int coups, int l_case, int h_case){
|
2025-12-02 00:38:32 +01:00
|
|
|
int i,j;
|
2025-12-04 00:21:45 +01:00
|
|
|
int x, y;
|
|
|
|
|
int num;
|
2025-12-02 00:38:32 +01:00
|
|
|
int src_x, src_y;
|
2025-12-04 00:21:45 +01:00
|
|
|
char text_coups[50];
|
2025-12-02 00:38:32 +01:00
|
|
|
|
|
|
|
|
EffacerEcran(CouleurParNom("black"));
|
2025-12-04 00:21:45 +01:00
|
|
|
/*Compteur de coups*/
|
|
|
|
|
ChoisirCouleurDessin(CouleurParNom("white"));
|
|
|
|
|
sprintf(text_coups,"Coups : %d",coups);
|
2025-12-05 21:17:40 +01:00
|
|
|
/* On place le texte en bas de l'image */
|
|
|
|
|
EcrireTexte(10, nb_ligne*h_case + 40, text_coups, 2);
|
2025-12-04 00:21:45 +01:00
|
|
|
|
2025-11-29 20:25:05 +01:00
|
|
|
|
2025-12-04 00:21:45 +01:00
|
|
|
for (i = 0; i < nb_ligne; i++){
|
|
|
|
|
for(j = 0; j < nb_colonne; j++){
|
2025-11-30 16:16:27 +01:00
|
|
|
/*Calcul en pixel de la taille d'une case*/
|
2025-12-04 00:21:45 +01:00
|
|
|
num = grille[i][j];
|
2025-12-05 21:17:40 +01:00
|
|
|
/* Calcul dynamique de la position */
|
|
|
|
|
x = j * l_case;
|
|
|
|
|
y = i * h_case;
|
2025-11-30 16:16:27 +01:00
|
|
|
/*Ici on saute la case vide du taquin*/
|
2025-12-02 00:38:32 +01:00
|
|
|
|
2025-12-04 00:21:45 +01:00
|
|
|
if (num == 0) {
|
2025-12-02 00:38:32 +01:00
|
|
|
ChoisirCouleurDessin(CouleurParNom("black"));
|
2025-12-05 21:17:40 +01:00
|
|
|
RemplirRectangle(x, y, l_case, h_case);
|
2025-12-02 00:38:32 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-05 21:17:40 +01:00
|
|
|
src_x = (num % nb_colonne) * l_case;
|
|
|
|
|
src_y = (num / nb_colonne) * h_case;
|
2025-12-02 00:38:32 +01:00
|
|
|
|
2025-12-05 21:17:40 +01:00
|
|
|
CopierZone(1, 0, src_x, src_y, l_case, h_case, x, y);
|
2025-12-02 00:38:32 +01:00
|
|
|
|
2025-11-30 16:16:27 +01:00
|
|
|
/*ET on ecrit le numéro dans un rectagle*/
|
|
|
|
|
ChoisirCouleurDessin(CouleurParNom("black"));
|
2025-12-05 21:17:40 +01:00
|
|
|
DessinerRectangle(x, y, l_case, h_case);
|
2025-11-30 16:16:27 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-29 20:25:05 +01:00
|
|
|
void fermer_affichage(void){
|
2025-11-30 16:16:27 +01:00
|
|
|
FermerGraphique();
|
2025-11-29 20:25:05 +01:00
|
|
|
}
|