on peut choisir le nombre de ligne et colonne mais il y a un problème de dimension de l'image, le compteur a été ajouter , mais on peut toujours pas controler avec la souris

This commit is contained in:
2025-12-04 00:21:45 +01:00
parent 7325bc7500
commit 20ec920174
8 changed files with 227 additions and 131 deletions
-9
View File
@@ -1,9 +0,0 @@
#ifndef CONFIG_H
#define CONFIG_H
#define NB_LIGNES 4
#define NB_COLS
#define TAILLE_CASE 100
#endif
+23 -16
View File
@@ -4,11 +4,11 @@
#include "config.h" #include "config.h"
void init_affichage(void){ void init_affichage(int nb_ligne,int nb_colonne){
InitialiserGraphique(); InitialiserGraphique();
/*La fenetre vass faire la taille de la grille*/ /*La fenetre vass faire la taille de la grille*/
CreerFenetre(100, 100, NB_COLS * TAILLE_CASE, NB_LIGNES * TAILLE_CASE); CreerFenetre(100, 100, nb_colonne * TAILLE_CASE, (nb_ligne * TAILLE_CASE)+60);
} }
void charger_image_source(char *nom_fichier) { void charger_image_source(char *nom_fichier) {
@@ -22,36 +22,43 @@ void charger_image_source(char *nom_fichier) {
ChoisirEcran(0); ChoisirEcran(0);
} }
void afficher_plateau(int grille[NB_LIGNES][NB_COLS]){ void afficher_plateau(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_colonne,int coups){
int i,j; int i,j;
int x_ecran, y_ecran; int x, y;
int num_tuile; int num;
int src_x, src_y; int src_x, src_y;
char text_coups[50];
EffacerEcran(CouleurParNom("black")); 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_LIGNES; i++){ for (i = 0; i < nb_ligne; i++){
for(j = 0; j < NB_COLS; 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_tuile = grille[i][j]; num = grille[i][j];
x_ecran = j * TAILLE_CASE; x = j * TAILLE_CASE;
y_ecran = i * TAILLE_CASE; y = i * TAILLE_CASE;
/*Ici on saute la case vide du taquin*/ /*Ici on saute la case vide du taquin*/
if (num_tuile == 0) { if (num == 0) {
ChoisirCouleurDessin(CouleurParNom("black")); ChoisirCouleurDessin(CouleurParNom("black"));
RemplirRectangle(x_ecran, y_ecran, TAILLE_CASE, TAILLE_CASE); RemplirRectangle(x, y, TAILLE_CASE, TAILLE_CASE);
continue; continue;
} }
src_x = ((num_tuile - 1) % NB_COLS) * TAILLE_CASE; src_x = ((num - 1) % nb_colonne) * TAILLE_CASE;
src_y = ((num_tuile - 1) / NB_COLS) * TAILLE_CASE; src_y = ((num - 1) / nb_colonne) * TAILLE_CASE;
CopierZone(1, 0, src_x, src_y, TAILLE_CASE, TAILLE_CASE, x_ecran, y_ecran); CopierZone(1, 0, src_x, src_y, TAILLE_CASE, TAILLE_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_ecran, y_ecran, TAILLE_CASE, TAILLE_CASE); DessinerRectangle(x, y, TAILLE_CASE, TAILLE_CASE);
} }
} }
} }
+2 -2
View File
@@ -2,9 +2,9 @@
#define AFFICHAGE_H #define AFFICHAGE_H
#include "config.h" #include "config.h"
void init_affichage(void); void init_affichage(int nb_ligne,int nb_colonne);
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[NB_LIGNES][NB_COLS]); void afficher_plateau(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_colonne,int coups);
#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 100 #define TAILLE_CASE 60
#endif #endif
+172 -67
View File
@@ -6,85 +6,190 @@
#include "partie.h" #include "partie.h"
int main(void){ int main(void){
int grille[NB_LIGNES][NB_COLS], touche; int grille[MAX_TAILLE][MAX_TAILLE];
int ligne=0, colonne=0, touche, coups;
char *nom_image = NULL; char *nom_image = NULL;
int choix_fait = 0,jeu_fini = 0; int choix_image_fait = 0;
int choix_lignes_fait = 0;
int choix_colonne_fait = 0;
int jeu_fini = 0;
int vouloir_rejouer=1;
init_affichage(); InitialiserGraphique();
EffacerEcran(CouleurParNom("white")); while(vouloir_rejouer ==1){
ChoisirCouleurDessin(CouleurParNom("black")); choix_image_fait = 0;
choix_lignes_fait = 0;
EcrireTexte(50, 50, "MENU TAQUIN", 2); choix_colonne_fait =0;
EcrireTexte(50, 100, "Choisissez votre image :", 1); jeu_fini = 0;
EcrireTexte(50, 150, "Touche 1 : Image 1", 1); coups=0;
EcrireTexte(50, 180, "Touche 2 : Image 2", 1); ligne=0;
EcrireTexte(50, 210, "Touche 3 : Image 3", 1); colonne =0;
EcrireTexte(50, 300, "(Appuyez sur q pour quitter)", 1); /*Fenetre du menu*/
CreerFenetre(100,100,400,400);
while(choix_fait == 0) { /*Le choix de l'image*/
if(ToucheEnAttente()) {
touche = Touche(); EffacerEcran(CouleurParNom("white"));
ChoisirCouleurDessin(CouleurParNom("black"));
if(touche == XK_1 || touche == XK_KP_1) { EcrireTexte(50, 50, "MENU TAQUIN", 2);
nom_image = "image1.png"; EcrireTexte(50, 100, "Choisissez votre image :", 1);
choix_fait = 1; EcrireTexte(50, 150, "Touche 1 : Image 1", 1);
} EcrireTexte(50, 180, "Touche 2 : Image 2", 1);
else if(touche == XK_2 || touche == XK_KP_2) { EcrireTexte(50, 210, "Touche 3 : Image 3", 1);
nom_image = "image2.png"; EcrireTexte(50, 300, "(Appuyez sur q pour quitter)", 1);
choix_fait = 2;
} while(choix_image_fait == 0) {
else if(touche == XK_3 || touche == XK_KP_3) { if(ToucheEnAttente()) {
nom_image = "image3.png"; touche = Touche();
choix_fait = 3;
if(touche == XK_1 || touche == XK_KP_1) {
nom_image = "image1.png";
choix_image_fait = 1;
}
else if(touche == XK_2 || touche == XK_KP_2) {
nom_image = "image2.png";
choix_image_fait = 2;
}
else if(touche == XK_3 || touche == XK_KP_3) {
nom_image = "image3.png";
choix_image_fait = 3;
} }
else if(touche == XK_q || touche == XK_Q) { else if(touche == XK_q || touche == XK_Q) {
fermer_affichage(); fermer_affichage();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
} }
} }
/*Choix de la taille*/
charger_image_source(nom_image); /*Lignes*/
EffacerEcran(CouleurParNom("white"));
EcrireTexte(20,30,"Combien de lignes ?",2);
EcrireTexte(20,80,"Appuyez sur une touche",1);
EcrireTexte(20,110,"entre 3 et 8",1);
while(choix_lignes_fait ==0){
if(ToucheEnAttente()){
touche=Touche();
if (touche == XK_3 || touche == XK_KP_3) {
ligne = 3; choix_lignes_fait = 1;
}
else if (touche == XK_4 || touche == XK_KP_4) {
ligne = 4; choix_lignes_fait = 1;
}
else if (touche == XK_5 || touche == XK_KP_5) {
ligne = 5; choix_lignes_fait = 1;
}
else if (touche == XK_6 || touche == XK_KP_6) {
ligne = 6; choix_lignes_fait = 1;
}
else if (touche == XK_7 || touche == XK_KP_7) {
ligne = 7; choix_lignes_fait = 1;
}
else if (touche == XK_8 || touche == XK_KP_8) {
ligne = 8; choix_lignes_fait = 1;
}
if (touche == XK_q) { FermerGraphique(); return EXIT_SUCCESS; }
initialiser_plateau(grille);
melanger_plateau(grille);
afficher_plateau(grille);
while(jeu_fini == 0){
if (ToucheEnAttente()){
touche = Touche();
/* Pour quitter on clique sur q */
if (touche == XK_q || touche == XK_Q) break;
/* Déplacement +on affiche la nouvelle grille */
deplacer(grille, touche);
afficher_plateau(grille);
/*On vérifie si on a gagner */
if(verifier_victoire(grille) == 1 ){
jeu_fini = 1;
} }
} }
} /*Colonne*/
EffacerEcran(CouleurParNom("white"));
if (jeu_fini == 1){ EcrireTexte(20,30,"Combien de colonne ?",2);
ChoisirCouleurDessin(CouleurParNom("white")); EcrireTexte(20,80,"Appuyez sur une touche",1);
RemplirRectangle(50,150,300,100); EcrireTexte(20,110,"entre 3 et 8",1);
ChoisirCouleurDessin(CouleurParNom("red"));
EcrireTexte(60,200,"Bravo",2);
EcrireTexte(60,230,"Appuyer pour quitter...",1);
Touche();
}
while(choix_colonne_fait ==0){
if(ToucheEnAttente()){
touche=Touche();
if (touche == XK_3 || touche == XK_KP_3) {
colonne = 3; choix_colonne_fait = 1;
}
else if (touche == XK_4 || touche == XK_KP_4) {
colonne = 4; choix_colonne_fait = 1;
}
else if (touche == XK_5 || touche == XK_KP_5) {
colonne = 5; choix_colonne_fait = 1;
}
else if (touche == XK_6 || touche == XK_KP_6) {
colonne = 6; choix_colonne_fait = 1;
}
else if (touche == XK_7 || touche == XK_KP_7) {
colonne = 7; choix_colonne_fait = 1;
}
else if (touche == XK_8 || touche == XK_KP_8) {
colonne = 8; choix_colonne_fait = 1;
}
if (touche == XK_q) { FermerGraphique(); return EXIT_SUCCESS; }
}
}
FermerGraphique();
init_affichage(ligne,colonne);
charger_image_source(nom_image);
initialiser_plateau(grille,ligne,colonne);
melanger_plateau(grille,ligne,colonne);
afficher_plateau(grille,ligne,colonne,coups);
while(jeu_fini == 0){
if (ToucheEnAttente()){
touche = Touche();
/* Pour quitter on clique sur q */
if (touche == XK_q || touche == XK_Q) break;
/* Déplacement +on affiche la nouvelle grille */
deplacer(grille,ligne,colonne,touche);
coups++;
afficher_plateau(grille,ligne,colonne,coups);
/*On vérifie si on a gagner */
if(verifier_victoire(grille,ligne,colonne) == 1 ){
jeu_fini = 1;
}
}
}
if (jeu_fini == 1){
ChoisirCouleurDessin(CouleurParNom("white"));
RemplirRectangle(50,150,300,100);
ChoisirCouleurDessin(CouleurParNom("red"));
EcrireTexte(60,200,"Bravo",2);
EcrireTexte(60,230,"Rejouer ? (O/N)",1);
while(1) {
touche = Touche();
if (touche == XK_o || touche == XK_O) {
FermerGraphique();
InitialiserGraphique();
break;
}
if (touche == XK_n || touche == XK_N) {
vouloir_rejouer = 0;
break;
}
}
}
}
fermer_affichage(); fermer_affichage();
+24 -31
View File
@@ -1,35 +1,35 @@
#include "partie.h" #include "partie.h"
/* On inclut stdio au cas où */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <graph.h> #include <graph.h>
void initialiser_plateau(int grille[NB_LIGNES][NB_COLS]){ void initialiser_plateau(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_colonne){
int i, j; int i, j;
int compteur = 1; int compteur = 1;
for (i = 0; i < NB_LIGNES; i++){ grille[0][0]=0;
for(j = 0; j < NB_COLS; j++){
for (i = 0; i < nb_ligne; i++){
for(j = 0; j < nb_colonne; j++){
/*On saute la 1er case*/
if (i == 0 && j== 0)continue;
grille[i][j] = compteur; grille[i][j] = compteur;
compteur++; compteur++;
} }
} }
/*On laisse la dernière case du tableu vide pour le taquin*/
grille[NB_LIGNES - 1 ][NB_COLS - 1] = 0;
} }
void deplacer(int grille[NB_LIGNES][NB_COLS], int touche) { void deplacer(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_colonne,int touche) {
int i, j; int i, j;
int vide_i, vide_j; int vide_i = -1, vide_j = -1;
int cible_i, cible_j; int cible_i, cible_j;
int temp; int temp;
/* Trouver la case vide */ /* Trouver la case vide */
vide_i = -1; for(i = 0; i < nb_ligne; i++) {
for(i = 0; i < NB_LIGNES; i++) { for(j = 0; j< nb_colonne; j++) {
for(j = 0; j< NB_COLS; j++) {
if (grille[i][j] == 0) { if (grille[i][j] == 0) {
/*vide i/j est l'adresse du trou*/ /*vide i/j est l'adresse du trou*/
vide_i = i; vide_i = i;
@@ -49,8 +49,8 @@ if(touche == XK_Up) cible_i = vide_i - 1;
if(touche == XK_Down) cible_i = vide_i + 1; if(touche == XK_Down) cible_i = vide_i + 1;
/* Vérifier les bords */ /* Vérifier les bords */
if (cible_i < 0 || cible_i >= NB_LIGNES || if (cible_i < 0 || cible_i >= nb_ligne ||
cible_j < 0 || cible_j >= NB_COLS) { cible_j < 0 || cible_j >= nb_colonne) {
return; return;
} }
@@ -60,7 +60,7 @@ grille[cible_i][cible_j] = 0;
grille[vide_i][vide_j] = temp; grille[vide_i][vide_j] = temp;
} }
void melanger_plateau(int grille[NB_LIGNES][NB_COLS]) { void melanger_plateau(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_colonne) {
int i; int i;
int touche_aleatoire; int touche_aleatoire;
int direction; int direction;
@@ -76,28 +76,21 @@ void melanger_plateau(int grille[NB_LIGNES][NB_COLS]) {
else if (direction == 1)touche_aleatoire = XK_Up; else if (direction == 1)touche_aleatoire = XK_Up;
else if (direction == 2)touche_aleatoire = XK_Right; else if (direction == 2)touche_aleatoire = XK_Right;
else touche_aleatoire = XK_Down; else touche_aleatoire = XK_Down;
deplacer(grille, touche_aleatoire); deplacer(grille,nb_ligne,nb_colonne,touche_aleatoire);
} }
} }
int verifier_victoire(int grille[NB_LIGNES][NB_COLS]){ int verifier_victoire(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_colonne){
int i,j,compteur = 1; int i,j,compteur = 1;
for(i = 0; i < NB_LIGNES; i++) { if(grille[0][0]!= 0)return 0;
for(j = 0; j< NB_COLS; j++) {
/*La dernière case en bas a droite doit être vide */ for(i = 0; i < nb_ligne; i++) {
if (i == NB_LIGNES - 1 && j == NB_COLS - 1){ for(j = 0; j< nb_colonne; j++) {
if(grille[i][j] != 0){ if (i == 0 && j == 0)continue;
return 0;
} if(grille[i][j] != compteur)return 0;
} compteur++;
else {
/*les autres cases doivent être dans l'orde*/
if(grille[i][j] != compteur){
return 0;
}
compteur++;
}
} }
} }
return 1; return 1;
+5 -5
View File
@@ -3,11 +3,11 @@
#include "config.h" #include "config.h"
void initialiser_plateau(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_cologne); void initialiser_plateau(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_colonne);
void deplacer(int grille[MAX_TAILLE][MAX_TAILLE], int touche); void deplacer(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_colonne, int touche);
void deplacer_souris(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_cologne,int clic_x,int clic_y); void deplacer_souris(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_colonne,int clic_x,int clic_y);
void melanger_plateau(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_cologne); void melanger_plateau(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_colonne);
int verifier_victoire(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_cologne); int verifier_victoire(int grille[MAX_TAILLE][MAX_TAILLE],int nb_ligne,int nb_colonne);
#endif #endif
Executable
BIN
View File
Binary file not shown.