Accueil > > > JEU DE CODE SECRET
JEU DE CODE SECRET
Information sur la source
Description
Jeu que j'ai invente, il s'agit de remettre dans l'ordre la serie de chiffre 0123456789 initialement dans le desordre en un minimum de coup. Pour cela on execute des permutations, les chiffres respectivement immediatement a droite et a gauche du choix se retrouvent reportes respectivement a l'extreme gauche et a l'extreme droite de la combinaison.
Source
- code du fichier vague.c
- /* jeu de la vague des chiffres */
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
- #include <ctype.h>
-
- #define max 10
- #define bleu 9
- #define rouge 12
- #define blanc 15
- #define blink 128
-
- typedef enum {faux, vrai} booleen;
-
- int f1 (void);
- int f2 (void);
- int f3 (void);
- int f4 (void);
- int f5 (void);
- void page_garde (char *, int);
- void continuation (void);
- void duree (long, long);
- void ouverture (char *);
- void fermeture (char *);
- void raz (char *);
- void tri (void);
- void genere_nb (int *);
- void affiche (int *);
- void deplace (int *, int);
- booleen comparaison (int *);
-
- struct {
- int elt;
- int (*f)();
- }
- tableau[]={
- {1, f1},
- {2, f2},
- {3, f3},
- {4, f4},
- {5, f5}
- };
- struct result {
- int coup;
- int temp;
- char nom[21];
- };
- struct result resultat[11];
- int tab[max], premier;
- FILE * fichier;
-
- void main()
- {
- int ind=0;
- char chy;
-
- page_garde("LOGICIEL DU JEU DE LA VAGUE", 1999);
- ouverture("vague_sc.txt");
- while (ind<5)
- {
- clrscr();
- printf("Menu general:");
- printf("\n<R>egle du jeu.");
- printf("\nJouer contre l'<O>rdinateur.");
- printf("\n<V>oir les meilleurs scores.");
- printf("\n<Q>uitter.\nQuel est votre choix? : ");
- fflush(stdin);
- scanf("%c", &chy);
- if (chy=='q' || chy=='Q')
- ind=5;
- else
- if (chy=='o' || chy=='O')
- ind=1;
- else
- if (chy=='r' || chy=='R')
- ind=2;
- else
- if (chy=='v' || chy=='V')
- ind=4;
- else
- ind=3;
- ind=(*tableau[ind-1].f)();
- }
- fermeture("vague_sc.txt");
- clrscr();
- }
-
- int f1 (void) /* jeu */
- {
- int position, erreur, test, cpt, i, indicateur, x, y, cl;
- char chx='o', name[21];
- long t0, t1;
- booleen comp;
-
- clrscr();
- printf("Veuillez entrez votre nom puis valider : ");
- fflush(stdin);
- gets(name);
- for (i=0; i<strlen(name); i++) /* convertit le nom en majuscule */
- name[i]=toupper(name[i]);
- while (chx=='o' || chx=='O')
- {
- indicateur=0;
- cpt=0;
- t0=time(0);
- comp=faux;
- genere_nb(tab);
- while (!comp)
- {
- clrscr();
- cpt++;
- textcolor(blink+blanc);
- cprintf("< TAPEZ <0> POUR QUITTER A TOUT MOMENT >\n\n\r");
- textcolor(blanc);
- affiche (tab);
- do
- {
- erreur=0;
- indicateur=0;
- x=wherex();
- y=wherey();
- printf("\nQuelle position souhaitez-vous jouer (entre 1 et 9)? : ");
- fflush(stdin);
- scanf("%d", &position);
- if (position==0)
- {
- indicateur=f5(); /* ind=5 quitter */
- if (indicateur==5) /* ind=1 continuer */
- break;
- }
- if (position>=max || position<=0)
- if (indicateur!=1) /* ind=0 */
- {
- erreur=f3();
- gotoxy(x, y+1);
- delline();
- gotoxy(x, y);
- }
- else /* ind=1 */
- {
- gotoxy(1, y+1);
- for (cl=0; cl<4; cl++)
- delline();
- gotoxy(x, y);
- erreur=3;
- }
- }
- while (erreur==3);
- if (indicateur==5)
- break;
- deplace (tab, position);
- comp=comparaison(tab);
- }
- if (indicateur==5)
- break;
- t1=time(0);
- clrscr();
- affiche (tab);
- if (cpt==1)
- {
- textcolor(bleu);
- cprintf("\n\n\n\rBravo, %s, vous gagnez en %d coup et ", name, cpt);
- duree(t0, t1);
- textcolor(blanc);
- }
- else
- {
- textcolor(bleu);
- cprintf("\n\n\rBravo, %s, vous gagnez en %d coups et ", name, cpt);
- duree(t0, t1);
- textcolor(blanc);
- }
- resultat[0].coup=cpt;
- resultat[0].temp=(int)(t1-t0);
- strcpy(resultat[0].nom, name);
- if (premier<=10 || cpt<=resultat[premier].coup)
- tri();
- if (premier<10)
- premier++;
- do
- {
- test=0;
- x=wherex();
- y=wherey();
- printf("\n\nVoulez-vous rejouer? <O>ui, <N>on : ");
- fflush(stdin);
- scanf("%c", &chx);
- if (chx!='o' && chx!='O' && chx!='n' && chx!='N')
- test=f3();
- gotoxy(1, y+2);
- delline();
- gotoxy(x, y);
- }
- while (test==3);
- }
- clrscr();
- return(1);
- }
-
- int f2 (void) /* regle du jeu */
- {
- char aide1[1000]="", choix='S';
- int test, y, cl;
-
- clrscr();
- if ((fichier=fopen("vague.txt", "r+"))!=NULL)
- {
- fread(&aide1, 780, 1, fichier);
- fclose(fichier);
- fflush(stdin);
- puts(aide1);
- do
- {
- test=0;
- y=wherey();
- printf("\n<Q>uitter : ");
- fflush(stdin);
- scanf("%c", &choix);
- if (choix!='q' && choix!='Q')
- {
- textcolor(rouge);
- cprintf("\n\rChoix impossible!!!\a");
- continuation();
- gotoxy(1, y);
- for (cl=0; cl<6; cl++)
- delline();
- test=3;
- }
- }
- while (test==3);
- }
- else
- {
- printf("Le fichier d'aide est absent.\n");
- f3();
- }
- return(2);
- }
-
- int f3 (void) /* traitement des erreurs */
- {
- int x, y, cl;
-
- x=wherex();
- y=wherey();
- textcolor(rouge);
- cprintf("\n\rChoix impossible!!!\a");
- continuation();
- gotoxy(1, y);
- for (cl=0; cl<6; cl++)
- delline();
- gotoxy(x, y);
- return(3);
- }
-
- int f4 (void) /* affichage des scores */
- {
- int i, j, ind_erreur, x, y, param1, param2;
- char chw, chq;
-
- clrscr();
- gotoxy(35, 1);
- printf("CLASSEMENT\n\n");
- printf(" coups temps nom");
- for (i=1; i<=premier; i++)
- {
- printf("\n%2d : ", i);
- printf("%2d", resultat[i].coup);
- param1=(resultat[i].temp)%60;
- param2=(resultat[i].temp-param1)/60;
- if (param2>60)
- param2=60;
- printf(" %2d.%02d ", param2, param1);
- j=0;
- do
- {
- putchar((resultat[i].nom)[j]);
- j++;
- }
- while((isalpha((resultat[i].nom)[j])) || (((resultat[i].nom)[j])=='-'));
- }
- gotoxy(1, 15);
- do
- {
- ind_erreur=1;
- printf("<Q>uitter, <E>ffacer les scores : ");
- fflush(stdin);
- scanf("%c", &chw);
- if (chw!='q' && chw!='Q' && chw!='e' && chw!='E')
- {
- ind_erreur=f3();
- gotoxy(1, 15);
- delline();
- gotoxy(1, 15);
- }
- }
- while (ind_erreur==3);
- if (chw=='e' || chw=='E')
- {
- do
- {
- x=wherex();
- y=wherey();
- ind_erreur=1;
- printf("\nVoulez-vous vraiment effacer les scores? <O>ui, <N>on : ");
- fflush(stdin);
- scanf("%c", &chq);
- if (chq=='n' || chq=='N')
- f4();
- else
- if ((chq=='o' || chq=='O') && premier!=0)
- {
- raz("vague_sc.txt");
- break;
- }
- else
- {
- ind_erreur=f3();
- gotoxy(1, y+1);
- delline();
- gotoxy(x, y);
- }
- }
- while (ind_erreur==3);
- }
- return(2);
- }
-
- int f5 (void) /* quitter */
- {
- int dip=1, x, y;
- char cht;
-
- x=wherex();
- y=wherey();
- do
- {
- printf("\nVoulez-vous vraiment quitter? <O>ui, <N>on : ");
- fflush(stdin);
- scanf("%c", &cht);
- if (cht=='o' || cht=='O')
- dip=5;
- else
- if (cht=='n' || cht=='N')
- dip=1;
- else
- {
- dip=f3();
- gotoxy(1, y);
- delline();
- delline();
- gotoxy(x, y);
- }
- }
- while (dip==3);
- return(dip);
- }
-
- void page_garde (char pgm[], int an)
- {
- char txt[60], txt0[2];
-
- clrscr();
- textcolor(blanc);
- strcpy(txt, "***************************************************");
- gotoxy(15, 8);
- puts(txt);
- strcpy(txt0, "*");
- gotoxy(15, 9);
- puts(txt0);
- gotoxy(65, 9);
- puts(txt0);
- gotoxy(15, 10);
- puts(txt0);
- gotoxy((int)(41-(strlen(pgm))/2), 10);
- puts(pgm);
- gotoxy(65, 10);
- puts(txt0);
- gotoxy(15, 11);
- puts(txt0);
- gotoxy(65, 11);
- puts(txt0);
- gotoxy(15, 12);
- puts(txt0);
- gotoxy(65, 12);
- puts(txt0);
- strcpy(txt, "* COPYRIGHT ALEXANDRE ROGER");
- gotoxy(15, 13);
- puts(txt);
- gotoxy(52, 13);
- printf("%d", an);
- gotoxy(65, 13);
- puts(txt0);
- gotoxy(15, 14);
- puts(txt0);
- gotoxy(65, 14);
- puts(txt0);
- gotoxy(15, 15);
- puts(txt0);
- gotoxy(65, 15);
- puts(txt0);
- gotoxy(15, 16);
- puts(txt0);
- textcolor(blanc+blink);
- gotoxy(20, 16);
- cprintf("< APPUYEZ SUR UNE TOUCHE POUR CONTINUER >");
- textcolor(blanc);
- gotoxy(65, 16);
- puts(txt0);
- gotoxy(15, 17);
- puts(txt0);
- gotoxy(65, 17);
- puts(txt0);
- strcpy(txt, "***************************************************");
- gotoxy(15, 18);
- puts(txt);
- gotoxy(80, 25);
- getch();
- }
-
- void continuation (void)
- {
- textcolor(blink+blanc);
- cprintf("\n\n\r< APPUYEZ SUR UNE TOUCHE POUR CONTINUER >");
- textcolor(blanc);
- gotoxy(80, 25);
- getch();
- }
-
- void duree (long tpa, long tpb)
- {
- long mn, sec;
-
- sec=(tpb-tpa)%60;
- mn=(tpb-tpa-sec)/60;
- if (tpa==tpb)
- cprintf("%ld seconde", sec);
- else
- if (mn==0)
- cprintf("%ld secondes", sec);
- else
- if (mn==1 && sec==0)
- cprintf("%ld minute", mn);
- else
- if (mn==1 && sec==1)
- cprintf("%ld minute et %ld seconde", mn, sec);
- else
- if (mn==1 && sec>1)
- cprintf("%ld minute et %ld secondes", mn, sec);
- else
- if (mn>1 && sec==0)
- cprintf("%ld minutes", mn);
- else
- if (mn>1 && sec==1)
- cprintf("%ld minutes et %ld seconde", mn, sec);
- else
- cprintf("%ld minutes et %ld secondes", mn, sec);
- }
-
- void ouverture (char fic[])
- {
- int i;
-
- if ((fichier=fopen(fic, "r+"))!=NULL)
- {
- fread(&premier, 1, 1, fichier);
- if (premier!=0)
- {
- for (i=1; i<=premier; i++)
- {
- fseek(fichier, 10+3*i, 0);
- fflush(stdin);
- fread(&(resultat[i].coup), 2, 1, fichier);
- fseek(fichier, 50+5*i, 0);
- fflush(stdin);
- fread(&(resultat[i].temp), 4, 1, fichier);
- fseek(fichier, 120+30*i, 0);
- fflush(stdin);
- fread(&(resultat[i].nom), 21, 1, fichier);
- }
- }
- fclose(fichier);
- }
- else
- raz (fic);
- }
-
- void fermeture (char fic[]) /* r‚‚criture dans le fichier */
- {
- int i;
-
- fichier=fopen(fic, "w");
- fseek(fichier, 0, 0);
- fflush(stdin);
- fwrite(&premier, sizeof(premier), 1, fichier);
- if (premier!=0)
- {
- for (i=1; i<=premier; i++)
- {
- fseek(fichier, 10+3*i, 0);
- fflush(stdin);
- fwrite(&(resultat[i].coup), sizeof(resultat[i].coup), 1, fichier);
- fseek(fichier, 50+5*i, 0);
- fflush(stdin);
- fwrite(&(resultat[i].temp), sizeof(resultat[i].temp), 1, fichier);
- fseek(fichier, 120+30*i, 0);
- fflush(stdin);
- fwrite(&(resultat[i].nom), 1+strlen(resultat[i].nom), 1, fichier);
- }
- }
- fclose(fichier);
- }
-
- void raz (char fic[])
- {
- premier=0;
- fichier=fopen(fic, "w");
- fseek(fichier, 0, 0);
- fflush(stdin);
- fwrite(&premier, sizeof(premier), 1, fichier);
- fclose(fichier);
- }
-
- void tri (void)
- {
- int i=0, j;
-
- while ((i<=premier) && (resultat[0].coup>=resultat[i].coup))
- {
- if (resultat[0].coup==resultat[i].coup)
- if (resultat[0].temp<resultat[i].temp)
- break;
- i++;
- if (premier==0)
- break;
- }
- if (i<10)
- {
- for (j=0; j<=premier-i; j++)
- {
- resultat[premier+1-j].coup=resultat[premier-j].coup;
- resultat[premier+1-j].temp=resultat[premier-j].temp;
- strcpy(resultat[premier+1-j].nom, resultat[premier-j].nom);
- }
- }
- if (i<11)
- {
- resultat[i].coup=resultat[0].coup;
- resultat[i].temp=resultat[0].temp;
- strcpy(resultat[i].nom, resultat[0].nom);
- }
- }
-
- void genere_nb (int ta[max])
- {
- int i, alpha;
- time_t temps;
-
- for (i=0; i<max; i++)
- ta[i]=i;
- srand ((unsigned)time (&temps));
- alpha=rand()%100;
- srand ((unsigned)time (&temps));
- for (i=0; i<1+rand()%alpha; i++)
- deplace (ta, 1+rand()%9);
- }
-
- void affiche (int t0[max])
- {
- int i;
-
- gotoxy(17, 3);
- printf("positions ---> ");
- for (i=1; i<max; i++)
- printf("%d ", i);
- gotoxy(17, 4);
- printf("code secret : ");
- for (i=0; i<max-1; i++)
- printf("%d.", t0[i]);
- printf("%d", t0[max-1]);
- }
-
- void deplace (int t1[max], int pos)
- {
- int tbis[2], i, j;
-
- tbis[0]=t1[pos-1];
- tbis[1]=t1[pos];
- for (i=0; i<=pos-2; i++)
- t1[pos-1-i]=t1[pos-2-i];
- t1[0]=tbis[0];
- for (j=0; j<=8-pos; j++)
- t1[pos+j]=t1[pos+1+j];
- t1[9]=tbis[1];
- }
-
- booleen comparaison (int t3[max])
- {
- int tprim[max], i;
-
- for (i=0; i<max; i++)
- tprim[i]=i;
- i=0;
- while (i<max)
- {
- if (t3[i]==tprim[i])
- i++;
- else
- break;
- }
- if (i==max)
- return(vrai);
- else return(faux);
- }
-
- -------------------------------------------------------------------------------------
- code du fichier vague.txt
- /* ‚criture dans un fichier */
- #include <errno.h>
- #include <ctype.h>
- #include <stdio.h>
- #include <conio.h>
-
- void main()
- {
- FILE *fichier;
- char buf[3000]="";
-
- strcpy(buf," REGLE DU JEU.\n\n\n");
- strcat(buf,"Les chiffres du code secret, initialement dans l'ordre suivant 0123456789, ont\n‚t?brouilles. Il convient de reconstituer la combinaison en un minimum de\ntentatives.");
- strcat(buf,"\nPour cela, on choisit une position entre 2 chiffres (par exemple, celle ‚tant\nsitue entre le quatriŠme et le cinquieme chiffre est la position 4), puis on\nd‚place le chiffre situ??gauche de la position choisie pour le placer en\npremiŠre position (extrˆme gauche); tandis que le chiffre situ??droite de la\nposition choisie est d‚plac?pour ˆtre positionnee en derniere position (extreme\ndroite).");
- strcat(buf," On recommence jusqu'?reconstituer la sequence initiale: 0123456789.");
- strcat(buf,"\nExemple:\nCombinaison brouillee: 3569102478.\nOn joue en position 4.\nLa serie devient: 9356024781.");
- clrscr();
- fichier=fopen("vague.txt", "w+");
- fwrite(&buf, strlen(buf), 1, fichier);
- fclose(fichier);
- printf("Fin d'‚criture!... Appuyez sur une touche pour continuer.");
- getch();
- }
code du fichier vague.c
/* jeu de la vague des chiffres */
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#define max 10
#define bleu 9
#define rouge 12
#define blanc 15
#define blink 128
typedef enum {faux, vrai} booleen;
int f1 (void);
int f2 (void);
int f3 (void);
int f4 (void);
int f5 (void);
void page_garde (char *, int);
void continuation (void);
void duree (long, long);
void ouverture (char *);
void fermeture (char *);
void raz (char *);
void tri (void);
void genere_nb (int *);
void affiche (int *);
void deplace (int *, int);
booleen comparaison (int *);
struct {
int elt;
int (*f)();
}
tableau[]={
{1, f1},
{2, f2},
{3, f3},
{4, f4},
{5, f5}
};
struct result {
int coup;
int temp;
char nom[21];
};
struct result resultat[11];
int tab[max], premier;
FILE * fichier;
void main()
{
int ind=0;
char chy;
page_garde("LOGICIEL DU JEU DE LA VAGUE", 1999);
ouverture("vague_sc.txt");
while (ind<5)
{
clrscr();
printf("Menu general:");
printf("\n<R>egle du jeu.");
printf("\nJouer contre l'<O>rdinateur.");
printf("\n<V>oir les meilleurs scores.");
printf("\n<Q>uitter.\nQuel est votre choix? : ");
fflush(stdin);
scanf("%c", &chy);
if (chy=='q' || chy=='Q')
ind=5;
else
if (chy=='o' || chy=='O')
ind=1;
else
if (chy=='r' || chy=='R')
ind=2;
else
if (chy=='v' || chy=='V')
ind=4;
else
ind=3;
ind=(*tableau[ind-1].f)();
}
fermeture("vague_sc.txt");
clrscr();
}
int f1 (void) /* jeu */
{
int position, erreur, test, cpt, i, indicateur, x, y, cl;
char chx='o', name[21];
long t0, t1;
booleen comp;
clrscr();
printf("Veuillez entrez votre nom puis valider : ");
fflush(stdin);
gets(name);
for (i=0; i<strlen(name); i++) /* convertit le nom en majuscule */
name[i]=toupper(name[i]);
while (chx=='o' || chx=='O')
{
indicateur=0;
cpt=0;
t0=time(0);
comp=faux;
genere_nb(tab);
while (!comp)
{
clrscr();
cpt++;
textcolor(blink+blanc);
cprintf("< TAPEZ <0> POUR QUITTER A TOUT MOMENT >\n\n\r");
textcolor(blanc);
affiche (tab);
do
{
erreur=0;
indicateur=0;
x=wherex();
y=wherey();
printf("\nQuelle position souhaitez-vous jouer (entre 1 et 9)? : ");
fflush(stdin);
scanf("%d", &position);
if (position==0)
{
indicateur=f5(); /* ind=5 quitter */
if (indicateur==5) /* ind=1 continuer */
break;
}
if (position>=max || position<=0)
if (indicateur!=1) /* ind=0 */
{
erreur=f3();
gotoxy(x, y+1);
delline();
gotoxy(x, y);
}
else /* ind=1 */
{
gotoxy(1, y+1);
for (cl=0; cl<4; cl++)
delline();
gotoxy(x, y);
erreur=3;
}
}
while (erreur==3);
if (indicateur==5)
break;
deplace (tab, position);
comp=comparaison(tab);
}
if (indicateur==5)
break;
t1=time(0);
clrscr();
affiche (tab);
if (cpt==1)
{
textcolor(bleu);
cprintf("\n\n\n\rBravo, %s, vous gagnez en %d coup et ", name, cpt);
duree(t0, t1);
textcolor(blanc);
}
else
{
textcolor(bleu);
cprintf("\n\n\rBravo, %s, vous gagnez en %d coups et ", name, cpt);
duree(t0, t1);
textcolor(blanc);
}
resultat[0].coup=cpt;
resultat[0].temp=(int)(t1-t0);
strcpy(resultat[0].nom, name);
if (premier<=10 || cpt<=resultat[premier].coup)
tri();
if (premier<10)
premier++;
do
{
test=0;
x=wherex();
y=wherey();
printf("\n\nVoulez-vous rejouer? <O>ui, <N>on : ");
fflush(stdin);
scanf("%c", &chx);
if (chx!='o' && chx!='O' && chx!='n' && chx!='N')
test=f3();
gotoxy(1, y+2);
delline();
gotoxy(x, y);
}
while (test==3);
}
clrscr();
return(1);
}
int f2 (void) /* regle du jeu */
{
char aide1[1000]="", choix='S';
int test, y, cl;
clrscr();
if ((fichier=fopen("vague.txt", "r+"))!=NULL)
{
fread(&aide1, 780, 1, fichier);
fclose(fichier);
fflush(stdin);
puts(aide1);
do
{
test=0;
y=wherey();
printf("\n<Q>uitter : ");
fflush(stdin);
scanf("%c", &choix);
if (choix!='q' && choix!='Q')
{
textcolor(rouge);
cprintf("\n\rChoix impossible!!!\a");
continuation();
gotoxy(1, y);
for (cl=0; cl<6; cl++)
delline();
test=3;
}
}
while (test==3);
}
else
{
printf("Le fichier d'aide est absent.\n");
f3();
}
return(2);
}
int f3 (void) /* traitement des erreurs */
{
int x, y, cl;
x=wherex();
y=wherey();
textcolor(rouge);
cprintf("\n\rChoix impossible!!!\a");
continuation();
gotoxy(1, y);
for (cl=0; cl<6; cl++)
delline();
gotoxy(x, y);
return(3);
}
int f4 (void) /* affichage des scores */
{
int i, j, ind_erreur, x, y, param1, param2;
char chw, chq;
clrscr();
gotoxy(35, 1);
printf("CLASSEMENT\n\n");
printf(" coups temps nom");
for (i=1; i<=premier; i++)
{
printf("\n%2d : ", i);
printf("%2d", resultat[i].coup);
param1=(resultat[i].temp)%60;
param2=(resultat[i].temp-param1)/60;
if (param2>60)
param2=60;
printf(" %2d.%02d ", param2, param1);
j=0;
do
{
putchar((resultat[i].nom)[j]);
j++;
}
while((isalpha((resultat[i].nom)[j])) || (((resultat[i].nom)[j])=='-'));
}
gotoxy(1, 15);
do
{
ind_erreur=1;
printf("<Q>uitter, <E>ffacer les scores : ");
fflush(stdin);
scanf("%c", &chw);
if (chw!='q' && chw!='Q' && chw!='e' && chw!='E')
{
ind_erreur=f3();
gotoxy(1, 15);
delline();
gotoxy(1, 15);
}
}
while (ind_erreur==3);
if (chw=='e' || chw=='E')
{
do
{
x=wherex();
y=wherey();
ind_erreur=1;
printf("\nVoulez-vous vraiment effacer les scores? <O>ui, <N>on : ");
fflush(stdin);
scanf("%c", &chq);
if (chq=='n' || chq=='N')
f4();
else
if ((chq=='o' || chq=='O') && premier!=0)
{
raz("vague_sc.txt");
break;
}
else
{
ind_erreur=f3();
gotoxy(1, y+1);
delline();
gotoxy(x, y);
}
}
while (ind_erreur==3);
}
return(2);
}
int f5 (void) /* quitter */
{
int dip=1, x, y;
char cht;
x=wherex();
y=wherey();
do
{
printf("\nVoulez-vous vraiment quitter? <O>ui, <N>on : ");
fflush(stdin);
scanf("%c", &cht);
if (cht=='o' || cht=='O')
dip=5;
else
if (cht=='n' || cht=='N')
dip=1;
else
{
dip=f3();
gotoxy(1, y);
delline();
delline();
gotoxy(x, y);
}
}
while (dip==3);
return(dip);
}
void page_garde (char pgm[], int an)
{
char txt[60], txt0[2];
clrscr();
textcolor(blanc);
strcpy(txt, "***************************************************");
gotoxy(15, 8);
puts(txt);
strcpy(txt0, "*");
gotoxy(15, 9);
puts(txt0);
gotoxy(65, 9);
puts(txt0);
gotoxy(15, 10);
puts(txt0);
gotoxy((int)(41-(strlen(pgm))/2), 10);
puts(pgm);
gotoxy(65, 10);
puts(txt0);
gotoxy(15, 11);
puts(txt0);
gotoxy(65, 11);
puts(txt0);
gotoxy(15, 12);
puts(txt0);
gotoxy(65, 12);
puts(txt0);
strcpy(txt, "* COPYRIGHT ALEXANDRE ROGER");
gotoxy(15, 13);
puts(txt);
gotoxy(52, 13);
printf("%d", an);
gotoxy(65, 13);
puts(txt0);
gotoxy(15, 14);
puts(txt0);
gotoxy(65, 14);
puts(txt0);
gotoxy(15, 15);
puts(txt0);
gotoxy(65, 15);
puts(txt0);
gotoxy(15, 16);
puts(txt0);
textcolor(blanc+blink);
gotoxy(20, 16);
cprintf("< APPUYEZ SUR UNE TOUCHE POUR CONTINUER >");
textcolor(blanc);
gotoxy(65, 16);
puts(txt0);
gotoxy(15, 17);
puts(txt0);
gotoxy(65, 17);
puts(txt0);
strcpy(txt, "***************************************************");
gotoxy(15, 18);
puts(txt);
gotoxy(80, 25);
getch();
}
void continuation (void)
{
textcolor(blink+blanc);
cprintf("\n\n\r< APPUYEZ SUR UNE TOUCHE POUR CONTINUER >");
textcolor(blanc);
gotoxy(80, 25);
getch();
}
void duree (long tpa, long tpb)
{
long mn, sec;
sec=(tpb-tpa)%60;
mn=(tpb-tpa-sec)/60;
if (tpa==tpb)
cprintf("%ld seconde", sec);
else
if (mn==0)
cprintf("%ld secondes", sec);
else
if (mn==1 && sec==0)
cprintf("%ld minute", mn);
else
if (mn==1 && sec==1)
cprintf("%ld minute et %ld seconde", mn, sec);
else
if (mn==1 && sec>1)
cprintf("%ld minute et %ld secondes", mn, sec);
else
if (mn>1 && sec==0)
cprintf("%ld minutes", mn);
else
if (mn>1 && sec==1)
cprintf("%ld minutes et %ld seconde", mn, sec);
else
cprintf("%ld minutes et %ld secondes", mn, sec);
}
void ouverture (char fic[])
{
int i;
if ((fichier=fopen(fic, "r+"))!=NULL)
{
fread(&premier, 1, 1, fichier);
if (premier!=0)
{
for (i=1; i<=premier; i++)
{
fseek(fichier, 10+3*i, 0);
fflush(stdin);
fread(&(resultat[i].coup), 2, 1, fichier);
fseek(fichier, 50+5*i, 0);
fflush(stdin);
fread(&(resultat[i].temp), 4, 1, fichier);
fseek(fichier, 120+30*i, 0);
fflush(stdin);
fread(&(resultat[i].nom), 21, 1, fichier);
}
}
fclose(fichier);
}
else
raz (fic);
}
void fermeture (char fic[]) /* r‚‚criture dans le fichier */
{
int i;
fichier=fopen(fic, "w");
fseek(fichier, 0, 0);
fflush(stdin);
fwrite(&premier, sizeof(premier), 1, fichier);
if (premier!=0)
{
for (i=1; i<=premier; i++)
{
fseek(fichier, 10+3*i, 0);
fflush(stdin);
fwrite(&(resultat[i].coup), sizeof(resultat[i].coup), 1, fichier);
fseek(fichier, 50+5*i, 0);
fflush(stdin);
fwrite(&(resultat[i].temp), sizeof(resultat[i].temp), 1, fichier);
fseek(fichier, 120+30*i, 0);
fflush(stdin);
fwrite(&(resultat[i].nom), 1+strlen(resultat[i].nom), 1, fichier);
}
}
fclose(fichier);
}
void raz (char fic[])
{
premier=0;
fichier=fopen(fic, "w");
fseek(fichier, 0, 0);
fflush(stdin);
fwrite(&premier, sizeof(premier), 1, fichier);
fclose(fichier);
}
void tri (void)
{
int i=0, j;
while ((i<=premier) && (resultat[0].coup>=resultat[i].coup))
{
if (resultat[0].coup==resultat[i].coup)
if (resultat[0].temp<resultat[i].temp)
break;
i++;
if (premier==0)
break;
}
if (i<10)
{
for (j=0; j<=premier-i; j++)
{
resultat[premier+1-j].coup=resultat[premier-j].coup;
resultat[premier+1-j].temp=resultat[premier-j].temp;
strcpy(resultat[premier+1-j].nom, resultat[premier-j].nom);
}
}
if (i<11)
{
resultat[i].coup=resultat[0].coup;
resultat[i].temp=resultat[0].temp;
strcpy(resultat[i].nom, resultat[0].nom);
}
}
void genere_nb (int ta[max])
{
int i, alpha;
time_t temps;
for (i=0; i<max; i++)
ta[i]=i;
srand ((unsigned)time (&temps));
alpha=rand()%100;
srand ((unsigned)time (&temps));
for (i=0; i<1+rand()%alpha; i++)
deplace (ta, 1+rand()%9);
}
void affiche (int t0[max])
{
int i;
gotoxy(17, 3);
printf("positions ---> ");
for (i=1; i<max; i++)
printf("%d ", i);
gotoxy(17, 4);
printf("code secret : ");
for (i=0; i<max-1; i++)
printf("%d.", t0[i]);
printf("%d", t0[max-1]);
}
void deplace (int t1[max], int pos)
{
int tbis[2], i, j;
tbis[0]=t1[pos-1];
tbis[1]=t1[pos];
for (i=0; i<=pos-2; i++)
t1[pos-1-i]=t1[pos-2-i];
t1[0]=tbis[0];
for (j=0; j<=8-pos; j++)
t1[pos+j]=t1[pos+1+j];
t1[9]=tbis[1];
}
booleen comparaison (int t3[max])
{
int tprim[max], i;
for (i=0; i<max; i++)
tprim[i]=i;
i=0;
while (i<max)
{
if (t3[i]==tprim[i])
i++;
else
break;
}
if (i==max)
return(vrai);
else return(faux);
}
-------------------------------------------------------------------------------------
code du fichier vague.txt
/* ‚criture dans un fichier */
#include <errno.h>
#include <ctype.h>
#include <stdio.h>
#include <conio.h>
void main()
{
FILE *fichier;
char buf[3000]="";
strcpy(buf," REGLE DU JEU.\n\n\n");
strcat(buf,"Les chiffres du code secret, initialement dans l'ordre suivant 0123456789, ont\n‚t?brouilles. Il convient de reconstituer la combinaison en un minimum de\ntentatives.");
strcat(buf,"\nPour cela, on choisit une position entre 2 chiffres (par exemple, celle ‚tant\nsitue entre le quatriŠme et le cinquieme chiffre est la position 4), puis on\nd‚place le chiffre situ??gauche de la position choisie pour le placer en\npremiŠre position (extrˆme gauche); tandis que le chiffre situ??droite de la\nposition choisie est d‚plac?pour ˆtre positionnee en derniere position (extreme\ndroite).");
strcat(buf," On recommence jusqu'?reconstituer la sequence initiale: 0123456789.");
strcat(buf,"\nExemple:\nCombinaison brouillee: 3569102478.\nOn joue en position 4.\nLa serie devient: 9356024781.");
clrscr();
fichier=fopen("vague.txt", "w+");
fwrite(&buf, strlen(buf), 1, fichier);
fclose(fichier);
printf("Fin d'‚criture!... Appuyez sur une touche pour continuer.");
getch();
}
Conclusion
definition de type lecture et ecriture de fichiers manipulation de structures et de tableaux positionnement a l'ecran, ecriture en couleur manipulation de chaines realisation d'un chronometre utilisation des meilleurs scores
Historique
- 31 juillet 2004 11:56:53 :
- il manquait un fichier
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
RE : SAC A DOS RE : SAC A DOS par hadjkaddour
Cliquez pour lire la suite par hadjkaddour
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|