Programme Mastermind ??
Fermé
ribery_7_91
Messages postés
233
Date d'inscription
jeudi 22 novembre 2007
Statut
Membre
Dernière intervention
4 septembre 2010
-
6 janv. 2008 à 14:56
ribery_7_91 Messages postés 233 Date d'inscription jeudi 22 novembre 2007 Statut Membre Dernière intervention 4 septembre 2010 - 7 janv. 2008 à 16:13
ribery_7_91 Messages postés 233 Date d'inscription jeudi 22 novembre 2007 Statut Membre Dernière intervention 4 septembre 2010 - 7 janv. 2008 à 16:13
A voir également:
- Programme Mastermind ??
- Ce programme est écrit en python. il construit un mot secret dans une variable mais il ne l'affiche pas. modifiez-le pour qu'il affiche le mot secret. exécutez-le. quel est ce mot secret ? ✓ - Forum Python
- Technique mastermind ✓ - Forum Loisirs / Divertissements
- Frequence programme national ✓ - Forum Messagerie
- Programme demarrage windows 10 - Guide
- Programme bonjour ✓ - Forum Windows
6 réponses
ribery_7_91
Messages postés
233
Date d'inscription
jeudi 22 novembre 2007
Statut
Membre
Dernière intervention
4 septembre 2010
16
6 janv. 2008 à 16:15
6 janv. 2008 à 16:15
personne ??
s'il vous plait
s'il vous plait
Nico#
Messages postés
323
Date d'inscription
vendredi 4 janvier 2008
Statut
Membre
Dernière intervention
28 août 2013
102
6 janv. 2008 à 16:17
6 janv. 2008 à 16:17
Salut, Tu bloque sur quoi exactement
ribery_7_91
Messages postés
233
Date d'inscription
jeudi 22 novembre 2007
Statut
Membre
Dernière intervention
4 septembre 2010
16
6 janv. 2008 à 17:04
6 janv. 2008 à 17:04
ba justement je ne sais pas
je veux juste faire un mastermind avec ce programme mais sa ne marche aps alors je voulais savoir ce qui n'allait pas
merci
je veux juste faire un mastermind avec ce programme mais sa ne marche aps alors je voulais savoir ce qui n'allait pas
merci
Nico#
Messages postés
323
Date d'inscription
vendredi 4 janvier 2008
Statut
Membre
Dernière intervention
28 août 2013
102
6 janv. 2008 à 18:25
6 janv. 2008 à 18:25
Voila un exemple complet
tu mets sa dans un fichier Fonction.h
#define DROITE 77
#define BAS 80
enum CURSOR
{
NORMALCURSOR = 0,
NOCURSOR = 100,
SOLIDCURSOR = 20,
};
enum COLORS
{
BLACK = 0,
BLUE = FOREGROUND_BLUE,
GREEN = FOREGROUND_GREEN,
CYAN = FOREGROUND_GREEN | FOREGROUND_BLUE,
RED = FOREGROUND_RED,
MAGENTA = FOREGROUND_RED | FOREGROUND_BLUE,
BROWN = FOREGROUND_RED | FOREGROUND_GREEN,
LIGHTGRAY = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
DARKGRAY = FOREGROUND_INTENSITY,
LIGHTBLUE = FOREGROUND_BLUE | FOREGROUND_INTENSITY,
LIGHTGREEN = FOREGROUND_GREEN | FOREGROUND_INTENSITY,
LIGHTCYAN = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
LIGHTRED = FOREGROUND_RED | FOREGROUND_INTENSITY,
LIGHTMAGENTA = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
YELLOW = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY,
WHITE = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
};
typedef unsigned char U8;
void gotoxy( U8 x, U8 y );
void SetCursorType( U8 cur );
void textcolor( U8 text, U8 background );
void gotoxy(U8 x, U8 y)
{
COORD c;
c.X = x - 1;
c.Y = y - 1;
SetConsoleCursorPosition (STDOUT, c);
}
void SetCursorType( U8 cur )
{
BOOL visible = cur != NOCURSOR;
CONSOLE_CURSOR_INFO CursorInfo = { cur, visible };
SetConsoleCursorInfo (STDOUT, &CursorInfo);
}
void textcolor( U8 text, U8 background )
{
if (text > 15)
text = 7;
if (background >15)
background = 0;
SetConsoleTextAttribute (STDOUT, 16 * background + text);
}
puis sa dans un fichier Mastermind.c
#include "Fonction.h"
#include "Mastermind.h"
int main()
{
initialisation();
menu();
do {
switch(action)
{
case MENU : menu();
break;
case AIDE : aide();
break;
case PARTIE : reinitialisation();
demarrer_une_partie();
demande_rejouer();
break;
}
}while(rejouer == OUI || partie != DEMARREE);
}
void initialisation (void)
{
srand(time(NULL));
SetCursorType(NOCURSOR);
}
void menu (void)
{
U8 ligne = 8, touche;
system ("CLS");
gotoxy(21,3); printf ("BIENVENUE DANS LE JEU DU MASTERMIND");
gotoxy(27, 6); printf ("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",201,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,187);
gotoxy(27, 7); printf ("%c %c",186,186);
gotoxy(27, 8); printf ("%c D%cmarrer une partie %c",186,130,186);
gotoxy(27, 9); printf ("%c %c",186,186);
gotoxy(27,10); printf ("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,188);
gotoxy(27,13); printf ("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",201,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,187);
gotoxy(27,14); printf ("%c %c",186,186);
gotoxy(27,15); printf ("%c Aide %c",186,186);
gotoxy(27,16); printf ("%c %c",186,186);
gotoxy(27,17); printf ("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,188);
gotoxy(27,20); printf ("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",201,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,187);
gotoxy(27,21); printf ("%c %c",186,186);
gotoxy(27,22); printf ("%c Quitter le jeu %c",186,186);
gotoxy(27,23); printf ("%c %c",186,186);
gotoxy(27,24); printf ("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,188);
do {
gotoxy(22,ligne); printf ("==%c",62);
touche = getch();
gotoxy(22,ligne); printf (" ");
if (touche == HAUT)
{
if (ligne != 8) ligne-= 7;
else ligne = 22;
}
if (touche == BAS)
{
if (ligne != 22) ligne+= 7;
else ligne = 8;
}
}while (touche != ENTREE);
switch (ligne)
{
case 8 : action = PARTIE;
break;
case 15 : action = AIDE;
break;
case 22 : exit(0);
break;
}
}
void aide (void)
{
system("CLS");
printf("4 numeros sont tires au hasard et vous devez les retrouver\n\n");
printf("Si un numero que vous avez propose est correct, un I apparaitra en dessous\n\n");
printf("Si un numero que vous avez propose est parmi les quatres tires mais pas a la bonne place, un");
textcolor(LIGHTRED,BLACK); printf(" I "); textcolor(LIGHTGRAY,BLACK); printf("apparaitra en dessous.");
getch();
action = MENU;
}
void reinitialisation (void)
{
U8 i;
for (i=0;i<4;i++)
nb_choisi[i] = rand() % 10;
nb_proposition = 0;
combi_trouve = 0;
}
void demarrer_une_partie (void)
{
partie = DEMARREE;
affichage_depart();
do {
saisie_des_numeros();
test_des_numeros();
affichage();
}while(combi_trouve != TROUVE && nb_proposition < NB_PROPOSITION_MAX);
}
void affichage_depart (void)
{
system ("CLS");
printf ("Trouver les 4 bons num%cros : X X X X\n\t\t\t\t",130);
}
void saisie_des_numeros (void)
{
U8 i;
for (i=0;i<4;i++)
{
do {
nb_propose[i] = getch();
}while(nb_propose[i] < '0' || nb_propose[i] > '9');
nb_propose[i]&=0x0F;
printf ("%d ",nb_propose[i]);
}
nb_proposition++;
}
void test_des_numeros (void)
{
U8 i;
for (i=0;i<4;i++)
{
if (nb_propose[i] == nb_choisi[i])
nb_valide[i] = BP;
else
{
nb_valide[i] = FF;
if (i == 0)
{
if (nb_propose[i] == nb_choisi[1] || nb_propose[i] == nb_choisi[2] || nb_propose[i] == nb_choisi[3])
nb_valide[i] = MP;
}
if (i == 1)
{
if (nb_propose[i] == nb_choisi[0] || nb_propose[i] == nb_choisi[2] || nb_propose[i] == nb_choisi[3])
nb_valide[i] = MP;
}
if (i == 2)
{
if (nb_propose[i] == nb_choisi[0] || nb_propose[i] == nb_choisi[1] || nb_propose[i] == nb_choisi[3])
nb_valide[i] = MP;
}
if (i == 3)
{
if (nb_propose[i] == nb_choisi[0] || nb_propose[i] == nb_choisi[1] || nb_propose[i] == nb_choisi[2])
nb_valide[i] = MP;
}
}
}
if (nb_valide[0] == BP && nb_valide[1] == BP && nb_valide[2] == BP && nb_valide[3] == BP)
combi_trouve = TROUVE;
}
void affichage (void)
{
U8 i;
printf ("\n\t\t\t\t");
for (i=0;i<4;i++)
{
if (nb_valide[i] == BP) { printf ("I "); }
if (nb_valide[i] == FF) { printf (" "); }
if (nb_valide[i] == MP) { textcolor(LIGHTRED,BLACK); printf ("I "); }
textcolor(LIGHTGRAY,BLACK);
}
if (combi_trouve == TROUVE)
{
gotoxy(1,22);
printf ("Bravo, vous avez trouv%c la combinaison.",130);
}
else
{
if (nb_proposition == NB_PROPOSITION_MAX)
{
gotoxy(1,22);
printf ("Dommage. Vous n'avez pas trouv%c la combinaison qui %ctait : %d %d %d %d",130,130,nb_choisi[0],nb_choisi[1],nb_choisi[2],nb_choisi[3]);
}
else
printf ("\n\n\t\t\t\tX X X X\n\t\t\t\t");
}
}
void demande_rejouer (void)
{
U8 touche;
printf ("\n\nVoulez-vous rejouer : ");
do {
touche = getch();
}while(touche != 'o' && touche != 'O' && touche != 'n' && touche != 'N');
if (touche == 'o' || touche == 'O')
rejouer = OUI;
else
rejouer = NON;
}
puis sa dans Mastermind.h
/*Sert pour connaître l'action en cours*/
#define MENU 0
#define AIDE 1
#define PARTIE 2
/*Sert pour savoir si la partie est démarrée*/
#define DEMARREE 3
/*Sert pour savoir si les chiffres sont à la bonne place*/
#define BP 0 // bonne place
#define MP 1 // mauvaise place
#define FF 2 // nombre faux
/*Sert pour savoir si la combinaison à été trouvée*/
#define TROUVE 1
/*Sert pour savoir si le nombre de proposition est inférieur à 5*/
#define NB_PROPOSITION_MAX 5
/*Sert pour savoir si le joueur veut rejouer*/
#define OUI 0
#define NON 1
U8 action, partie, rejouer;
U8 nb_choisi[4], nb_propose[4], nb_valide[4];
U8 nb_proposition, combi_trouve;
void initialisation (void);
void menu (void);
void aide (void);
void reinitialisation (void);
void demarrer_une_partie (void);
void affichage_depart (void);
void saisie_des_numeros (void);
void test_des_numeros (void);
void affichage (void);
void demande_rejouer (void);
tu mets sa dans un fichier Fonction.h
#define DROITE 77
#define BAS 80
enum CURSOR
{
NORMALCURSOR = 0,
NOCURSOR = 100,
SOLIDCURSOR = 20,
};
enum COLORS
{
BLACK = 0,
BLUE = FOREGROUND_BLUE,
GREEN = FOREGROUND_GREEN,
CYAN = FOREGROUND_GREEN | FOREGROUND_BLUE,
RED = FOREGROUND_RED,
MAGENTA = FOREGROUND_RED | FOREGROUND_BLUE,
BROWN = FOREGROUND_RED | FOREGROUND_GREEN,
LIGHTGRAY = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
DARKGRAY = FOREGROUND_INTENSITY,
LIGHTBLUE = FOREGROUND_BLUE | FOREGROUND_INTENSITY,
LIGHTGREEN = FOREGROUND_GREEN | FOREGROUND_INTENSITY,
LIGHTCYAN = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
LIGHTRED = FOREGROUND_RED | FOREGROUND_INTENSITY,
LIGHTMAGENTA = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
YELLOW = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY,
WHITE = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
};
typedef unsigned char U8;
void gotoxy( U8 x, U8 y );
void SetCursorType( U8 cur );
void textcolor( U8 text, U8 background );
void gotoxy(U8 x, U8 y)
{
COORD c;
c.X = x - 1;
c.Y = y - 1;
SetConsoleCursorPosition (STDOUT, c);
}
void SetCursorType( U8 cur )
{
BOOL visible = cur != NOCURSOR;
CONSOLE_CURSOR_INFO CursorInfo = { cur, visible };
SetConsoleCursorInfo (STDOUT, &CursorInfo);
}
void textcolor( U8 text, U8 background )
{
if (text > 15)
text = 7;
if (background >15)
background = 0;
SetConsoleTextAttribute (STDOUT, 16 * background + text);
}
puis sa dans un fichier Mastermind.c
#include "Fonction.h"
#include "Mastermind.h"
int main()
{
initialisation();
menu();
do {
switch(action)
{
case MENU : menu();
break;
case AIDE : aide();
break;
case PARTIE : reinitialisation();
demarrer_une_partie();
demande_rejouer();
break;
}
}while(rejouer == OUI || partie != DEMARREE);
}
void initialisation (void)
{
srand(time(NULL));
SetCursorType(NOCURSOR);
}
void menu (void)
{
U8 ligne = 8, touche;
system ("CLS");
gotoxy(21,3); printf ("BIENVENUE DANS LE JEU DU MASTERMIND");
gotoxy(27, 6); printf ("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",201,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,187);
gotoxy(27, 7); printf ("%c %c",186,186);
gotoxy(27, 8); printf ("%c D%cmarrer une partie %c",186,130,186);
gotoxy(27, 9); printf ("%c %c",186,186);
gotoxy(27,10); printf ("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,188);
gotoxy(27,13); printf ("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",201,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,187);
gotoxy(27,14); printf ("%c %c",186,186);
gotoxy(27,15); printf ("%c Aide %c",186,186);
gotoxy(27,16); printf ("%c %c",186,186);
gotoxy(27,17); printf ("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,188);
gotoxy(27,20); printf ("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",201,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,187);
gotoxy(27,21); printf ("%c %c",186,186);
gotoxy(27,22); printf ("%c Quitter le jeu %c",186,186);
gotoxy(27,23); printf ("%c %c",186,186);
gotoxy(27,24); printf ("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,188);
do {
gotoxy(22,ligne); printf ("==%c",62);
touche = getch();
gotoxy(22,ligne); printf (" ");
if (touche == HAUT)
{
if (ligne != 8) ligne-= 7;
else ligne = 22;
}
if (touche == BAS)
{
if (ligne != 22) ligne+= 7;
else ligne = 8;
}
}while (touche != ENTREE);
switch (ligne)
{
case 8 : action = PARTIE;
break;
case 15 : action = AIDE;
break;
case 22 : exit(0);
break;
}
}
void aide (void)
{
system("CLS");
printf("4 numeros sont tires au hasard et vous devez les retrouver\n\n");
printf("Si un numero que vous avez propose est correct, un I apparaitra en dessous\n\n");
printf("Si un numero que vous avez propose est parmi les quatres tires mais pas a la bonne place, un");
textcolor(LIGHTRED,BLACK); printf(" I "); textcolor(LIGHTGRAY,BLACK); printf("apparaitra en dessous.");
getch();
action = MENU;
}
void reinitialisation (void)
{
U8 i;
for (i=0;i<4;i++)
nb_choisi[i] = rand() % 10;
nb_proposition = 0;
combi_trouve = 0;
}
void demarrer_une_partie (void)
{
partie = DEMARREE;
affichage_depart();
do {
saisie_des_numeros();
test_des_numeros();
affichage();
}while(combi_trouve != TROUVE && nb_proposition < NB_PROPOSITION_MAX);
}
void affichage_depart (void)
{
system ("CLS");
printf ("Trouver les 4 bons num%cros : X X X X\n\t\t\t\t",130);
}
void saisie_des_numeros (void)
{
U8 i;
for (i=0;i<4;i++)
{
do {
nb_propose[i] = getch();
}while(nb_propose[i] < '0' || nb_propose[i] > '9');
nb_propose[i]&=0x0F;
printf ("%d ",nb_propose[i]);
}
nb_proposition++;
}
void test_des_numeros (void)
{
U8 i;
for (i=0;i<4;i++)
{
if (nb_propose[i] == nb_choisi[i])
nb_valide[i] = BP;
else
{
nb_valide[i] = FF;
if (i == 0)
{
if (nb_propose[i] == nb_choisi[1] || nb_propose[i] == nb_choisi[2] || nb_propose[i] == nb_choisi[3])
nb_valide[i] = MP;
}
if (i == 1)
{
if (nb_propose[i] == nb_choisi[0] || nb_propose[i] == nb_choisi[2] || nb_propose[i] == nb_choisi[3])
nb_valide[i] = MP;
}
if (i == 2)
{
if (nb_propose[i] == nb_choisi[0] || nb_propose[i] == nb_choisi[1] || nb_propose[i] == nb_choisi[3])
nb_valide[i] = MP;
}
if (i == 3)
{
if (nb_propose[i] == nb_choisi[0] || nb_propose[i] == nb_choisi[1] || nb_propose[i] == nb_choisi[2])
nb_valide[i] = MP;
}
}
}
if (nb_valide[0] == BP && nb_valide[1] == BP && nb_valide[2] == BP && nb_valide[3] == BP)
combi_trouve = TROUVE;
}
void affichage (void)
{
U8 i;
printf ("\n\t\t\t\t");
for (i=0;i<4;i++)
{
if (nb_valide[i] == BP) { printf ("I "); }
if (nb_valide[i] == FF) { printf (" "); }
if (nb_valide[i] == MP) { textcolor(LIGHTRED,BLACK); printf ("I "); }
textcolor(LIGHTGRAY,BLACK);
}
if (combi_trouve == TROUVE)
{
gotoxy(1,22);
printf ("Bravo, vous avez trouv%c la combinaison.",130);
}
else
{
if (nb_proposition == NB_PROPOSITION_MAX)
{
gotoxy(1,22);
printf ("Dommage. Vous n'avez pas trouv%c la combinaison qui %ctait : %d %d %d %d",130,130,nb_choisi[0],nb_choisi[1],nb_choisi[2],nb_choisi[3]);
}
else
printf ("\n\n\t\t\t\tX X X X\n\t\t\t\t");
}
}
void demande_rejouer (void)
{
U8 touche;
printf ("\n\nVoulez-vous rejouer : ");
do {
touche = getch();
}while(touche != 'o' && touche != 'O' && touche != 'n' && touche != 'N');
if (touche == 'o' || touche == 'O')
rejouer = OUI;
else
rejouer = NON;
}
puis sa dans Mastermind.h
/*Sert pour connaître l'action en cours*/
#define MENU 0
#define AIDE 1
#define PARTIE 2
/*Sert pour savoir si la partie est démarrée*/
#define DEMARREE 3
/*Sert pour savoir si les chiffres sont à la bonne place*/
#define BP 0 // bonne place
#define MP 1 // mauvaise place
#define FF 2 // nombre faux
/*Sert pour savoir si la combinaison à été trouvée*/
#define TROUVE 1
/*Sert pour savoir si le nombre de proposition est inférieur à 5*/
#define NB_PROPOSITION_MAX 5
/*Sert pour savoir si le joueur veut rejouer*/
#define OUI 0
#define NON 1
U8 action, partie, rejouer;
U8 nb_choisi[4], nb_propose[4], nb_valide[4];
U8 nb_proposition, combi_trouve;
void initialisation (void);
void menu (void);
void aide (void);
void reinitialisation (void);
void demarrer_une_partie (void);
void affichage_depart (void);
void saisie_des_numeros (void);
void test_des_numeros (void);
void affichage (void);
void demande_rejouer (void);
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
mype
Messages postés
2435
Date d'inscription
jeudi 1 novembre 2007
Statut
Membre
Dernière intervention
16 août 2010
435
6 janv. 2008 à 18:56
6 janv. 2008 à 18:56
va voir ici ça pourrait t'aider...
ribery_7_91
Messages postés
233
Date d'inscription
jeudi 22 novembre 2007
Statut
Membre
Dernière intervention
4 septembre 2010
16
7 janv. 2008 à 16:13
7 janv. 2008 à 16:13
alors voila plutot que d'utiliser celui que je vous ai donné je vous en donne un nouveau qui consiste a faire un mastermind
la consigne est la suivante :
il faut faire des sous programme :
- le sous programme CduPif et init pour générer les nombres aléatoires du jeu
- le sous programme saisie pour que l'utilisateur saisisse les chiffres qu'il veut
-le sous programme mal_place qui dit le nombre de chiffres mal placé
- le sous programme bien_placé qui dit le nombre de chiffres bien placés
Il me manque les fonctions mal_placé et bien_placé et peut étre quelques retouches a faire sur ce qui est deja fait mais la structure ne doit pas changé
#include <stdio.h>
#include <stdlib.h>
#define taille 4
int CduPif (int);
int init (int []);
int saisie (void);
main ()
{
int tab[taille], i;
printf ("***********************\n");
printf ("* MASTERMIND *\n");
printf ("***********************\n\n");
printf ("Bienvenue sur le jeu de Mastermind\n");
init (tab);
for (i=0; i < taille; i++)
{
printf (" %d | ",tab[i]);
}
printf ("\t");
printf (" Les chiffres ont été générés \n\n");
printf (" Début du jeu : \n\n");
saisie ();
}
int init(int tab[])
{
int i,n ;
randomize();
printf (" Jusqu'à quel valeur voulez vous initialiser le jeu??\n");
scanf ("%d",&n);
for(i=0; i<4; i++)
{
tab[i] = CduPif(n);
}
}
int CduPif(int n)
{
int a;
a = rand() % n ;
return a;
}
int saisie ()
{
int i;
int ch;
for (i=0; i < taille; i++)
{
printf ("Veuillez saisir le chiffre %d : ",i+1);
scanf ("%d",&ch);
}
}
merci
la consigne est la suivante :
il faut faire des sous programme :
- le sous programme CduPif et init pour générer les nombres aléatoires du jeu
- le sous programme saisie pour que l'utilisateur saisisse les chiffres qu'il veut
-le sous programme mal_place qui dit le nombre de chiffres mal placé
- le sous programme bien_placé qui dit le nombre de chiffres bien placés
Il me manque les fonctions mal_placé et bien_placé et peut étre quelques retouches a faire sur ce qui est deja fait mais la structure ne doit pas changé
#include <stdio.h>
#include <stdlib.h>
#define taille 4
int CduPif (int);
int init (int []);
int saisie (void);
main ()
{
int tab[taille], i;
printf ("***********************\n");
printf ("* MASTERMIND *\n");
printf ("***********************\n\n");
printf ("Bienvenue sur le jeu de Mastermind\n");
init (tab);
for (i=0; i < taille; i++)
{
printf (" %d | ",tab[i]);
}
printf ("\t");
printf (" Les chiffres ont été générés \n\n");
printf (" Début du jeu : \n\n");
saisie ();
}
int init(int tab[])
{
int i,n ;
randomize();
printf (" Jusqu'à quel valeur voulez vous initialiser le jeu??\n");
scanf ("%d",&n);
for(i=0; i<4; i++)
{
tab[i] = CduPif(n);
}
}
int CduPif(int n)
{
int a;
a = rand() % n ;
return a;
}
int saisie ()
{
int i;
int ch;
for (i=0; i < taille; i++)
{
printf ("Veuillez saisir le chiffre %d : ",i+1);
scanf ("%d",&ch);
}
}
merci