Files
SAE11_2025/affichage.c
T

61 lines
1.5 KiB
C

#include <stdio.h>
#include "affichage.h"
#include <graph.h>
#include "config.h"
void init_affichage(void){
InitialiserGraphique();
/*La fenetre vass faire la taille de la grille*/
CreerFenetre(100, 100, NB_COLS * TAILLE_CASE, NB_LIGNES * TAILLE_CASE);
}
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[NB_LIGNES][NB_COLS]){
int i,j;
int x_ecran, y_ecran;
int num_tuile;
int src_x, src_y;
EffacerEcran(CouleurParNom("black"));
for (i = 0; i < NB_LIGNES; i++){
for(j = 0; j < NB_COLS; j++){
/*Calcul en pixel de la taille d'une case*/
num_tuile = grille[i][j];
x_ecran = j * TAILLE_CASE;
y_ecran = i * TAILLE_CASE;
/*Ici on saute la case vide du taquin*/
if (num_tuile == 0) {
ChoisirCouleurDessin(CouleurParNom("black"));
RemplirRectangle(x_ecran, y_ecran, TAILLE_CASE, TAILLE_CASE);
continue;
}
src_x = ((num_tuile - 1) % NB_COLS) * TAILLE_CASE;
src_y = ((num_tuile - 1) / NB_COLS) * TAILLE_CASE;
CopierZone(1, 0, src_x, src_y, TAILLE_CASE, TAILLE_CASE, x_ecran, y_ecran);
/*ET on ecrit le numéro dans un rectagle*/
ChoisirCouleurDessin(CouleurParNom("black"));
DessinerRectangle(x_ecran, y_ecran, TAILLE_CASE, TAILLE_CASE);
}
}
}
void fermer_affichage(void){
FermerGraphique();
}