begin process at 2012 05 27 20:08:04
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Jeux

 > JEU DE CODE SECRET

JEU DE CODE SECRET


 Information sur la source

Note :
Aucune note
Catégorie :Jeux Niveau :Initié Date de création :31/07/2004 Date de mise à jour :31/07/2004 11:56:53 Vu :3 414

Auteur : pinderlot

Ecrire un message privé
Site perso
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 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&#130;&#130;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&#130;&#130;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

Source avec Zip Source avec une capture DEVINER 1 NOMBRE EN FENÊTRES FILLES
MASTERMIND EN LANGAGE C BASIQUE
CARRÉ MAGIQUE
RECHERCHE DES NOMBRES PARFAITS
CALCUL DE PI

 Sources de la même categorie

Source avec Zip Source avec une capture JEU DES CARTES par eapaceinfo
PROGRAMME DE JEU DE MPT par KerizGarmm
Source avec Zip Source avec une capture JEUX SERPENT par antho974
Source avec Zip Source avec une capture PENDU EN SDL par Damsou91
Source avec Zip STATE MACHINE MODIFICATION MATH BUCKHAM par billybones79

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

Photothèque

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,343 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales