Accueil > > > PROGRAMME DE JEU DE MPT
PROGRAMME DE JEU DE MPT
Information sur la source
Description
Tout vient de moi, et vous pouvez vous en servir comme bon vous le semble pour vos programmes. Fonction de calcul de moyenne, ouverture de fichier..
Source
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <stdlib.h>
- #include <cmath>
- #include <vector>
- #include <ctime>
- #include <cstdlib>
- #include <time.h>
-
- using namespace std;
-
- void statDeLaPartie(int decompteur)
- {
- ofstream statFlux("bla/stat.txt", ios::app);
-
- statFlux << decompteur * 4 << endl;
-
- }
-
- void afficherMoyenne ()
- {
- double moyenne(0);
-
- int b;
-
- vector <int> notes;
-
- ifstream fichier("bla/stat.txt");
-
- string line;
-
- if(fichier)
- {
- while(getline(fichier, line))
- {
- b = atof(line.c_str());
- notes.push_back(b);
- }
- }
- else
- {
- cout << "impossible d'ouvrir le fichier " << endl;
- }
-
-
-
- for (int i(0); notes.size() > i; i++)
- {
- moyenne += notes[i];
- }
-
- moyenne /= notes.size();
-
-
- cout << "Votre moyenne est de:" << moyenne << endl << endl;
- }
-
- void motIndice (string motChoisi)
- {
- for (int indice(0); indice != 3; indice++)
- {
- cout << motChoisi[indice];
- }
- }
-
- unsigned int nbAleatoire(int range)
- {
- unsigned int aleatoire = (rand() & 0xFFFF) | ((rand() & 0xFFFF) << 16);
-
- if (range == 0)
- {
- range = 2;
- }
- return aleatoire % range;
- }
-
- string choixMot(vector <string> &dico)
- {
- string motDict;
-
- if (dico.size() != 0)
- {
-
- motDict = dico[nbAleatoire(dico.size())];
-
- }
-
- else if (dico.size() == 0)
- {
- motDict = "AUCUN";
- }
-
- return motDict;
- }
-
- string melanger(string mot)
- {
- string melange;
- int position(0);
-
- while (mot.size() != 0)
- {
-
- position = rand() % mot.size();
- melange += mot[position];
- mot.erase(position, 1);
- }
-
- return melange;
- }
-
- vector <string> dictionnaire(string nomFichier)
- {
- ifstream fichier(nomFichier.c_str());
- vector <string> dico;
- string line;
-
- cout << "Chargement du dictionnaire..." << endl;
- if(fichier)
- {
- while(getline(fichier, line)) dico.push_back(line);
- return dico;
- }
- else cout << "impossible d'ouvrir le fichier " << nomFichier << endl;
- }
-
- int main()
- {
- srand(time(NULL));
-
- bool quitter(1), continuer(1), continuerDuDico(1);
-
- int choixMenuPrincip(0), choixMenuDic(0), choixMenuStat(0),
- choixMenuDuDico(0), choixMenuDuDico2(0), decompteur(5);
-
- string const dicoFr("personnalise.txt"), dicoFr2("francais.txt");
- string motEntreDicoFr, dictionnaireChoisi("personnalise.txt"), motChoisi, motMelanger, motPense;
-
- vector <string> dico;
-
-
- do
- {
- cout << " /----------------------------!" << endl;
- cout << "! BIEVENUE DANS LE !" << endl;
- cout << "! PROGRAMMES D'ENTRAINEMENT !" << endl;
- cout << "! DES LANGUES DE !" << endl;
- cout << "! !" << endl;
- cout << "! !" << endl;
- cout << "! KERIZ !" << endl;
- cout << "!___________________________/ " << endl << endl;
-
-
-
-
-
- do
- {
-
-
- cout << "Que voulez vous faire ?" << endl;
- cout << "1.Entrer des mots dans le dictionnaire" << endl;
- cout << "2.Choix du dictionnaire" << endl;
- cout << "3.Statistiques" << endl;
- cout << "4.Commencer une partie" << endl;
- cout << "5.Quittez le jeu" << endl << endl;
- cout << "Votre choix ? ";
-
- cin >> choixMenuPrincip;
-
- }
-
- while (choixMenuPrincip >= 6 || choixMenuPrincip == 0);
-
-
-
- switch (choixMenuPrincip)
- {
- // DEBUT CASE 1 //Case 1 fini
- case 1:
- {
- system("cls");
- do
- {
- cout << "Entrez le mot en francais: " << endl;
-
- ofstream dicoFrancais(dicoFr.c_str(), ios::app); //ios::app
- cin.get();
- getline(cin, motEntreDicoFr);
-
- if (dicoFrancais)
- {
- dicoFrancais << motEntreDicoFr << endl;
- }
-
-
- else
- {
- cout << "ERREUR DANS LA CREATION DU FICHIER " << dicoFr << endl;
- }
-
-
-
-
-
- do
- {
-
-
- cout << endl << "Que voulez vous faire ?" << endl;
- cout << "1.Continuer a entrer des mots" << endl;
- cout << "2.Remettre le dictionnaire a 0" << endl;
- cout << "3.Retourner au menu" << endl << endl;
- cout << "Votre choix ? ";
-
- cin >> choixMenuDic;
-
- }
-
- while (choixMenuDic >= 4 || choixMenuDic == 0);
-
- switch (choixMenuDic)
- {
- case 1:
- {
- continuer = 1;
- break;
- }
-
- case 2:
- {
- ofstream dicoFrancais(dicoFr.c_str());
- continuer = 0;
- break;
- }
-
- case 3:
- {
- continuer = 0;
- break;
- }
-
- }
- }
-
- while (continuer);
-
- system("cls");
-
- break;
-
- }
- //CASE 2
- case 2:
- {
- system("cls");
-
- do
- {
- cout << "Que voulez vous faire ?" << endl;
- cout << "1.Regarder les mots de mon dictionnaire" << endl;
- cout << "2.Choisir le dictionnaire avec lequel je joue" << endl;
- cout << "3.Retourner au menu"<< endl << endl;
- cout << "Votre choix: " << endl;
-
- cin >> choixMenuDuDico;
-
- system("cls");
-
- }
- while (choixMenuDuDico >= 4);
-
-
-
- switch (choixMenuDuDico)
- {
- case 1:
- {
- system("cls");
-
- ifstream dicoALire(dicoFr.c_str());
-
- if (dicoALire)
- {
- cout << "Dictionnaire :" << endl << endl;
- string ligne;
-
- while (getline(dicoALire, ligne))
- {
- cout << ligne << endl;
- }
- }
-
- else
- {
- cout << "ERREUR DANS LA LECTURE DU DICO" << endl;
- }
-
- cout << endl << "Fin du dictionnaire" << endl << endl;
-
- system("Pause");
-
- system("cls");
- break;
- }
-
- case 2:
- {
- do
- {
-
-
- cout << "Quel dictionnaire veux tu choisir ?" << endl;
- cout << "1.Le mien" << endl;
- cout << "2.Langue francais (environ 360000 mots)" << endl << endl;
- cout << "Votre choix: ";
-
- cin >> choixMenuDuDico2;
-
- system("cls");
-
- }
- while (choixMenuDuDico2 >= 3);
-
- switch (choixMenuDuDico2)
- {
- case 1:
- {
- dictionnaireChoisi = "personnalise.txt";
- system("cls");
- break;
- }
-
- case 2:
- {
- dictionnaireChoisi = "francais.txt";
- system("cls");
- break;
- }
-
- }
-
- continuerDuDico = 0;
- break;
- }
-
- case 3:
- {
- system("cls");
- continuerDuDico = 0;
- break;
- }
- }
-
-
-
-
- break;
- }
-
- case 3:
- {
- do
- {
-
-
- system("cls");
-
- cout << "Que veux tu faire ?" << endl;
- cout << "1.Voir ma moyenne (/20)" << endl;
- cout << "2.Remettre a 0 les scores" << endl << endl;
- cout << "Votre choix: " << endl;
-
- cin >> choixMenuStat;
-
- }
- while (choixMenuStat >= 3 || choixMenuStat == 0);
-
- switch (choixMenuStat)
- {
- case 1:
- {
- afficherMoyenne();
-
- system("pause");
- system("cls");
-
- break;
- }
-
- case 2:
- {
- ofstream fichier("stat.txt");
- system("CLS");
- }
- }
- break;
- }
-
- case 4:
- {
- system("cls");
-
- dico = dictionnaire(dictionnaireChoisi);
-
- cout << "Tirage du mot en cours.." << endl << endl << endl;
-
- motChoisi = choixMot(dico);
-
- motMelanger = motChoisi;
-
- motMelanger = melanger(motMelanger);
-
- cout << "Quel est le mot mystere ? " << motMelanger << endl << endl;
-
- while (decompteur != 0)
- {
- if (decompteur - 2 >> 0)
- {
- if (decompteur == 1)
- {
- cout << "Tu as encore " << decompteur << " essaies, voici l'indice (debut du mot): ";
- motIndice(motChoisi);
- cout << endl;
- cout << "Je pense: ";
- }
-
- if (decompteur != 1)
- {
- cout << "Tu as encore " << decompteur << " essaies, il te reste maintenant "
- << decompteur - 2 << " fautes avant un indice !" << endl
- << "Je pense: ";
- }
-
- }
-
- else
- {
- cout << "Tu as encore " << decompteur << " essaies, voici l'indice (debut du mot): ";
- motIndice(motChoisi);
- cout << endl;
- cout << "Je pense: ";
-
- }
-
-
-
-
-
- cin >> motPense;
-
- cout << endl << endl;
-
-
- if (motPense == motChoisi)
- {
- statDeLaPartie(decompteur);
-
- decompteur = 1;
-
- cout << "Tu as trouver le mot (" << motChoisi << ") !" << endl << endl;
-
- system("pause");
-
- dico = dictionnaire(dictionnaireChoisi);
-
- motChoisi = "";
-
- motMelanger = "";
-
- system("cls");
-
- }
-
-
- decompteur = decompteur - 1;
-
- }
-
- if (decompteur == 0 && motChoisi != "")
-
- {
- statDeLaPartie(0);
- cout << "Tu as perdu... Le mot a trouve etait " << motChoisi << ". Retente ta chance !" << endl;
-
- system("pause");
-
- dico = dictionnaire(dictionnaireChoisi);
-
- motChoisi = "";
-
- motMelanger = "";
-
- system("cls");
- }
-
- decompteur = 5;
-
- break;
- }
-
- case 5:
- {
- quitter = 0;
- break;
- }
-
- }
-
-
-
- }
- while (quitter);
- return 0;
- }
#include <iostream>
#include <string>
#include <fstream>
#include <stdlib.h>
#include <cmath>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <time.h>
using namespace std;
void statDeLaPartie(int decompteur)
{
ofstream statFlux("bla/stat.txt", ios::app);
statFlux << decompteur * 4 << endl;
}
void afficherMoyenne ()
{
double moyenne(0);
int b;
vector <int> notes;
ifstream fichier("bla/stat.txt");
string line;
if(fichier)
{
while(getline(fichier, line))
{
b = atof(line.c_str());
notes.push_back(b);
}
}
else
{
cout << "impossible d'ouvrir le fichier " << endl;
}
for (int i(0); notes.size() > i; i++)
{
moyenne += notes[i];
}
moyenne /= notes.size();
cout << "Votre moyenne est de:" << moyenne << endl << endl;
}
void motIndice (string motChoisi)
{
for (int indice(0); indice != 3; indice++)
{
cout << motChoisi[indice];
}
}
unsigned int nbAleatoire(int range)
{
unsigned int aleatoire = (rand() & 0xFFFF) | ((rand() & 0xFFFF) << 16);
if (range == 0)
{
range = 2;
}
return aleatoire % range;
}
string choixMot(vector <string> &dico)
{
string motDict;
if (dico.size() != 0)
{
motDict = dico[nbAleatoire(dico.size())];
}
else if (dico.size() == 0)
{
motDict = "AUCUN";
}
return motDict;
}
string melanger(string mot)
{
string melange;
int position(0);
while (mot.size() != 0)
{
position = rand() % mot.size();
melange += mot[position];
mot.erase(position, 1);
}
return melange;
}
vector <string> dictionnaire(string nomFichier)
{
ifstream fichier(nomFichier.c_str());
vector <string> dico;
string line;
cout << "Chargement du dictionnaire..." << endl;
if(fichier)
{
while(getline(fichier, line)) dico.push_back(line);
return dico;
}
else cout << "impossible d'ouvrir le fichier " << nomFichier << endl;
}
int main()
{
srand(time(NULL));
bool quitter(1), continuer(1), continuerDuDico(1);
int choixMenuPrincip(0), choixMenuDic(0), choixMenuStat(0),
choixMenuDuDico(0), choixMenuDuDico2(0), decompteur(5);
string const dicoFr("personnalise.txt"), dicoFr2("francais.txt");
string motEntreDicoFr, dictionnaireChoisi("personnalise.txt"), motChoisi, motMelanger, motPense;
vector <string> dico;
do
{
cout << " /----------------------------!" << endl;
cout << "! BIEVENUE DANS LE !" << endl;
cout << "! PROGRAMMES D'ENTRAINEMENT !" << endl;
cout << "! DES LANGUES DE !" << endl;
cout << "! !" << endl;
cout << "! !" << endl;
cout << "! KERIZ !" << endl;
cout << "!___________________________/ " << endl << endl;
do
{
cout << "Que voulez vous faire ?" << endl;
cout << "1.Entrer des mots dans le dictionnaire" << endl;
cout << "2.Choix du dictionnaire" << endl;
cout << "3.Statistiques" << endl;
cout << "4.Commencer une partie" << endl;
cout << "5.Quittez le jeu" << endl << endl;
cout << "Votre choix ? ";
cin >> choixMenuPrincip;
}
while (choixMenuPrincip >= 6 || choixMenuPrincip == 0);
switch (choixMenuPrincip)
{
// DEBUT CASE 1 //Case 1 fini
case 1:
{
system("cls");
do
{
cout << "Entrez le mot en francais: " << endl;
ofstream dicoFrancais(dicoFr.c_str(), ios::app); //ios::app
cin.get();
getline(cin, motEntreDicoFr);
if (dicoFrancais)
{
dicoFrancais << motEntreDicoFr << endl;
}
else
{
cout << "ERREUR DANS LA CREATION DU FICHIER " << dicoFr << endl;
}
do
{
cout << endl << "Que voulez vous faire ?" << endl;
cout << "1.Continuer a entrer des mots" << endl;
cout << "2.Remettre le dictionnaire a 0" << endl;
cout << "3.Retourner au menu" << endl << endl;
cout << "Votre choix ? ";
cin >> choixMenuDic;
}
while (choixMenuDic >= 4 || choixMenuDic == 0);
switch (choixMenuDic)
{
case 1:
{
continuer = 1;
break;
}
case 2:
{
ofstream dicoFrancais(dicoFr.c_str());
continuer = 0;
break;
}
case 3:
{
continuer = 0;
break;
}
}
}
while (continuer);
system("cls");
break;
}
//CASE 2
case 2:
{
system("cls");
do
{
cout << "Que voulez vous faire ?" << endl;
cout << "1.Regarder les mots de mon dictionnaire" << endl;
cout << "2.Choisir le dictionnaire avec lequel je joue" << endl;
cout << "3.Retourner au menu"<< endl << endl;
cout << "Votre choix: " << endl;
cin >> choixMenuDuDico;
system("cls");
}
while (choixMenuDuDico >= 4);
switch (choixMenuDuDico)
{
case 1:
{
system("cls");
ifstream dicoALire(dicoFr.c_str());
if (dicoALire)
{
cout << "Dictionnaire :" << endl << endl;
string ligne;
while (getline(dicoALire, ligne))
{
cout << ligne << endl;
}
}
else
{
cout << "ERREUR DANS LA LECTURE DU DICO" << endl;
}
cout << endl << "Fin du dictionnaire" << endl << endl;
system("Pause");
system("cls");
break;
}
case 2:
{
do
{
cout << "Quel dictionnaire veux tu choisir ?" << endl;
cout << "1.Le mien" << endl;
cout << "2.Langue francais (environ 360000 mots)" << endl << endl;
cout << "Votre choix: ";
cin >> choixMenuDuDico2;
system("cls");
}
while (choixMenuDuDico2 >= 3);
switch (choixMenuDuDico2)
{
case 1:
{
dictionnaireChoisi = "personnalise.txt";
system("cls");
break;
}
case 2:
{
dictionnaireChoisi = "francais.txt";
system("cls");
break;
}
}
continuerDuDico = 0;
break;
}
case 3:
{
system("cls");
continuerDuDico = 0;
break;
}
}
break;
}
case 3:
{
do
{
system("cls");
cout << "Que veux tu faire ?" << endl;
cout << "1.Voir ma moyenne (/20)" << endl;
cout << "2.Remettre a 0 les scores" << endl << endl;
cout << "Votre choix: " << endl;
cin >> choixMenuStat;
}
while (choixMenuStat >= 3 || choixMenuStat == 0);
switch (choixMenuStat)
{
case 1:
{
afficherMoyenne();
system("pause");
system("cls");
break;
}
case 2:
{
ofstream fichier("stat.txt");
system("CLS");
}
}
break;
}
case 4:
{
system("cls");
dico = dictionnaire(dictionnaireChoisi);
cout << "Tirage du mot en cours.." << endl << endl << endl;
motChoisi = choixMot(dico);
motMelanger = motChoisi;
motMelanger = melanger(motMelanger);
cout << "Quel est le mot mystere ? " << motMelanger << endl << endl;
while (decompteur != 0)
{
if (decompteur - 2 >> 0)
{
if (decompteur == 1)
{
cout << "Tu as encore " << decompteur << " essaies, voici l'indice (debut du mot): ";
motIndice(motChoisi);
cout << endl;
cout << "Je pense: ";
}
if (decompteur != 1)
{
cout << "Tu as encore " << decompteur << " essaies, il te reste maintenant "
<< decompteur - 2 << " fautes avant un indice !" << endl
<< "Je pense: ";
}
}
else
{
cout << "Tu as encore " << decompteur << " essaies, voici l'indice (debut du mot): ";
motIndice(motChoisi);
cout << endl;
cout << "Je pense: ";
}
cin >> motPense;
cout << endl << endl;
if (motPense == motChoisi)
{
statDeLaPartie(decompteur);
decompteur = 1;
cout << "Tu as trouver le mot (" << motChoisi << ") !" << endl << endl;
system("pause");
dico = dictionnaire(dictionnaireChoisi);
motChoisi = "";
motMelanger = "";
system("cls");
}
decompteur = decompteur - 1;
}
if (decompteur == 0 && motChoisi != "")
{
statDeLaPartie(0);
cout << "Tu as perdu... Le mot a trouve etait " << motChoisi << ". Retente ta chance !" << endl;
system("pause");
dico = dictionnaire(dictionnaireChoisi);
motChoisi = "";
motMelanger = "";
system("cls");
}
decompteur = 5;
break;
}
case 5:
{
quitter = 0;
break;
}
}
}
while (quitter);
return 0;
}
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Personnalisation console windows [ par fredd49 ]
Salut à tous, J'aurrai voulu savoir :1 - comment faire pour mettre de la couleur sur le texte dans la console windows en C++2 - Comment mettre
|
Derniers Blogs
VOTEZ POUR LE TOP 10 DES INFLUENCEURS SHAREPOINT FRANCOPHONES !VOTEZ POUR LE TOP 10 DES INFLUENCEURS SHAREPOINT FRANCOPHONES ! par Patrick Guimonet
Si ce n'est déjà fait (comme plus de 600 personnes déjà), il est encore temps de voter pour le concours TOP 10 des influenceurs SharePoint francophones ! Il est organisé par harmon.ie et accessible ici : http://harmon.ie/top-...
Cliquez pour lire la suite de l'article par Patrick Guimonet [CONF'SHAREPOINT] DERNIER RAPPEL ! :-)[CONF'SHAREPOINT] DERNIER RAPPEL ! :-) par Patrick Guimonet
La Conf'SharePoint en chiffres c'est : 3 jours de SharePoint ! 4 parcours et 60 sessions 17 partenaires représentant toutes les fac...
Cliquez pour lire la suite de l'article par Patrick Guimonet [ #SHAREPOINT 2013 ] LES MODèLES DE SITES STANDARDS.[ #SHAREPOINT 2013 ] LES MODèLES DE SITES STANDARDS. par Patrick Guimonet
C'est un point peu mis en avant mais SharePoint 2013 a été l'occasion de remettre de l'ordre dans les modèles de sites. Tout d'abord, un certain nombre de modèles ont été tout simplement rendus obsolètes (cf. Fonctionnalités déco...
Cliquez pour lire la suite de l'article par Patrick Guimonet 10 ERREURS DE COMPRéHENSION CONCERNANT SHAREPOINT.10 ERREURS DE COMPRéHENSION CONCERNANT SHAREPOINT. par Patrick Guimonet
Une excellente infographie (qui a sa source ici :http://www.evokeit.com/sharepoint-blog/misconceptions-of-microsoft-sharepoint) que j'ai traduite et commentée sur le blog d'Abalon : http://abalon.fr/blog/10-erreurs-de-comprhension-...
Cliquez pour lire la suite de l'article par Patrick Guimonet
Forum
MINI PROJETMINI PROJET par codexana
Cliquez pour lire la suite par codexana
Logiciels
Nego Facturation (1.84)NEGO FACTURATION (1.84)Nego Facturation est un logiciel complet qui permet de gérer vos factures et devis très simplemen... Cliquez pour télécharger Nego Facturation Revealer Keylogger Free (2.07)REVEALER KEYLOGGER FREE (2.07)Keylogger invisible et gratuit pour Windows 8, 7, Vista ou XP. Revealer Keylogger Free vous perme... Cliquez pour télécharger Revealer Keylogger Free Devis-Factures PHMSD (2.1.0.1)DEVIS-FACTURES PHMSD (2.1.0.1)Configuration minimale
Nécessite Windows™ 2000, XP, Windows 7, 8, Vista (Service Pack à... Cliquez pour télécharger Devis-Factures PHMSD Ludoprêt (3.2)LUDOPRêT (3.2)Logiciel gratuit de gestion de ludothèque.
Gestion des jeux et des adhérents.
Gestion des for... Cliquez pour télécharger Ludoprêt 974 Application Server (13.2.1.3)974 APPLICATION SERVER (13.2.1.3)Ecommerce, Blogueur, Vitrine, Newsletter, Java IDE, ..., in the cloud et sous haute dispo. Facile... Cliquez pour télécharger 974 Application Server
|