diff --git a/affichage.c b/affichage.c index 9fdf9cf..6a95825 100644 --- a/affichage.c +++ b/affichage.c @@ -10,23 +10,48 @@ void init_affichage(void){ /*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,x,y; - char texte[10]; - EffacerEcran(CouleurParNom("white")); + 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*/ - x = j * TAILLE_CASE; - y = i * TAILLE_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 (grille[i][j] == 0) continue; + + 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, y, TAILLE_CASE, TAILLE_CASE); - sprintf(texte, "%d", grille[i][j]); - EcrireTexte(x + 40, y + 60, texte, 2); + DessinerRectangle(x_ecran, y_ecran, TAILLE_CASE, TAILLE_CASE); } } } diff --git a/affichage.h b/affichage.h index 8701263..81eaa00 100644 --- a/affichage.h +++ b/affichage.h @@ -4,7 +4,7 @@ void init_affichage(void); void fermer_affichage(void); +void charger_image_source(char *nom_fichier); void afficher_plateau(int grille[NB_LIGNES][NB_COLS]); - #endif diff --git a/image1.jpg b/image1.jpg new file mode 100644 index 0000000..7cff59d Binary files /dev/null and b/image1.jpg differ diff --git a/image1.png b/image1.png new file mode 100644 index 0000000..10021ef Binary files /dev/null and b/image1.png differ diff --git a/image2.jpg b/image2.jpg new file mode 100644 index 0000000..d396e93 Binary files /dev/null and b/image2.jpg differ diff --git a/image2.png b/image2.png new file mode 100644 index 0000000..aac03af Binary files /dev/null and b/image2.png differ diff --git a/image3.jpg b/image3.jpg new file mode 100644 index 0000000..2e9e281 Binary files /dev/null and b/image3.jpg differ diff --git a/image3.png b/image3.png new file mode 100644 index 0000000..179aa8d Binary files /dev/null and b/image3.png differ diff --git a/main.c b/main.c index 4a48f22..b7b7a91 100644 --- a/main.c +++ b/main.c @@ -7,9 +7,48 @@ int main(void){ int grille[NB_LIGNES][NB_COLS], touche; - - init_affichage(); + char *nom_image = NULL; + int choix_fait = 0; + init_affichage(); + + EffacerEcran(CouleurParNom("white")); + ChoisirCouleurDessin(CouleurParNom("black")); + + EcrireTexte(50, 50, "MENU TAQUIN", 2); + EcrireTexte(50, 100, "Choisissez votre image :", 1); + EcrireTexte(50, 150, "Touche 1 : Image 1", 1); + EcrireTexte(50, 180, "Touche 2 : Image 2", 1); + EcrireTexte(50, 210, "Touche 3 : Image 3", 1); + EcrireTexte(50, 300, "(Appuyez sur q pour quitter)", 1); + + while(choix_fait == 0) { + if(ToucheEnAttente()) { + touche = Touche(); + + printf("Touche reçue : %d (Caractère : %c)\n", touche, (char)touche); + + if(touche == '1' || touche == 38) { + nom_image = "image1.png"; + choix_fait = 1; + } + else if(touche == '2' || touche == 233) { + nom_image = "image2.png"; + choix_fait = 2; + } + else if(touche == '3' || touche == 34) { + nom_image = "image3.png"; + choix_fait = 3; + } + else if(touche == 'q' || touche == 27) { + fermer_affichage(); + return EXIT_SUCCESS; + } + } + } + + charger_image_source(nom_image); + initialiser_plateau(grille); melanger_plateau(grille); diff --git a/taquin b/taquin index 9e8d476..3b87875 100755 Binary files a/taquin and b/taquin differ