begin process at 2012 05 27 15:31:00
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Jeux

 > DÉMINEUR POUR DÉBUTANT (BORLAND C++)

DÉMINEUR POUR DÉBUTANT (BORLAND C++)


 Information sur la source

Note :
6 / 10 - par 1 personne
6,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Jeux Niveau :Débutant Date de création :18/01/2002 Date de mise à jour :30/04/2002 13:04:36 Vu / téléchargé :9 986 / 224

Auteur : Thanatos

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

 Description

Il s'agit du jeu du démineur (sans aucun graphisme)

Source

  • #include <stdio.h>
  • #include <stdlib.h>
  • #include <conio.h>
  • #define L 11
  • #define C 11
  • #define M 10
  • int nb_mine=0;
  • struct type_case
  • {int val;
  • int visible;
  • int zero;
  • int mine;
  • int utile;};
  • void initialise_jeu(struct type_case tab[L][C])
  • {
  • int i,j;
  • for (i=0;i<L;i++)
  • for (j=0;j<C;j++)
  • { tab[i][j].visible=0;
  • tab[i][j].val=0;
  • tab[i][j].zero=0;
  • tab[i][j].mine=0;
  • tab[i][j].utile=0;}
  • }
  • void creation_jeu (int N,struct type_case tab[L][C])
  • {
  • int j; int i; int compteur=0;
  • randomize();
  • while ( compteur<N)
  • {
  • i=random(L-2);
  • j=random(C-2);
  • if (tab[i+1][j+1].val ==0)
  • {
  • tab[i+1][j+1].val=-1;
  • compteur++;
  • }
  • else ;
  • }
  • }
  • void rempli_case(struct type_case tab[L][C])
  • {
  • int i,j, compteur=0;
  • for (i=1;i<L-1;i++)
  • for (j=1;j<C-1;j++)
  • {
  • if (tab[i-1][j].val==-1) compteur++;
  • if (tab[i-1][j+1].val==-1) compteur++;
  • if (tab[i][j+1].val==-1) compteur++;
  • if (tab[i+1][j+1].val==-1) compteur++;
  • if (tab[i+1][j].val==-1) compteur++;
  • if (tab[i+1][j-1].val==-1) compteur++;
  • if (tab[i][j-1].val==-1) compteur++;
  • if (tab[i-1][j-1].val==-1) compteur++;
  • if (tab[i][j].val==0) tab[i][j].val=compteur;
  • compteur=0;
  • }
  • for (i=0;i<L;i++)
  • {tab[i][0].val=9;
  • tab[i][C-1].val=9;}
  • for (j=0;j<C;j++)
  • {tab[0][j].val=9;
  • tab[L-1][j].val=9;}
  • }
  • void affichage(struct type_case tab[L][C])
  • {
  • int i,j;
  • for (i=1;i<L-1;i++)
  • for (j=1;j<C-1;j++)
  • { gotoxy(3*i,j);
  • if (tab[i][j].visible==1)
  • { if ((tab[i][j].mine==0) && (tab[i][j].val!=-1)) {textcolor(11);cprintf("%d",tab[i][j].val);}
  • else {textcolor(10);cprintf("X");};
  • }
  • else printf("+");
  • }
  • printf("\n");
  • }
  • void affiche_zero(struct type_case tab[L][C],int xx,int yy)
  • {
  • tab[xx-1][yy].visible=1;
  • tab[xx-1][yy+1].visible=1;
  • tab[xx][yy+1].visible=1;
  • tab[xx+1][yy+1].visible=1;
  • tab[xx+1][yy].visible=1;
  • tab[xx+1][yy-1].visible=1;
  • tab[xx][yy-1].visible=1;
  • tab[xx-1][yy-1].visible=1;
  • tab[xx][yy].zero=1;
  • tab[xx][yy].visible=1;
  • if ((tab[xx-1][yy].val==0) && (tab[xx-1][yy].zero==0)) affiche_zero(tab,xx-1,yy);
  • if ((tab[xx-1][yy+1].val==0) && (tab[xx-1][yy+1].zero==0)) affiche_zero(tab,xx-1,yy+1);
  • if ((tab[xx][yy+1].val==0) && (tab[xx][yy+1].zero==0)) affiche_zero(tab,xx,yy+1);
  • if ((tab[xx+1][yy+1].val==0) && (tab[xx+1][yy+1].zero==0)) affiche_zero(tab,xx+1,yy+1);
  • if ((tab[xx+1][yy].val==0) && (tab[xx+1][yy].zero==0)) affiche_zero(tab,xx+1,yy);
  • if ((tab[xx+1][yy-1].val==0) && (tab[xx+1][yy-1].zero==0)) affiche_zero(tab,xx+1,yy-1);
  • if ((tab[xx][yy-1].val==0) && (tab[xx][yy-1].zero==0)) affiche_zero(tab,xx,yy-1);
  • if ((tab[xx-1][yy-1].val==0) && (tab[xx-1][yy-1].zero==0)) affiche_zero(tab,xx-1,yy-1);
  • }
  • void montre_ttes_mines(struct type_case tableau[L][C])
  • {
  • int i,j;
  • for (i=1;i<L-1;i++)
  • for (j=1;j<L-1;j++)
  • {if (tableau[i][j].val==-1)
  • {textcolor(4);gotoxy(3*i,j);cprintf("#");}
  • else;};
  • }
  • void verif_nb_mine( struct type_case tableau[L][C])
  • {
  • int a=0;
  • int i,j;
  • for (i=1;i<L-1;i++)
  • for (j=1;j<L-1;j++)
  • if ((tableau[i][j].visible==1) && (tableau[i][j].val!=-1))
  • {a++;}
  • else;
  • if (a==((L-2)*(C-2)-M))
  • { gotoxy(12,12); printf("GAGNE\n");exit(0);}
  • else;
  • }
  • void demande(struct type_case tab[L][C])
  • {
  • int x=0,y=0,choix=0,r;
  • printf("\n\t1 : Desamorcer une mine");
  • printf("\n\t2 : Localiser une mine");
  • printf("\nVotre choix :");
  • scanf("%d",&choix);
  • switch (choix) {
  • case 1:
  • {
  • printf("\n\nCoordonnees de la case à desamorcer(x,y):");
  • scanf("%d,%d",&y, &x);
  • if (tab[x][y].utile==0)
  • {tab[x][y].visible=1;
  • tab[x][y].utile=1;
  • tab[x][y].mine=0;
  • clrscr();
  • if (tab[x][y].val==0)
  • affiche_zero(tab,x,y);
  • else;
  • affichage(tab);
  • verif_nb_mine(tab);
  • if (tab[x][y].val!=-1)
  • {demande(tab);}
  • else
  • { montre_ttes_mines(tab); gotoxy(12,12);printf("Perdu !");};}
  • else { clrscr();
  • affichage(tab);
  • demande(tab);};
  • }
  • break;
  • case 2:{
  • printf("\n\nCoordonnees de la case à isoler(x,y):");
  • scanf("%d,%d",&y, &x);
  • if (tab[x][y].visible!=1)
  • {tab[x][y].visible=1;
  • tab[x][y].mine=1;
  • clrscr();
  • affichage(tab);
  • demande(tab);}
  • else {
  • clrscr();
  • affichage(tab);
  • demande(tab);};
  • };
  • break;
  • }
  • }
  • void main()
  • {
  • struct type_case jeu[L][C];
  • clrscr();
  • initialise_jeu(jeu);
  • creation_jeu(M,jeu);
  • rempli_case(jeu);
  • affichage(jeu);
  • demande(jeu);
  • }
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

