début de la mise en commun des fichiers
This commit is contained in:
parent
47b3d39dc6
commit
6d1d07ae52
@ -1,3 +1,4 @@
|
||||
#include "timer.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
@ -148,7 +149,7 @@ void InsereTableau(int val, int* tab){
|
||||
}
|
||||
}
|
||||
|
||||
int main(void){
|
||||
int essay(void){
|
||||
int tab[4][5] = {{},{},{},{}};
|
||||
int o;
|
||||
int timerStop;
|
||||
@ -166,6 +167,7 @@ int main(void){
|
||||
ChoisirCouleurDessin(CouleurParComposante(0,0,0));
|
||||
DessinerGrille(GRILLE_X,GRILLE_Y,1500,844,0,found,tab);
|
||||
while(1){
|
||||
timer();
|
||||
if (ToucheEnAttente()){
|
||||
touche = Touche();
|
||||
if (touche == XK_t){
|
||||
@ -226,3 +228,5 @@ int main(void){
|
||||
FermerGraphique();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
27
affichage.h
Normal file
27
affichage.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef AFFICHAGE_H
|
||||
#define AFFICHAGE_H
|
||||
|
||||
#define GRILLE_X 4
|
||||
#define GRILLE_Y 4
|
||||
|
||||
int Trouvee(int found, int carte);
|
||||
|
||||
void DefinirCouleurs(couleur c[10]);
|
||||
|
||||
int ZoneRectangle(int upper_x, int upper_y, int lower_x, int lower_y);
|
||||
|
||||
void DessinerGrille(int x_g, int y_g, int x_fen, int y_fen, int triche, int* found, int tab[4][4]);
|
||||
|
||||
void Jeu(int x_g, int y_g, int x_fen, int y_fen, int* carte, int tab[4][4]);
|
||||
void GenererGrille(int x_grille, int y_grille, int tab[4][4]);
|
||||
|
||||
void Triche(int* triche);
|
||||
|
||||
int Victoire(int* found, int x_grille, int y_grille);
|
||||
|
||||
void InsereTableau(int val, int* tab);
|
||||
|
||||
int essay(void);
|
||||
|
||||
#endif /* AFFICHAGE_H */
|
||||
|
230
affichage_2.c
Normal file
230
affichage_2.c
Normal file
@ -0,0 +1,230 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
#define GRILLE_X 4
|
||||
#define GRILLE_Y 4
|
||||
|
||||
int Trouvee(int* found, int carte){
|
||||
int i;
|
||||
for (i=0;i<10;i++){
|
||||
if (found[i] == carte) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DefinirSprite(int c[10]){
|
||||
//Insère les couleurs dans le tableau c pris en argument
|
||||
c[0] = ChargerSprite("./test_sprite.png");
|
||||
c[1] = ChargerSprite("./test_sprites.png");
|
||||
c[2] = ChargerSprite("./test_sprites.png");
|
||||
c[3] = ChargerSprite("./test_sprites.png");
|
||||
c[4] = ChargerSprite("./test_sprites.png");
|
||||
c[5] = ChargerSprite("./test_sprites.png");
|
||||
c[6] = ChargerSprite("./test_sprites.png");
|
||||
c[7] = ChargerSprite("./test_sprites.png");
|
||||
c[8] = ChargerSprite("./test_sprites.png");
|
||||
c[9] = ChargerSprite("./test_sprites.png");
|
||||
}
|
||||
|
||||
int ZoneRectangle(int upper_x, int upper_y, int lower_x, int lower_y){
|
||||
//upper_x et upper_y sont les coordonnées du point supérieur gauche du rectangle
|
||||
//lower_x et lower_y sont les coordonnées du point inferieur droit du rectangle
|
||||
//La fonction renvoie 1 si la souris est dans la zone et renvoie 0 si elle n'y est pas
|
||||
SourisPosition();
|
||||
int pos_x = _X;
|
||||
int pos_y = _Y;
|
||||
if ((pos_x >= upper_x) && (pos_x <= lower_x) && (pos_y >= upper_y) && (pos_y <= lower_y))
|
||||
return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
void DessinerGrille(int x_g, int y_g, int x_fen, int y_fen, int triche, int* found, int tab[4][5]){
|
||||
// Dessine la grille des cartes en noir si le mode de triche est désactivé et dévoile les cartes si le mode triche est activé
|
||||
int i,j;
|
||||
int c[10];
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int l_case = (x_fen-((10*x_g)+10))/x_g;
|
||||
int h_case = (y_fen-((10*y_g)+10))/y_g;
|
||||
DefinirSprite(c);
|
||||
if (triche == 0){
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
for(i=10;i<x_fen-10;i+=l_case+10){
|
||||
for(j=10;j<y_fen-10;j+=h_case+10){
|
||||
if (Trouvee(found, tab[x][y])){
|
||||
AfficherSprite(c[tab[x][y]-1],i,j);
|
||||
}
|
||||
else{
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
RemplirRectangle(i,j,l_case,h_case);
|
||||
}
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
x=0;
|
||||
}
|
||||
}
|
||||
if (triche == 1){
|
||||
for(i=10;i<x_fen-10;i+=l_case+10){
|
||||
for(j=10;j<y_fen-10;j+=h_case+10){
|
||||
AfficherSprite(c[tab[x][y]-1],i,j);
|
||||
//RemplirRectangle(i,j,l_case,h_case);
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
x=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Jeu(int x_g, int y_g, int x_fen, int y_fen, int* carte, int tab[4][5]){
|
||||
int l_case = (x_fen-((10*x_g)+10))/x_g;
|
||||
int h_case = (y_fen-((10*y_g)+10))/y_g;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int i,j;
|
||||
int c[10];
|
||||
DefinirSprite(c);
|
||||
for(i=10;i<x_fen-10;i+=l_case+10){
|
||||
for(j=10;j<y_fen-10;j+=h_case+10){
|
||||
if (ZoneRectangle(i,j,i+l_case,j+h_case)){
|
||||
AfficherSprite(c[tab[x][y]-1],i,j);
|
||||
RemplirRectangle(i,j,l_case,h_case);
|
||||
carte[0] = tab[x][y];
|
||||
carte[1] = x;
|
||||
carte[2] = y;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
x=0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GenererGrille(int x_grille, int y_grille, int tab[4][5]){
|
||||
srand(Microsecondes());
|
||||
int i,j;
|
||||
int coos[2];
|
||||
for (i=0;i<x_grille;i++){
|
||||
for (j=0;j<y_grille;j++){
|
||||
tab[i][j] = 0;
|
||||
}
|
||||
}
|
||||
coos[0] = rand()%x_grille;
|
||||
coos[1] = rand()%y_grille;
|
||||
for (i=0;i<(x_grille*y_grille)/2;i++){
|
||||
for (j=0;j<2;j++){
|
||||
while (1){
|
||||
coos[0] = rand()%x_grille;
|
||||
coos[1] = rand()%y_grille;
|
||||
if (tab[coos[0]][coos[1]] == 0) break;
|
||||
}
|
||||
tab[coos[0]][coos[1]] = i+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Triche(int* triche){
|
||||
*triche = -(*triche);
|
||||
}
|
||||
|
||||
int Victoire(int* found, int x_grille, int y_grille){
|
||||
int i,j;
|
||||
for (i=0;i<(x_grille*y_grille)/2;i++){
|
||||
if (found[i] == 0) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void InsereTableau(int val, int* tab){
|
||||
int i;
|
||||
for (i=0;i<10;i++){
|
||||
if (tab[i] == 0){
|
||||
tab[i] = val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void){
|
||||
int tab[4][5] = {{},{},{},{}};
|
||||
int o;
|
||||
int timerStop;
|
||||
int i,j;
|
||||
int x=1;
|
||||
int temps;
|
||||
int touche;
|
||||
int retourne_time = 0;
|
||||
int found[10] = {};
|
||||
int carte_1[3] = {0,-1,-1};
|
||||
int carte_2[3] = {0,-1,-1};
|
||||
GenererGrille(GRILLE_Y, GRILLE_X, tab);
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(10,10,1500,844);
|
||||
ChoisirCouleurDessin(CouleurParComposante(0,0,0));
|
||||
DessinerGrille(GRILLE_X,GRILLE_Y,1500,844,0,found,tab);
|
||||
while(1){
|
||||
if (ToucheEnAttente()){
|
||||
touche = Touche();
|
||||
if (touche == XK_t){
|
||||
Triche(&x);
|
||||
if (x==-1){
|
||||
DessinerGrille(GRILLE_X,GRILLE_Y,1500,844,1,found,tab);
|
||||
timerStop = 1;
|
||||
}
|
||||
else{
|
||||
DessinerGrille(GRILLE_X,GRILLE_Y,1500,844,0,found,tab);
|
||||
timerStop = 0;
|
||||
}
|
||||
}
|
||||
if (touche == XK_space)
|
||||
break;
|
||||
touche = 0;
|
||||
}
|
||||
if (SourisCliquee()){
|
||||
if (x==1){
|
||||
|
||||
if (carte_1[0] == 0){
|
||||
Jeu(GRILLE_X,GRILLE_Y,1500,844,carte_1,tab);
|
||||
if (Trouvee(found,carte_1[0])){
|
||||
carte_1[0] = 0;
|
||||
}
|
||||
}
|
||||
else if (carte_2[0] == 0){
|
||||
Jeu(GRILLE_X,GRILLE_Y,1500,844,carte_2,tab);
|
||||
if (carte_1[1] == carte_2[1] && carte_1[2] == carte_2[2]) carte_2[0] = 0;
|
||||
if (Trouvee(found,carte_2[0])) carte_2[0] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (carte_1[0] == carte_2[0] && carte_1[0] != 0){
|
||||
InsereTableau(carte_1[0], found);
|
||||
}
|
||||
if (carte_1[0] != 0 && carte_2[0] != 0){
|
||||
carte_1[0] = 0;
|
||||
carte_1[1] = -1;
|
||||
carte_1[2] = -1;
|
||||
carte_2[0] = 0;
|
||||
carte_2[1] = -1;
|
||||
carte_2[2] = -1;
|
||||
temps = Microsecondes();
|
||||
retourne_time = Microsecondes()+1000000;
|
||||
while (temps < retourne_time){
|
||||
temps = Microsecondes();
|
||||
}
|
||||
DessinerGrille(GRILLE_X,GRILLE_Y,1500,844,0,found,tab);
|
||||
|
||||
}
|
||||
if (Victoire(found,GRILLE_X,GRILLE_Y)){
|
||||
printf("Victoire !\n");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
FermerGraphique();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
10
menu_v2.c
10
menu_v2.c
@ -1,6 +1,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
#include "affichage.h"
|
||||
|
||||
int menu_principal(void){
|
||||
//créeation de variable de position
|
||||
@ -80,7 +81,8 @@ int menu_principal(void){
|
||||
EffacerEcran(CouleurParNom("grey"));
|
||||
}
|
||||
if((x>537) && (x<958) && (y>266) && (y<696)){
|
||||
EffacerEcran(CouleurParNom("grey"));
|
||||
EffacerEcran(CouleurParNom("white"));
|
||||
essay();
|
||||
}
|
||||
if((x>1007) && (x<1432) && (y>266) && (y<696)) {
|
||||
EffacerEcran(CouleurParNom("grey"));
|
||||
@ -101,7 +103,8 @@ int menu_principal(void){
|
||||
EffacerEcran(CouleurParNom("grey"));
|
||||
}
|
||||
if((x>537) && (x<958) && (y>266) && (y<696)){
|
||||
EffacerEcran(CouleurParNom("grey"));
|
||||
EffacerEcran(CouleurParNom("white"));
|
||||
essay();
|
||||
}
|
||||
if((x>1007) && (x<1432) && (y>266) && (y<696)) {
|
||||
EffacerEcran(CouleurParNom("grey"));
|
||||
@ -122,7 +125,8 @@ int menu_principal(void){
|
||||
EffacerEcran(CouleurParNom("grey"));
|
||||
}
|
||||
if((x>537) && (x<958) && (y>266) && (y<696)){
|
||||
EffacerEcran(CouleurParNom("grey"));
|
||||
EffacerEcran(CouleurParNom("white"));
|
||||
essay();
|
||||
}
|
||||
if((x>1007) && (x<1432) && (y>266) && (y<696)) {
|
||||
EffacerEcran(CouleurParNom("grey"));
|
||||
|
BIN
test_sprite.png
Normal file
BIN
test_sprite.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 106 KiB |
65
timer.c
65
timer.c
@ -1,39 +1,48 @@
|
||||
#include "timer.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
|
||||
int main(void){
|
||||
unsigned long temps_ecoule = 0;
|
||||
unsigned long temps = Microsecondes();
|
||||
int timer;
|
||||
int seconde_passee;
|
||||
int minutes = 0;
|
||||
int secondes = 0;
|
||||
int a = 1;
|
||||
int temps_reference = 0;
|
||||
char afficher_temps[20];
|
||||
unsigned long temps_ecoule = 0;
|
||||
unsigned long temps = Microsecondes();
|
||||
int time;
|
||||
int seconde_passee;
|
||||
int minutes = 0;
|
||||
int secondes = 0;
|
||||
//int a = 1;
|
||||
int temps_reference = 0;
|
||||
char afficher_temps[20];
|
||||
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(10,10,1500,844);
|
||||
while(a==1){
|
||||
temps_ecoule = (int) (Microsecondes() - temps);
|
||||
if (temps_reference<temps_ecoule){
|
||||
temps_reference +=1;
|
||||
timer = (int) (temps_ecoule / 1000000);
|
||||
if (timer != seconde_passee){
|
||||
seconde_passee = timer;
|
||||
secondes = timer ;
|
||||
if (secondes > 59){
|
||||
minutes = secondes/60 ;
|
||||
secondes = secondes - (minutes*60);
|
||||
}
|
||||
EffacerEcran(CouleurParNom("white"));
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
snprintf(afficher_temps,15,"Time : %02d : %02d",minutes,secondes);
|
||||
EcrireTexte(700,50,afficher_temps,1);
|
||||
int timer(void){
|
||||
//unsigned long temps_ecoule = 0;
|
||||
//unsigned long temps = Microsecondes();
|
||||
//int timer;
|
||||
//int seconde_passee;
|
||||
//int minutes = 0;
|
||||
//int secondes = 0;
|
||||
//int a = 1;
|
||||
//int temps_reference = 0;
|
||||
//char afficher_temps[20];
|
||||
|
||||
temps_ecoule = (int) (Microsecondes() - temps);
|
||||
if (temps_reference<temps_ecoule){
|
||||
temps_reference +=1;
|
||||
time = (int) (temps_ecoule / 1000000);
|
||||
if (time != seconde_passee){
|
||||
seconde_passee = time;
|
||||
secondes = time ;
|
||||
if (secondes >59){
|
||||
minutes = secondes/60;
|
||||
secondes = secondes - (minutes * 60);
|
||||
}
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
RemplirRectangle(675,25,160,30);
|
||||
ChoisirCouleurDessin(CouleurParNom("white"));
|
||||
snprintf(afficher_temps,15,"Time : %02d : %02d",minutes,secondes);
|
||||
EcrireTexte(700,50,afficher_temps,1);
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user