1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <time.h>
#include <string>
#include <sstream>
using namespace std;
void introduction()
{
int const lenCombinaison(3);
string grandeLigneEtoile("*****************************************************************");
string petiteLigneEtoile(" ***************************************");
cout << "" << endl;
cout << petiteLigneEtoile << endl << petiteLigneEtoile << endl << " **** ****" << endl ;
cout << " **** MASTERMIND ... ****" << endl << " **** ****" << endl;
cout << petiteLigneEtoile << endl << petiteLigneEtoile << endl << endl;
/* DEFINITION DES REGLES ET SYMBOLES */
cout << grandeLigneEtoile << endl << "**** " << "Pour gagner : deviner la combinaison de " << lenCombinaison << " chiffres. ****" << endl;
cout << grandeLigneEtoile << endl << "**** I -> chiffre correct et bien place ****" << endl << "**** O -> se trouve dans la combinaison ****" << endl ;
cout << "**** X -> pas dans la combinaison ****" << endl << grandeLigneEtoile << endl << endl << grandeLigneEtoile << endl << " QUE LE JEUX COMMENCE !!!" << endl ;
}
void ligneEtoilee()
{
cout << "*****************************************************************" << endl;
}
int main()
{
int const lenCombinaison(3);
int const lenReponse(lenCombinaison);
int codeSecret[lenCombinaison];
int combi[lenReponse];
bool encoreUneErreurMini;
srand(time(NULL));
int nombre_aleatoire(0);
int nombreJoueur(1);
int proposiJoueur(0);
int rejouerUtilisateur (0);
int chiffreAestTrouve(0);
int chiffreBestTrouve(0);
int chiffreCestTrouve(0);
int essai(0);
int record(0);
string messageaa;
string messagebb;
string messagecc;
int nombre (0);
int chifgg (0);
int effgrdt (0);
introduction(); /* Message d'intro du jeux + règles du jeux. */
/* ICI ON POURRAIT METTRE UNE INVITATION SUR LE NOMBRE DE JOUEUR */
do
{ /* DEBUT DE LA BOUCLE POUR REJOUER */
/* CREATION DE LA COMBINAISON SECRETE */
for (int i(1);i<lenCombinaison+1;++i){
for(int b=1; b<2; ++b){
nombre_aleatoire= rand();
for (int a(0);nombre_aleatoire>10;++a){
nombre_aleatoire = nombre_aleatoire / 2,14549849486;
}
codeSecret[i] = nombre_aleatoire / 2,4468464648;
/*cout << codeSecret[i] << endl;*/
}
}
do
{ /* DEBUT DE LA BOUCLE POUR PLUSIEURS ESSAIS
/* JOUEUR JOUE */
essai = ++essai;
cout << "Coup No " << essai << ", saisissez votre combinaison : ";
cin >> proposiJoueur;
/* ON DECORTIQUE POUR AVOIR UN CHIFFRE PAR NOMBRE */
for(int d=1; d<lenReponse+1; ++d){
if (d == 1 && lenCombinaison == 3)
{
combi[d] = proposiJoueur / 100;
}
if (d == 2 && lenCombinaison == 3)
{
combi[d] = (proposiJoueur % 100) / 10;
}
if (d == 3 && lenCombinaison == 3)
{
combi[d] = (proposiJoueur % 10);
}
}
/* ON COMPARE CHAQUE CHIFFRE POUR VERIFIER SI LA COMBINAISON EST BONNE */
for(int k=1; k<lenReponse+1; ++k){
if (combi[k] == codeSecret[k])
{
if (k == 1)
{
chiffreAestTrouve = 1;
messageaa = "I " ;
}
if (k == 2)
{
chiffreBestTrouve = 1;
messagebb = "I " ;
}
if (k == 3)
{
chiffreCestTrouve = 1;
messagecc = "I " ;
}
}
else
{
if (k == 1)
{
if (combi[k] == codeSecret[2] ||combi[k] == codeSecret[3])
{
chiffreAestTrouve = 0;
messageaa = "O " ;
}
else
{
chiffreAestTrouve = 0;
messageaa = "X " ;
}
}
if (k == 2)
{
if (combi[k] == codeSecret[1] ||combi[k] == codeSecret[3])
{
chiffreBestTrouve = 0;
messagebb = "O " ;
}
else
{
chiffreBestTrouve = 0;
messagebb = "X " ;
}
}
if (k == 3)
{
if (combi[k] == codeSecret[1] ||combi[k] == codeSecret[2])
{
chiffreCestTrouve = 0;
messagecc = "O " ;
}
else
{
chiffreCestTrouve = 0;
messagecc = "X " ;
}
}
}
}
cout << " " << messageaa << " " << messagebb << " " << messagecc << endl;
ligneEtoilee();
}while (chiffreAestTrouve != 1 || chiffreBestTrouve != 1 || chiffreCestTrouve !=1) ;
cout << "OUI ! La combinaison gagnante était bien : " << codeSecret[1] << "" << codeSecret[2] << "" << codeSecret[3] << endl << endl;
cout << "Combinaison trouvée en " << essai << " essai(s). Essayez battre votre score !" << endl << endl;
if (record == 0)
{
int record (essai);
cout << "" << essai << " coup(s), record enregistré !" << endl << endl;
}
else
{
if (record > essai)
{
record = essai;
cout << "Nouveau record de " << essai << " coup(s) enregistrés ! Felicitation !" << endl << endl;
}
else
{
cout << "Vous n'avez pas battu votre record de " << record << " coup(s) !" << endl << endl;
}
}
essai = 0;
cout << "Pour rejouer, saisir 1 sinon 0." << endl << endl;
cin >> rejouerUtilisateur;
}while (rejouerUtilisateur == 1);
return 0;
} |
Partager