#define L 11
#define C 11
#define M 10

int nb_mine=0;

struct type_case
{int val;
 int visible;
int zero;
int mine;
int utile;};


void initialise_jeu(struct type_case tab[L][C])
{
int i,j;
for (i=0;i<L;i++)
for (j=0;j<C;j++)
{	tab[i][j].visible=0;
	tab[i][j].val=0;
	tab[i][j].zero=0;
	tab[i][j].mine=0;
	tab[i][j].utile=0;}
}


void creation_jeu (int N,struct type_case tab[L][C])
{
int j; int i; int compteur=0;
randomize();
while ( compteur<N)
	{
	i=random(L-2);
	j=random(C-2);
	if (tab[i+1][j+1].val ==0)
		{
		tab[i+1][j+1].val=-1;
		compteur++;
		}
	else ;
	}
}


void rempli_case(struct type_case tab[L][C])
{
int i,j, compteur=0;
for (i=1;i<L-1;i++)
	for (j=1;j<C-1;j++)
	{	
	if (tab[i-1][j].val==-1) compteur++;
	if (tab[i-1][j+1].val==-1) compteur++;
	if (tab[i][j+1].val==-1) compteur++;
	if (tab[i+1][j+1].val==-1) compteur++;
	if (tab[i+1][j].val==-1) compteur++;
	if (tab[i+1][j-1].val==-1) compteur++;
	if (tab[i][j-1].val==-1) compteur++;
	if (tab[i-1][j-1].val==-1) compteur++;		
	if (tab[i][j].val==0) tab[i][j].val=compteur;
	compteur=0;
	}

for (i=0;i<L;i++)
	{tab[i][0].val=9;
	tab[i][C-1].val=9;}			
for (j=0;j<C;j++)
	{tab[0][j].val=9;
	tab[L-1][j].val=9;}
}


