Files
SAE11_2025/affichage.c
T

68 lines
1.8 KiB
C
Raw Normal View History

#include <stdio.h>
#include "affichage.h"
#include <graph.h>
#include "config.h"
void init_affichage(int nb_ligne,int nb_colonne){
InitialiserGraphique();
/*La fenetre vass faire la taille de la grille*/
CreerFenetre(100, 100, nb_colonne * TAILLE_CASE, (nb_ligne * TAILLE_CASE)+60);
}
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);
}
void afficher_plateau(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_colonne,int coups){
2025-12-02 00:38:32 +01:00
int i,j;
int x, y;
int num;
2025-12-02 00:38:32 +01:00
int src_x, src_y;
char text_coups[50];
2025-12-02 00:38:32 +01:00
EffacerEcran(CouleurParNom("black"));
/*Compteur de coups*/
ChoisirCouleurDessin(CouleurParNom("white"));
sprintf(text_coups,"Coups : %d",coups);
/*Comme la taille de l'écran chage y n'est pas fixe*/
EcrireTexte(10,nb_ligne*TAILLE_CASE + 40, text_coups,2);
for (i = 0; i < nb_ligne; i++){
for(j = 0; j < nb_colonne; j++){
/*Calcul en pixel de la taille d'une case*/
num = grille[i][j];
x = j * TAILLE_CASE;
y = i * TAILLE_CASE;
/*Ici on saute la case vide du taquin*/
2025-12-02 00:38:32 +01:00
if (num == 0) {
2025-12-02 00:38:32 +01:00
ChoisirCouleurDessin(CouleurParNom("black"));
RemplirRectangle(x, y, TAILLE_CASE, TAILLE_CASE);
2025-12-02 00:38:32 +01:00
continue;
}
src_x = ((num - 1) % nb_colonne) * TAILLE_CASE;
src_y = ((num - 1) / nb_colonne) * TAILLE_CASE;
2025-12-02 00:38:32 +01:00
CopierZone(1, 0, src_x, src_y, TAILLE_CASE, TAILLE_CASE, x, y);
2025-12-02 00:38:32 +01:00
/*ET on ecrit le numéro dans un rectagle*/
ChoisirCouleurDessin(CouleurParNom("black"));
DessinerRectangle(x, y, TAILLE_CASE, TAILLE_CASE);
}
}
}
void fermer_affichage(void){
FermerGraphique();
}