update
34
DEV/DEV1.1_suite/TP_FILES/Makefile
Normal file
@@ -0,0 +1,34 @@
|
||||
# 1 : BUT FINAL
|
||||
|
||||
but : exe
|
||||
|
||||
# 2 : VARIABLES
|
||||
|
||||
OFILES = chaine.o \
|
||||
bouton.o \
|
||||
jeu.o \
|
||||
main.o
|
||||
|
||||
CC = gcc
|
||||
|
||||
CFLAGS = -Wall -g -lgraph
|
||||
|
||||
# 3 : DEPENDANCES (REGLES IMPLICITES)
|
||||
|
||||
bouton.o : chaine.h
|
||||
jeu.o : chaine.h bouton.h
|
||||
main.o : main.c chaine.h bouton.h jeu.h
|
||||
|
||||
#4 : DEPENDANCES AVEC COMMANDES
|
||||
|
||||
exe : $(OFILES)
|
||||
$(CC) $(CFLAGS) -o exe $(OFILES)
|
||||
|
||||
#5 : NETTOYAGE DES FICHIERS GENERES
|
||||
|
||||
clean :
|
||||
-rm -f $(OFILES) exe
|
||||
|
||||
#6 : BUTS FACTICES
|
||||
|
||||
.PHONY : but clean
|
32
DEV/DEV1.1_suite/TP_FILES/Makefile~
Normal file
@@ -0,0 +1,32 @@
|
||||
# 1 : BUT FINAL
|
||||
|
||||
but : exe
|
||||
|
||||
# 2 : VARIABLES
|
||||
|
||||
OFILES = chaine.o \
|
||||
jeu.o \
|
||||
main.o
|
||||
|
||||
CC = gcc
|
||||
|
||||
CFLAGS = -Wall -g -lgraph
|
||||
|
||||
# 3 : DEPENDANCES (REGLES IMPLICITES)
|
||||
|
||||
jeu.o : chaine.h
|
||||
main.o : main.c chaine.h jeu.h
|
||||
|
||||
#4 : DEPENDANCES AVEC COMMANDES
|
||||
|
||||
exe : $(OFILES)
|
||||
$(CC) $(CFLAGS) -o exe $(OFILES)
|
||||
|
||||
#5 : NETTOYAGE DES FICHIERS GENERES
|
||||
|
||||
clean :
|
||||
-rm -f $(OFILES) exe
|
||||
|
||||
#6 : BUTS FACTICES
|
||||
|
||||
.PHONY : but clean
|
87
DEV/DEV1.1_suite/TP_FILES/Q1_Chainees.c~
Normal file
@@ -0,0 +1,87 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
typedef struct m{
|
||||
char valeur;
|
||||
struct m* suivant;
|
||||
} maillon;
|
||||
|
||||
typedef struct file{
|
||||
maillon* debut;
|
||||
maillon* fin;
|
||||
}file;
|
||||
|
||||
int empty(file p_file){
|
||||
if (p_file.debut){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void enqueue(file* p_file, char new_valeur){
|
||||
maillon* new_maillon = (maillon*) malloc(sizeof(maillon));
|
||||
new_maillon->valeur = new_valeur;
|
||||
new_maillon->suivant = NULL;
|
||||
if ((*p_file).debut==NULL){
|
||||
p_file->debut = new_maillon;
|
||||
}
|
||||
else{
|
||||
(p_file->fin)->suivant = new_maillon;
|
||||
}
|
||||
p_file->fin = new_maillon;
|
||||
}
|
||||
|
||||
char dequeue(file* p_file){
|
||||
maillon* p_suivant=(p_file->debut)->suivant;
|
||||
char valeur = (p_file->debut)->valeur;
|
||||
free(p_file->debut);
|
||||
p_file->debut = p_suivant;
|
||||
return valeur;
|
||||
}
|
||||
|
||||
char old(file p_file){
|
||||
return (p_file.debut)->valeur;
|
||||
}
|
||||
|
||||
void clear(file* p_file){
|
||||
maillon* p_suivant = (*p_file).debut;
|
||||
while(p_suivant!=NULL){
|
||||
p_suivant = ((*p_file).debut)->suivant;
|
||||
free((*p_file).debut);
|
||||
p_file->debut = p_suivant;
|
||||
}
|
||||
p_file->fin = NULL;
|
||||
}
|
||||
|
||||
int main(void){
|
||||
int choix=99;
|
||||
char caractere;
|
||||
file p_file;
|
||||
p_file.debut=NULL;
|
||||
p_file.fin=NULL;
|
||||
printf("\n----------instruction----------\n1<char>- enqueue\n2- dequeue\n3- old\n4- clear\n5- quit\n----------------------------------\n");
|
||||
while(choix!=5){
|
||||
printf("choix : ");
|
||||
scanf("%d%c",&choix,&caractere);
|
||||
if (choix==1){
|
||||
enqueue(&p_file,caractere);
|
||||
}
|
||||
if (choix==2){
|
||||
if (empty(p_file)){
|
||||
printf("resultat : %c\n",dequeue(&p_file));
|
||||
}
|
||||
}
|
||||
if (choix==3){
|
||||
if (empty(p_file)){
|
||||
printf("resultat : %c\n",old(p_file));
|
||||
}
|
||||
}
|
||||
if (choix==4){
|
||||
clear(&p_file);
|
||||
printf("La liste à bien été vidé\n");
|
||||
}
|
||||
}
|
||||
clear(&p_file);
|
||||
printf("O revoir BG\n");
|
||||
return 0;
|
||||
}
|
47
DEV/DEV1.1_suite/TP_FILES/bouton.c
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <graph.h>
|
||||
|
||||
typedef struct bouton{
|
||||
int xmin;
|
||||
int xmax;
|
||||
int ymin;
|
||||
int ymax;
|
||||
}bouton;
|
||||
|
||||
|
||||
void creerBouton(bouton** boutons){
|
||||
int numBouton, x, y;
|
||||
*boutons= (bouton*) malloc(4*sizeof(bouton));
|
||||
for (numBouton=0, y=100; y<300; y+=150){
|
||||
for (x=100; x<300; x+=150, numBouton++){
|
||||
(*boutons)[numBouton].xmin=x;
|
||||
(*boutons)[numBouton].xmax=x+100;
|
||||
(*boutons)[numBouton].ymin=y;
|
||||
(*boutons)[numBouton].ymax=y+100;
|
||||
//afficheBouton(boutons[numBouton],0,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void afficheBouton(bouton* boutons, int numBouton, int etat){
|
||||
char chemin[21]="images/bouton?-?.png";
|
||||
chemin[13]= (char) (numBouton+48);
|
||||
chemin[15]= (char) (etat+48);
|
||||
ChargerImage(chemin,boutons[numBouton].xmin,boutons[numBouton].ymin,0,0,100,100);
|
||||
}
|
||||
|
||||
int detectClic(bouton* boutons, int choix){
|
||||
int numBouton;
|
||||
while(SourisCliquee());
|
||||
while(1){
|
||||
while (SourisCliquee()==0){}
|
||||
for (numBouton=0;numBouton<4; numBouton++){
|
||||
if (_X<boutons[numBouton].xmax && _X>boutons[numBouton].xmin && _Y<boutons[numBouton].ymax && _Y>boutons[numBouton].ymin){
|
||||
afficheBouton(boutons,choix,0);
|
||||
return numBouton;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
49
DEV/DEV1.1_suite/TP_FILES/bouton.c~
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <graph.h>
|
||||
|
||||
typedef struct bouton{
|
||||
int xmin;
|
||||
int xmax;
|
||||
int ymin;
|
||||
int ymax;
|
||||
}bouton;
|
||||
|
||||
|
||||
void creerBouton(bouton** boutons){
|
||||
int numBouton, x, y;
|
||||
*boutons= (bouton*) malloc(4*sizeof(bouton));
|
||||
for (numBouton=0, y=100; y<300; y+=150){
|
||||
for (x=100; x<300; x+=150, numBouton++){
|
||||
printf("%d) x=%d y=%d\n",numBouton,x,y);
|
||||
boutons[numBouton]->xmin=x;
|
||||
boutons[numBouton]->xmax=x+100;
|
||||
boutons[numBouton]->ymin=y;
|
||||
boutons[numBouton]->ymax=y+100;
|
||||
printf("finis\n");
|
||||
printf("%d %d %d %d\n",boutons[numBouton]->xmin,boutons[numBouton]->xmax,boutons[numBouton]->ymin,boutons[numBouton]->ymax);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void afficheBouton(bouton* boutons, int numBouton, int etat){
|
||||
char chemin[21]="images/bouton?-?.png";
|
||||
chemin[13]= (char) numBouton+48;
|
||||
chemin[13]= etat;
|
||||
ChargerImage(chemin,boutons[numBouton].xmin,boutons[numBouton].ymin,0,0,100,100);
|
||||
}
|
||||
|
||||
int detectClic(bouton* boutons, int choix){
|
||||
int numBouton;
|
||||
while(SourisCliquee());
|
||||
while(1){
|
||||
while (SourisCliquee()==0){}
|
||||
for (numBouton=0;numBouton<4; numBouton++){
|
||||
if (_X<boutons[numBouton].xmax && _X>boutons[numBouton].xmin && _Y<boutons[numBouton].ymax && _Y>boutons[numBouton].ymin){
|
||||
afficheBouton(boutons,choix,0);
|
||||
return numBouton;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
14
DEV/DEV1.1_suite/TP_FILES/bouton.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef BOUTON_H
|
||||
#define BOUTON_H
|
||||
|
||||
typedef struct bouton{
|
||||
int xmin;
|
||||
int xmax;
|
||||
int ymin;
|
||||
int ymax;
|
||||
}bouton;
|
||||
|
||||
void creerBouton(bouton** boutons);
|
||||
int detectClic(bouton* boutons, int choix);
|
||||
void afficheBouton(bouton* boutons, int numBouton, int etat);
|
||||
#endif
|
14
DEV/DEV1.1_suite/TP_FILES/bouton.h~
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef BOUTON_H
|
||||
#define BOUTON_H
|
||||
|
||||
typedef struct bouton{
|
||||
int xmin;
|
||||
int xmax;
|
||||
int ymin;
|
||||
int ymax;
|
||||
}bouton;
|
||||
|
||||
void creerBouton(bouton** boutons);
|
||||
int detectClic(bouton* boutons, int choix);
|
||||
void afficheBouton(bouton* boutons, int numBouton, int etat);
|
||||
#endif
|
BIN
DEV/DEV1.1_suite/TP_FILES/bouton.o
Normal file
95
DEV/DEV1.1_suite/TP_FILES/chaine.c
Normal file
@@ -0,0 +1,95 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
typedef struct maillon{
|
||||
int valeur;
|
||||
struct maillon* suivant;
|
||||
} maillon;
|
||||
|
||||
typedef struct file{
|
||||
maillon* debut;
|
||||
maillon* fin;
|
||||
}file;
|
||||
|
||||
int empty(file p_file){
|
||||
if (p_file.debut){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void creerFile(file* p_file){
|
||||
p_file->debut=NULL;
|
||||
p_file->fin=NULL;
|
||||
}
|
||||
|
||||
void enqueue(file* p_file, int new_valeur){
|
||||
maillon* new_maillon = (maillon*) malloc(sizeof(maillon));
|
||||
new_maillon->valeur = new_valeur;
|
||||
new_maillon->suivant = NULL;
|
||||
if (p_file->debut==NULL){
|
||||
p_file->debut = new_maillon;
|
||||
}
|
||||
else{
|
||||
(p_file->fin)->suivant = new_maillon;
|
||||
}
|
||||
p_file->fin = new_maillon;
|
||||
}
|
||||
|
||||
int dequeue(file* p_file){
|
||||
maillon* p_suivant=(p_file->debut)->suivant;
|
||||
int valeur = (p_file->debut)->valeur;
|
||||
free(p_file->debut);
|
||||
p_file->debut = p_suivant;
|
||||
return valeur;
|
||||
}
|
||||
|
||||
int first(file p_file){
|
||||
return (p_file.debut)->valeur;
|
||||
}
|
||||
|
||||
void clear(file* p_file){
|
||||
maillon* p_suivant = (*p_file).debut;
|
||||
while(p_suivant!=NULL){
|
||||
p_suivant = ((*p_file).debut)->suivant;
|
||||
free((*p_file).debut);
|
||||
p_file->debut = p_suivant;
|
||||
}
|
||||
p_file->fin = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
int main(void){
|
||||
int choix=99;
|
||||
int caractere;
|
||||
file p_file;
|
||||
creerFile(&p_file);
|
||||
printf("\n----------instruction----------\n1<char>- enqueue\n2- dequeue\n3- old\n4- clear\n5- quit\n----------------------------------\n");
|
||||
while(choix!=5){
|
||||
printf("choix : ");
|
||||
scanf(" %d",&choix);
|
||||
if (choix==1){
|
||||
printf("nombre : ");
|
||||
scanf(" %d",&caractere);
|
||||
enqueue(&p_file,caractere);
|
||||
}
|
||||
if (choix==2){
|
||||
if (empty(p_file)){
|
||||
printf("resultat : %d\n",dequeue(&p_file));
|
||||
}
|
||||
}
|
||||
if (choix==3){
|
||||
if (empty(p_file)){
|
||||
printf("resultat : %d\n",first(p_file));
|
||||
}
|
||||
}
|
||||
if (choix==4){
|
||||
clear(&p_file);
|
||||
printf("La liste à bien été vidé\n");
|
||||
}
|
||||
}
|
||||
clear(&p_file);
|
||||
printf("O revoir BG\n");
|
||||
return 0;
|
||||
}
|
||||
*/
|
93
DEV/DEV1.1_suite/TP_FILES/chaine.c~
Normal file
@@ -0,0 +1,93 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
typedef struct maillon{
|
||||
char valeur;
|
||||
struct maillon* suivant;
|
||||
} maillon;
|
||||
|
||||
typedef struct file{
|
||||
maillon* debut;
|
||||
maillon* fin;
|
||||
}file;
|
||||
|
||||
int empty(file p_file){
|
||||
if (p_file.debut){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void creerFile(file* p_file){
|
||||
p_file->debut=NULL;
|
||||
p_file->fin=NULL;
|
||||
}
|
||||
|
||||
void enqueue(file* p_file, char new_valeur){
|
||||
maillon* new_maillon = (maillon*) malloc(sizeof(maillon));
|
||||
new_maillon->valeur = new_valeur;
|
||||
new_maillon->suivant = NULL;
|
||||
if ((*p_file).debut==NULL){
|
||||
p_file->debut = new_maillon;
|
||||
}
|
||||
else{
|
||||
(p_file->fin)->suivant = new_maillon;
|
||||
}
|
||||
p_file->fin = new_maillon;
|
||||
}
|
||||
|
||||
char dequeue(file* p_file){
|
||||
maillon* p_suivant=(p_file->debut)->suivant;
|
||||
char valeur = (p_file->debut)->valeur;
|
||||
free(p_file->debut);
|
||||
p_file->debut = p_suivant;
|
||||
return valeur;
|
||||
}
|
||||
|
||||
char first(file p_file){
|
||||
return (p_file.debut)->valeur;
|
||||
}
|
||||
|
||||
void clear(file* p_file){
|
||||
maillon* p_suivant = (*p_file).debut;
|
||||
while(p_suivant!=NULL){
|
||||
p_suivant = ((*p_file).debut)->suivant;
|
||||
free((*p_file).debut);
|
||||
p_file->debut = p_suivant;
|
||||
}
|
||||
p_file->fin = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
int main(void){
|
||||
int choix=99;
|
||||
char caractere;
|
||||
file p_file;
|
||||
creerFile(&p_file);
|
||||
printf("\n----------instruction----------\n1<char>- enqueue\n2- dequeue\n3- old\n4- clear\n5- quit\n----------------------------------\n");
|
||||
while(choix!=5){
|
||||
printf("choix : ");
|
||||
scanf("%d%c",&choix,&caractere);
|
||||
if (choix==1){
|
||||
enqueue(&p_file,caractere);
|
||||
}
|
||||
if (choix==2){
|
||||
if (empty(p_file)){
|
||||
printf("resultat : %c\n",dequeue(&p_file));
|
||||
}
|
||||
}
|
||||
if (choix==3){
|
||||
if (empty(p_file)){
|
||||
printf("resultat : %c\n",first(p_file));
|
||||
}
|
||||
}
|
||||
if (choix==4){
|
||||
clear(&p_file);
|
||||
printf("La liste à bien été vidé\n");
|
||||
}
|
||||
}
|
||||
clear(&p_file);
|
||||
printf("O revoir BG\n");
|
||||
return 0;
|
||||
}
|
||||
*/
|
21
DEV/DEV1.1_suite/TP_FILES/chaine.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef CHAINE_H
|
||||
#define CHAINE_H
|
||||
|
||||
typedef struct maillon{
|
||||
int valeur;
|
||||
struct maillon* suivant;
|
||||
} maillon;
|
||||
|
||||
typedef struct file{
|
||||
maillon* debut;
|
||||
maillon* fin;
|
||||
}file;
|
||||
|
||||
void creerFile(file* p_file);
|
||||
int empty(file p_file);
|
||||
void enqueue(file* p_file, int new_valeur);
|
||||
int dequeue(file* p_file);
|
||||
int first(file p_file);
|
||||
void clear(file* p_file);
|
||||
|
||||
#endif
|
21
DEV/DEV1.1_suite/TP_FILES/chaine.h~
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef CHAINE_H
|
||||
#define CHAINE_H
|
||||
|
||||
typedef struct maillon{
|
||||
char valeur;
|
||||
struct maillon* suivant;
|
||||
} maillon;
|
||||
|
||||
typedef struct file{
|
||||
maillon* debut;
|
||||
maillon* fin;
|
||||
}file;
|
||||
|
||||
void creerFile(file* p_file);
|
||||
int empty(file p_file);
|
||||
void enqueue(file* p_file, char new_valeur);
|
||||
char dequeue(file* p_file);
|
||||
char first(file p_file);
|
||||
void clear(file* p_file);
|
||||
|
||||
#endif
|
BIN
DEV/DEV1.1_suite/TP_FILES/chaine.o
Normal file
BIN
DEV/DEV1.1_suite/TP_FILES/exe
Executable file
52
DEV/DEV1.1_suite/TP_FILES/graphique.c~
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <graph.h>
|
||||
|
||||
typedef struct bouton{
|
||||
int xmin;
|
||||
int xmax;
|
||||
int ymin;
|
||||
int ymax;
|
||||
}bouton;
|
||||
|
||||
|
||||
void creerBouton(bouton** boutons){
|
||||
int numBouton, x, y;
|
||||
for (numBouton=0, y=100; y<300; y+=150, numBouton++){
|
||||
for (x=100; x<300; x+=150){
|
||||
boutons[numBouton]->xmin=x;
|
||||
boutons[numBouton]->xmax=x+100;
|
||||
boutons[numBouton]->ymin=y;
|
||||
boutons[numBouton]->ymax=y+100;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int detectClic(bouton* boutons, long int* instant, int choix){
|
||||
int numBouton;
|
||||
while(1){
|
||||
while (SourisCliquee()==0){
|
||||
if (Microsecondes>*instant && choix >= 0 && choix <= 3){
|
||||
afficheBouton(boutons, choix, 0, instant);
|
||||
}
|
||||
}
|
||||
for (numBouton=0;numBouton<4; numBouton++){
|
||||
if (_X<boutons[numBouton].xmax && _X>boutons[numBouton].xmin && _Y<boutons[numBouton].ymax && _Y>boutons[numBouton].ymin){
|
||||
return numBouton;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void afficheBouton(bouton* boutons, int numBouton, int etat, long int* instant){
|
||||
if (Microsecondes()>*instant){
|
||||
char chemin[21]="images/bouton?-?.png";
|
||||
chemin[13]= (char) numBouton+48;
|
||||
chemin[13]= etat;
|
||||
ChargerImage(chemin,boutons[numBouton].xmin,boutons[numBouton].ymin,0,0,100,100);
|
||||
*instant = Microsecondes() + 500000;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
BIN
DEV/DEV1.1_suite/TP_FILES/images/bouton0-0.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
DEV/DEV1.1_suite/TP_FILES/images/bouton0-1.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
DEV/DEV1.1_suite/TP_FILES/images/bouton1-0.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
DEV/DEV1.1_suite/TP_FILES/images/bouton1-1.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
DEV/DEV1.1_suite/TP_FILES/images/bouton2-0.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
DEV/DEV1.1_suite/TP_FILES/images/bouton2-1.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
DEV/DEV1.1_suite/TP_FILES/images/bouton3-0.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
DEV/DEV1.1_suite/TP_FILES/images/bouton3-1.png
Normal file
After Width: | Height: | Size: 14 KiB |
63
DEV/DEV1.1_suite/TP_FILES/jeu.c
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <graph.h>
|
||||
#include "chaine.h"
|
||||
#include "bouton.h"
|
||||
|
||||
void nouvellePartie(file* file1){
|
||||
int newValeur = rand()%4;
|
||||
enqueue(file1,newValeur);
|
||||
}
|
||||
|
||||
void afficheCombinaison(file* file1, file* file2,bouton* boutons){
|
||||
int numBouton;
|
||||
long int instant=Microsecondes();
|
||||
while (empty(*file1)){
|
||||
numBouton = dequeue(file1);
|
||||
enqueue(file2, numBouton);
|
||||
while (Microsecondes()<instant){}
|
||||
afficheBouton(boutons,numBouton,1);
|
||||
instant = Microsecondes() + 500000;
|
||||
while (Microsecondes()<instant){}
|
||||
afficheBouton(boutons,numBouton,0);
|
||||
instant = Microsecondes() + 500000;
|
||||
//printf("%d ",numBouton);
|
||||
}
|
||||
//printf("\n");
|
||||
}
|
||||
|
||||
int verificateur(file* file1, file* file2, int choix){
|
||||
if (empty(*file2)){
|
||||
if (first(*file2)==choix){
|
||||
dequeue(file2);
|
||||
enqueue(file1,choix);
|
||||
return 1;
|
||||
}
|
||||
printf("PERDU !\n");
|
||||
return 0;
|
||||
}
|
||||
fprintf(stderr,"Erreur: Le joueur à réussi à jouer alors que le file de donnée était vide\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int partie(file* file1, file* file2,bouton* boutons){
|
||||
int choix;
|
||||
long int instant;
|
||||
printf("partie\n");
|
||||
nouvellePartie(file1);
|
||||
afficheCombinaison(file1,file2,boutons);
|
||||
while (empty(*file2)){
|
||||
//printf("choix : ");
|
||||
choix=detectClic(boutons,choix);
|
||||
afficheBouton(boutons,choix,1);
|
||||
//scanf("%d",&choix);
|
||||
if (verificateur(file1, file2, choix)==0){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
instant = Microsecondes() + 500000;
|
||||
while (Microsecondes()<instant){}
|
||||
afficheBouton(boutons,choix,0);
|
||||
return 1;
|
||||
}
|
62
DEV/DEV1.1_suite/TP_FILES/jeu.c~
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <graph.h>
|
||||
#include "chaine.h"
|
||||
#include "bouton.h"
|
||||
|
||||
void nouvellePartie(file* file1){
|
||||
int newValeur = rand()%4;
|
||||
enqueue(file1,newValeur);
|
||||
}
|
||||
|
||||
void afficheCombinaison(file* file1, file* file2,bouton* boutons){
|
||||
int numBouton;
|
||||
long int instant=Microsecondes();
|
||||
while (empty(*file1)){
|
||||
numBouton = dequeue(file1);
|
||||
enqueue(file2, numBouton);
|
||||
while (Microsecondes()<instant){}
|
||||
afficheBouton(boutons,numBouton,1);
|
||||
instant = Microsecondes() + 500000;
|
||||
while (Microsecondes()<instant){}
|
||||
afficheBouton(boutons,numBouton,0);
|
||||
instant = Microsecondes() + 500000;
|
||||
//printf("%d ",numBouton);
|
||||
}
|
||||
//printf("\n");
|
||||
}
|
||||
|
||||
int verificateur(file* file1, file* file2, int choix){
|
||||
if (empty(*file2)){
|
||||
if (first(*file2)==choix){
|
||||
dequeue(file2);
|
||||
enqueue(file1,choix);
|
||||
return 1;
|
||||
}
|
||||
printf("PERDU !\n");
|
||||
return 0;
|
||||
}
|
||||
fprintf(stderr,"Erreur: Le joueur à réussi à jouer alors que le file de donnée était vide\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int partie(file* file1, file* file2,bouton* boutons){
|
||||
int choix;
|
||||
long int instant;
|
||||
nouvellePartie(file1);
|
||||
afficheCombinaison(file1,file2,boutons);
|
||||
while (empty(*file2)){
|
||||
//printf("choix : ");
|
||||
choix=detectClic(boutons,choix);
|
||||
afficheBouton(boutons,choix,1);
|
||||
//scanf("%d",&choix);
|
||||
if (verificateur(file1, file2, choix)==0){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
instant = Microsecondes() + 500000;
|
||||
while (Microsecondes()<instant){}
|
||||
afficheBouton(boutons,choix,0);
|
||||
return 1;
|
||||
}
|
9
DEV/DEV1.1_suite/TP_FILES/jeu.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef JEU_H
|
||||
#define JEU_H
|
||||
|
||||
void nouvellePartie(file* file1);
|
||||
void afficheCombinaison(file* file1, file* file2,bouton* bouton);
|
||||
int verificateur(file* file1, file* file2, int choix);
|
||||
int partie(file* file1, file* file2,bouton* bouton);
|
||||
|
||||
#endif
|
9
DEV/DEV1.1_suite/TP_FILES/jeu.h~
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef JEU_H
|
||||
#define JEU_H
|
||||
|
||||
void nouvellePartie(file* file1);
|
||||
void afficheCombinaison(file* file1, file* file2);
|
||||
int verificateur(file* file1, file* file2, int choix);
|
||||
int partie(file* file1, file* file2);
|
||||
|
||||
#endif
|
BIN
DEV/DEV1.1_suite/TP_FILES/jeu.o
Normal file
25
DEV/DEV1.1_suite/TP_FILES/main.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <graph.h>
|
||||
#include <time.h>
|
||||
#include "chaine.h"
|
||||
#include "bouton.h"
|
||||
#include "jeu.h"
|
||||
//#include "tableau.c"
|
||||
|
||||
int main(void){
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(0,0,1000,1000);
|
||||
file file1, file2;
|
||||
int score;
|
||||
bouton* boutons;
|
||||
creerBouton(&boutons);
|
||||
creerFile(&file1);
|
||||
creerFile(&file2);
|
||||
srand(time(NULL));
|
||||
printf("test\n");
|
||||
for (score=1; partie(&file1,&file2,boutons)==1; score++){
|
||||
printf("\nBravo !!!\nScore=%d\n\n",score);
|
||||
}
|
||||
return 1;
|
||||
}
|
27
DEV/DEV1.1_suite/TP_FILES/main.c~
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <graph.h>
|
||||
#include <time.h>
|
||||
#include "chaine.h"
|
||||
#include "bouton.h"
|
||||
#include "jeu.h"
|
||||
//#include "tableau.c"
|
||||
|
||||
int main(void){
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(0,0,1000,1000);
|
||||
file file1, file2;
|
||||
int score;
|
||||
bouton* boutons;
|
||||
printf("test\n");
|
||||
creerBouton(&boutons);
|
||||
printf("test\n");
|
||||
creerFile(&file1);
|
||||
creerFile(&file2);
|
||||
srand(time(NULL));
|
||||
printf("test\n");
|
||||
for (score=1; partie(&file1,&file2,boutons)==1; score++){
|
||||
printf("\nBravo !!!\nScore=%d\n\n",score);
|
||||
}
|
||||
return 1;
|
||||
}
|
BIN
DEV/DEV1.1_suite/TP_FILES/main.o
Normal file
96
DEV/DEV1.1_suite/TP_FILES/tableau.c
Normal file
@@ -0,0 +1,96 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
typedef struct file{
|
||||
int* adresse;
|
||||
int debut;
|
||||
int fin;
|
||||
int capacite;
|
||||
}file;
|
||||
|
||||
int empty(file p_file){
|
||||
if (p_file.debut!=p_file.fin){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void creerFile(file* p_file){
|
||||
p_file->debut = 0;
|
||||
p_file->fin = 0;
|
||||
p_file->capacite = 4;
|
||||
p_file->adresse = (int*) malloc(p_file->capacite*sizeof(int));
|
||||
}
|
||||
|
||||
void decalage(file* p_file){
|
||||
int element;
|
||||
for (element=p_file->debut; element<=p_file->fin; element++){
|
||||
p_file->adresse[element-p_file->debut] = p_file->adresse[element];
|
||||
}
|
||||
p_file->fin -= p_file->debut;
|
||||
p_file->debut = 0;
|
||||
}
|
||||
|
||||
void enqueue(file* p_file, int newValeur){
|
||||
if (p_file->fin==p_file->capacite){
|
||||
if (p_file->debut==0){
|
||||
p_file->capacite *= 2;
|
||||
p_file->adresse = realloc(p_file->adresse, p_file->capacite*sizeof(int));
|
||||
}
|
||||
else{
|
||||
decalage(p_file);
|
||||
}
|
||||
}
|
||||
p_file->adresse[p_file->fin] = newValeur;
|
||||
p_file->fin ++;
|
||||
}
|
||||
|
||||
int dequeue(file* p_file){
|
||||
p_file->debut ++;
|
||||
return p_file->adresse[p_file->debut-1];
|
||||
}
|
||||
|
||||
int first(file p_file){
|
||||
return p_file.adresse[p_file.debut];
|
||||
}
|
||||
|
||||
void clear(file* p_file){
|
||||
p_file->debut = 0;
|
||||
p_file->fin = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
int main(void){
|
||||
int choix=99;
|
||||
int caractere;
|
||||
file p_file;
|
||||
creerFile(&p_file);
|
||||
printf("\n----------instruction----------\n1 <char>- enqueue\n2- dequeue\n3- first\n4- clear\n5- quit\n----------------------------------\n");
|
||||
while(choix!=5){
|
||||
printf("choix : ");
|
||||
scanf("%d",&choix);
|
||||
if (choix==1){
|
||||
printf("caractere : ");
|
||||
scanf(" %d",&caractere);
|
||||
enqueue(&p_file,caractere);
|
||||
}
|
||||
if (choix==2){
|
||||
if (empty(p_file)){
|
||||
printf("resultat : %d\n",dequeue(&p_file));
|
||||
}
|
||||
}
|
||||
if (choix==3){
|
||||
if (empty(p_file)){
|
||||
printf("resultat : %d\n",first(p_file));
|
||||
}
|
||||
}
|
||||
if (choix==4){
|
||||
clear(&p_file);
|
||||
printf("La liste à bien été vidé\n");
|
||||
}
|
||||
}
|
||||
clear(&p_file);
|
||||
printf("O revoir BG\n");
|
||||
return 0;
|
||||
}
|
||||
*/
|
94
DEV/DEV1.1_suite/TP_FILES/tableau.c~
Normal file
@@ -0,0 +1,94 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
typedef struct file{
|
||||
int* adresse;
|
||||
int debut;
|
||||
int fin;
|
||||
int capacite;
|
||||
}file;
|
||||
|
||||
int empty(file p_file){
|
||||
if (p_file.debut!=p_file.fin){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void creerFile(file* p_file){
|
||||
p_file->debut = 0;
|
||||
p_file->fin = 0;
|
||||
p_file->capacite = 4;
|
||||
p_file->adresse = (int*) malloc(p_file->capacite*sizeof(int));
|
||||
}
|
||||
|
||||
void decalage(file* p_file){
|
||||
int element;
|
||||
for (element=p_file->debut; element<=p_file->fin; element++){
|
||||
p_file->adresse[element-p_file->debut] = p_file->adresse[element];
|
||||
}
|
||||
p_file->fin -= p_file->debut;
|
||||
p_file->debut = 0;
|
||||
}
|
||||
|
||||
void enqueue(file* p_file, int newValeur){
|
||||
if (p_file->fin==p_file->capacite){
|
||||
if (p_file->debut==0){
|
||||
p_file->capacite *= 2;
|
||||
p_file->adresse = realloc(p_file->adresse, p_file->capacite*sizeof(int));
|
||||
}
|
||||
else{
|
||||
decalage(p_file);
|
||||
}
|
||||
}
|
||||
p_file->adresse[p_file->fin] = newValeur;
|
||||
p_file->fin ++;
|
||||
}
|
||||
|
||||
int dequeue(file* p_file){
|
||||
p_file->debut ++;
|
||||
return p_file->adresse[p_file->debut-1];
|
||||
}
|
||||
|
||||
int first(file p_file){
|
||||
return p_file.adresse[p_file.debut];
|
||||
}
|
||||
|
||||
void clear(file* p_file){
|
||||
p_file->debut = 0;
|
||||
p_file->fin = 0;
|
||||
}
|
||||
|
||||
int main(void){
|
||||
int choix=99;
|
||||
int caractere;
|
||||
file p_file;
|
||||
creerFile(&p_file);
|
||||
printf("\n----------instruction----------\n1 <char>- enqueue\n2- dequeue\n3- first\n4- clear\n5- quit\n----------------------------------\n");
|
||||
while(choix!=5){
|
||||
printf("choix : ");
|
||||
scanf("%d",&choix);
|
||||
if (choix==1){
|
||||
printf("caractere : ");
|
||||
scanf(" %d",&caractere);
|
||||
enqueue(&p_file,caractere);
|
||||
}
|
||||
if (choix==2){
|
||||
if (empty(p_file)){
|
||||
printf("resultat : %d\n",dequeue(&p_file));
|
||||
}
|
||||
}
|
||||
if (choix==3){
|
||||
if (empty(p_file)){
|
||||
printf("resultat : %d\n",first(p_file));
|
||||
}
|
||||
}
|
||||
if (choix==4){
|
||||
clear(&p_file);
|
||||
printf("La liste à bien été vidé\n");
|
||||
}
|
||||
}
|
||||
clear(&p_file);
|
||||
printf("O revoir BG\n");
|
||||
return 0;
|
||||
}
|