MAD_DIM | Bonjour,
J'ai programmé un démineur mais lorsque je vais dans le mode "Personnaliser" que je rentre par exemple 5 lignes, 5 colonnes pour les dimensions et ensuite 25 mines le programme plante mais je ne comprends pas d'ou cela peut provenir ?
Ainsi si quelqu'un pouvait m'aider pour cela ?
Merci
Code :
- #include<stdio.h>
- #include<stdlib.h>
- #include<windows.h>
- #include<time.h>
- typedef int GRILLE[50][50];
- typedef char GRILLEJEU[50][50];
- void Affiche(GRILLEJEU &, int, int);
- void Init(GRILLE &, GRILLEJEU &, int , int);
- void Mine(GRILLE &, int , int, int);
- void Position(GRILLE &, int, int);
- char Jeu(GRILLEJEU &, GRILLE &, int, int);
- char Convert(GRILLE &, int, int);
- void main()
- {
- GRILLE grille;
- GRILLEJEU grillejeu;
- bool test;
- int testint;
- int nbl, nbc, nbmine;
- int choix, choix2;
- char choix3;
- do
- {
- do
- {
- test = true;
- system("cls" );
- printf("\n LE DEMINEUR\n" );
- printf(" -----------\n\n" );
- printf(" **** MENU ****\n\n\n" );
- printf(" 1.Jouer\n" );
- printf(" 2.Personnaliser\n\n" );
- fflush(stdin);
- printf(" Choix : " );
- testint = scanf("%d", &choix);
- if(choix != 1 && choix != 2)
- {
- printf("\n CHOIX INVALIDE\n" );
- test = false;
- Sleep(2000);
- }
- }while(testint == 0 || test == false);
- if(choix == 1)
- {
- do
- {
- test = true;
- system("cls" );
- printf("\n LE DEMINEUR\n" );
- printf(" -----------\n\n" );
- printf("\n **** NIVEAU ****\n\n" );
- printf(" 1.Debutant\n" );
- printf(" 2.Intermediaire\n" );
- printf(" 3.Expert\n\n" );
- fflush(stdin);
- printf(" Choix : " );
- testint = scanf("%d", &choix2);
- if(choix2 == 1)
- {
- nbl = 8;
- nbc = 8;
- nbmine = 10;
- }
- else
- {
- if(choix2 == 2)
- {
- nbl = 16;
- nbc = 16;
- nbmine = 40;
- }
- else
- {
- if(choix2 == 3)
- {
- nbl = 16;
- nbc = 25;
- nbmine = 99;
- }
- else
- {
- printf("\n CHOIX INVALIDE\n" );
- test = false;
- Sleep(1000);
- }
- }
- }
- }while(testint == 0 || test == false);
- }
- else
- {
- do
- {
- test = true;
- system("cls" );
- printf("\n\n CHOISISSEZ LES DIMENSIONS DE LA GRILLE : \n" );
- printf(" ---------------------------------------\n\n" );
- printf(" * Entrez le nombre de lignes : " );
- fflush(stdin);
- testint = scanf("%d", &nbl);
- if(testint == 0 || nbl > 16 || nbl < 2)
- {
- printf("\n CHOIX INVALIDE\n" );
- test = false;
- Sleep(1000);
- }
- }while(testint == 0 || test == false);
- printf("\n" );
- do
- {
- test = true;
- printf(" * Entrez le nombre de colonnes : " );
- fflush(stdin);
- scanf("%d", &nbc);
- if(testint == 0 || nbc > 25 || nbc < 2)
- {
- printf("\n CHOIX INVALIDE\n" );
- test = false;
- Sleep(1000);
- }
- }while(testint == 0 || test == false);
- do
- {
- test = true;
- system("cls" );
- printf("\n\n CHOISISSEZ LE NOMBRE DE MINES : \n" );
- printf(" ------------------------------\n\n" );
- printf(" * Entrez le nombre de mines : " );
- fflush(stdin);
- testint = scanf("%d", &nbmine);
- if(nbmine > (nbl*nbc))
- {
- printf("\n POUR CETTE PARTIE LE NOMBRE DE MINE DOIT ETRE INFERIEUR A %d\n", (nbl*nbc));
- Sleep(2000);
- test = false;
- }
- else
- {
- if(testint == 0)
- {
- printf("\n CHOIX INVALIDE\n" );
- Sleep(2000);
- }
- }
- }while(testint == 0 || test == false);
- }
- Init(grille, grillejeu, nbl, nbc);
- Mine(grille, nbl, nbc, nbmine);
- Position(grille, nbl, nbc);
- choix3 = Jeu(grillejeu, grille, nbl, nbc);
- }while(choix3 == 'o');
- system("cls" );
- printf("\n\n DIMGAMES ENTERTAINEMENT VOUS A PRESENTER \n\n" );
- printf(" LE DEMINEUR\n\n" );
- Sleep(3000);
- system("cls" );
- printf("\n\n MERCI D AVOIR JOUER\n\n" );
- printf(" AU REVOIR\n\n" );
- }
- void Init(GRILLE &grille, GRILLEJEU &grillejeu, int nbl, int nbc)
- {
- int i, j;
-
- for(i=1;i<=nbl;i++)
- {
- for(j=1;j<=nbc;j++)
- {
- grille[i][j] = 0;
- }
- }
- for(i=1;i<=nbl;i++)
- {
- for(j=1;j<=nbc;j++)
- {
- grillejeu[i][j] = '*';
- }
- }
- }
- void Mine(GRILLE &grille, int nbl, int nbc, int nbmine)
- {
- int i, j;
- srand( (unsigned)time( NULL ) );
- while(nbmine > 0)
- {
- i = rand()%nbl;
- j = rand()%nbc;
- if (grille[i][j] == 0 && i > 0 && j > 0)
- {
- grille[i][j] = 9;
- nbmine--;
- }
- }
- }
- void Position(GRILLE &grille, int nbl, int nbc)
- {
- int i, j, k, l;
- int comptmine; /* Compteur de mine */
-
- for(i=1;i<=nbl;i++)
- {
- for(j=1;j<=nbc;j++)
- {
- if(grille[i][j]==0)
- {
- comptmine = 0; /* Initialise le compteur de mine */
- /* Scanne les cases entourant la mine */
- for (k=i-1;k<i+2;k++)
- {
- for (l=j-1; l<j+2;l++)
- {
- if(grille[k][l]== 9)
- {
- /* Incrémente le compteur de mine */
- comptmine = comptmine+1;
- }
- }
- /* La case recoit la valeur du compteur de mine */
- grille[i][j] = comptmine;
- }
- }
- }
- }
- }
- char Jeu(GRILLEJEU &grillejeu, GRILLE &grille, int nbl, int nbc)
- {
- bool explose;
- int i, j;
- char choix3;
- system("cls" );
- do
- {
- printf("\n LE DEMINEUR\n" );
- printf(" -----------\n\n" );
- Affiche(grillejeu, nbl, nbc);
- printf("\n * Entrez la ligne : " );
- fflush(stdin);
- scanf("%d", &i);
- printf("\n * Entrez la colonne : " );
- fflush(stdin);
- scanf("%d", &j);
- if(grille[i][j] == 0)
- {
- grillejeu[i][j] = '.';
- }
- else
- {
- if(grille[i][j] != 9)
- {
- grille[i][j] = Convert(grille, i, j);
- grillejeu[i][j] = grille[i][j];
- }
- else
- {
- grillejeu[i][j] = 'B';
- explose = true;
- system("cls" );
- printf("\n LE DEMINEUR\n" );
- printf(" -----------\n\n" );
- Affiche(grillejeu, nbl, nbc);
- Sleep(2000);
- }
- }
- system("cls" );
- }while(explose != true);
- do
- {
- system("cls" );
- if(explose == true)
- {
- printf("\n\n\n VOUS AVEZ PERDU !!!!\n\n" );
- }
- else
- {
- printf("\n\n\n VOUS AVEZ GAGNE !!!!\n\n" );
- }
- printf("Voulez - vous recommencer une partie ?(o/n) : " );
- fflush(stdin);
- scanf("%c", &choix3);
- if(choix3 != 'o' && choix3 != 'n')
- {
- printf("\n CHOIX INVALIDE\n" );
- Sleep(2000);
- }
- }while(choix3 != 'o' && choix3 != 'n');
- return(choix3);
- }
- char Convert(GRILLE &grille, int i, int j)
- {
- switch(grille[i][j])
- {
- case 0 :
- return(48);
- break;
- case 1 :
- return(49);
- break;
- case 2 :
- return(50);
- break;
- case 3 :
- return(51);
- break;
- case 4 :
- return(52);
- break;
- case 5 :
- return(53);
- break;
- case 6 :
- return(54);
- break;
- case 7 :
- return(55);
- break;
- case 8 :
- return(56);
- break;
- case 9 :
- return(57);
- break;
- default :
- return (-1);
- }
- }
- void Affiche(GRILLEJEU &grillejeu, int nbl, int nbc)
- {
- int i, j;
- if(nbl <= 9 && nbc <= 9)
- {
- printf(" %d ", 1);
- for(j=2;j<=nbc;j++)
- {
- printf("%d ", j);
- }
- printf("\n\n" );
- for(i=1;i<=nbl;i++)
- {
- printf("%d ", i);
- for(j=1;j<=nbc;j++)
- {
- printf("%c ", grillejeu[i][j]);
- }
- printf("\n" );
- }
- }
- else
- {
- printf(" %d ", 1);
- for(j=2;j<=9;j++)
- {
- printf("%d ", j);
- }
- for(j=10;j<=nbc;j++)
- {
- printf("%d ", j);
- }
- printf("\n\n" );
- for(i=1;i<=9;i++)
- {
- printf("%d ", i);
- for(j=1;j<=nbc;j++)
- {
- printf("%c ", grillejeu[i][j]);
- }
- printf("\n" );
- }
- for(i=10;i<=nbl;i++)
- {
- printf("%d ", i);
- for(j=1;j<=nbc;j++)
- {
- printf("%c ", grillejeu[i][j]);
- }
- printf("\n" );
- }
- }
- }
|
|