void affichage(struct type_case tab[L][C])
{
int i,j;	
for (i=1;i<L-1;i++)
for (j=1;j<C-1;j++)
	{ gotoxy(3*i,j); 
	if (tab[i][j].visible==1) 
		{ if ((tab[i][j].mine==0) && (tab[i][j].val!=-1)) {textcolor(11);cprintf("%d",tab[i][j].val);}
		  else {textcolor(10);cprintf("X");};
		}
	else printf("+");
	}
	   
printf("\n");
}


void affiche_zero(struct type_case tab[L][C],int xx,int yy)
{
tab[xx-1][yy].visible=1;
tab[xx-1][yy+1].visible=1;
tab[xx][yy+1].visible=1;
tab[xx+1][yy+1].visible=1;
tab[xx+1][yy].visible=1;
tab[xx+1][yy-1].visible=1;
tab[xx][yy-1].visible=1;
tab[xx-1][yy-1].visible=1;

tab[xx][yy].zero=1;
tab[xx][yy].visible=1;

if ((tab[xx-1][yy].val==0) && (tab[xx-1][yy].zero==0)) affiche_zero(tab,xx-1,yy);
if ((tab[xx-1][yy+1].val==0) && (tab[xx-1][yy+1].zero==0)) affiche_zero(tab,xx-1,yy+1);
if ((tab[xx][yy+1].val==0) && (tab[xx][yy+1].zero==0)) affiche_zero(tab,xx,yy+1);
if ((tab[xx+1][yy+1].val==0) && (tab[xx+1][yy+1].zero==0)) affiche_zero(tab,xx+1,yy+1);
if ((tab[xx+1][yy].val==0) && (tab[xx+1][yy].zero==0)) affiche_zero(tab,xx+1,yy);
if ((tab[xx+1][yy-1].val==0) && (tab[xx+1][yy-1].zero==0)) affiche_zero(tab,xx+1,yy-1);
if ((tab[xx][yy-1].val==0) && (tab[xx][yy-1].zero==0)) affiche_zero(tab,xx,yy-1);
if ((tab[xx-1][yy-1].val==0) && (tab[xx-1][yy-1].zero==0)) affiche_zero(tab,xx-1,yy-1);
}


void montre_ttes_mines(struct type_case tableau[L][C])
{
int i,j;
for (i=1;i<L-1;i++)
for (j=1;j<L-1;j++)
	{if (tableau[i][j].val==-1) 
		{textcolor(4);gotoxy(3*i,j);cprintf("#");}
	else;};
}


void verif_nb_mine( struct type_case tableau[L][C])
{
int a=0;
int i,j;
for (i=1;i<L-1;i++)
for (j=1;j<L-1;j++)
	if ((tableau[i][j].visible==1) && (tableau[i][j].val!=-1))
		{a++;}
	else;
	if (a==((L-2)*(C-2)-M))
		{ gotoxy(12,12); printf("GAGNE\n");exit(0);}
	else;
}


void demande(struct type_case tab[L][C])			
{
int x=0,y=0,choix=0,r;

printf("\n\t1 : Desamorcer une mine");
printf("\n\t2 : Localiser une mine");
printf("\nVotre choix :");
scanf("%d",&choix);
switch (choix) {

	case 1:
	{
	printf("\n\nCoordonnees de la case à desamorcer(x,y):");
	scanf("%d,%d",&y, &x);
	if (tab[x][y].utile==0)
		{tab[x][y].visible=1;
		tab[x][y].utile=1;
		tab[x][y].mine=0;
		clrscr();
		if (tab[x][y].val==0) 	
			affiche_zero(tab,x,y);
		else;
		affichage(tab);
		verif_nb_mine(tab);
		if (tab[x][y].val!=-1)
			 {demande(tab);}
		else 	
			{  montre_ttes_mines(tab);  gotoxy(12,12);printf("Perdu !");};}
	else {         clrscr();
		affichage(tab);
		demande(tab);};
	}
	break;

	case 2:{
	printf("\n\nCoordonnees de la case à isoler(x,y):");
	scanf("%d,%d",&y, &x);
	if (tab[x][y].visible!=1)
		{tab[x][y].visible=1;
		tab[x][y].mine=1;
		clrscr();
		affichage(tab);
		demande(tab);}
	else {
		clrscr();
		affichage(tab);
		demande(tab);};
	        };
	break;
	}
}


void main()
{
struct type_case jeu[L][C];
clrscr();
initialise_jeu(jeu);
creation_jeu(M,jeu);
rempli_case(jeu);
affichage(jeu);
demande(jeu);
}   



 Sources du même auteur

TROUVER L'INVERSE D'UN NOMBRE DANS Z/PZ
AFFICHE LES COORDONNÉES DE LA SOURIS(BORLAND C++5.5)

 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

Commentaire de Bk3k le 27/01/2002 07:50:27

Y a

Commentaire de Bk3k le 27/01/2002 07:54:18

Une variable déclarée qui n'est pas utilisée, des petites "fautes" de style, une indentation pas très claire par moment, des warnings à la compilation qu'on peut éliminer en 30 secondes si on en fait l'effort.

Bref, c'est bien, mais ce n'est pas fignolé.

Petit détail, quand tu ne mets pas de type à une fonction, elle est considérée comme "int" par défaut. Donc si tu ne mets rien, il te faut un return. Prend donc l'habitude de mettre un void quand tu veux que ta fonction ne retourne rien. C'est pas très grave parce que le compilateur ne bloque pas à la compilation, il donne juste un warning, mais bon, autant prendre les bonnes habitudes tout de suite.

Bon, je critique, mais je trouve quand même que c'est assez bien fait.

Commentaire de bouba le 27/01/2002 18:09:54

Un super jeux pour débuter, c'est cool!
Attention: 2 warnings à la compilation; il faut mettre un return 0; a la dernière ligne de la fonction main et un autre à la dernière ligne de la fonction initialise_jeu.
Sinon ça se compile bien.

Commentaire de Dax le 14/11/2002 13:34:50

merci je vais tout de suite analyser tout ca merci man :)

Commentaire de eryckb le 22/12/2002 23:40:25

j'aurai besoin d'aide car je debute en c++ et ton programme a des erreurs encore, peu tu me les corriger?

erreurs :
G:DESSc++Cpp1.cpp(39) : error C2065: 'random' : undeclared identifier
G:DESSc++Cpp1.cpp(85) : error C2065: 'textcolor' : undeclared identifier
G:DESSc++Cpp1.cpp(164) : error C2065: 'clrscr' : undeclared identifier

thx a++

Commentaire de shak le 01/04/2003 20:32:27

je debute en C. Peux tu m'expliquer ton algorithme?
que signifie le "-1" dans les commandes de la fonction void rempli_case:

int i,j, compteur=0;
for (i=1;i&lt;L-1;i++)
    for (j=1;j&lt;C-1;j++)
    {  
    if (tab[i-1][j].val==-1) compteur++;
    if (tab[i-1][j+1].val==-1) compteur++;
    if (tab[i][j+1].val==-1) compteur++;
    if (tab[i+1][j+1].val==-1) compteur++;
    if (tab[i+1][j].val==-1) compteur++;
    if (tab[i+1][j-1].val==-1) compteur++;
    if (tab[i][j-1].val==-1) compteur++;
    if (tab[i-1][j-1].val==-1) compteur++;      
    if (tab[i][j].val==0) tab[i][j].val=compteur;
    compteur=0;
    }

Pkoi utilise tu un goto et un Cprintf ds la ligne de commande suivante:

textcolor(4);gotoxy(3*i,j);cprintf("#");}

Merci

Commentaire de NGONGOETABA le 15/04/2004 17:11:18

je debute en C. Peux tu m'expliquer ton algorithme?
que signifie le "-1" dans les commandes de la fonction void rempli_case:

int i,j, compteur=0;
for (i=1;i&lt;L-1;i++)
    for (j=1;j&lt;C-1;j++)
    {  
    if (tab[i-1][j].val==-1) compteur++;
    if (tab[i-1][j+1].val==-1) compteur++;
    if (tab[i][j+1].val==-1) compteur++;
    if (tab[i+1][j+1].val==-1) compteur++;
    if (tab[i+1][j].val==-1) compteur++;
    if (tab[i+1][j-1].val==-1) compteur++;
    if (tab[i][j-1].val==-1) compteur++;
    if (tab[i-1][j-1].val==-1) compteur++;      
    if (tab[i][j].val==0) tab[i][j].val=compteur;
    compteur=0;
    }

Pkoi utilise tu un goto et un Cprintf ds la ligne de commande suivante:

textcolor(4);gotoxy(3*i,j);cprintf("#");}

Merci

Commentaire de aom333 le 07/01/2010 22:23:12

bravo frero good work!

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

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 : 1,045 sec (3)

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