From c0497715970a930df28dd99e5f6e9ab792f57580 Mon Sep 17 00:00:00 2001 From: simong4 Date: Mon, 3 Apr 2023 09:54:42 -0400 Subject: Version Audit3 Version utilisee pour l'audit3 --- main.cpp | 915 ++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 461 insertions(+), 454 deletions(-) diff --git a/main.cpp b/main.cpp index b298db0..a9529ac 100644 --- a/main.cpp +++ b/main.cpp @@ -32,8 +32,8 @@ using namespace std; /*------------------------- Prototypes de fonctions -------------------------*/ -bool SendToSerial(SerialPort *arduino, json j_msg); -bool RcvFromSerial(SerialPort *arduino, string &msg); +bool SendToSerial(SerialPort* arduino, json j_msg); +bool RcvFromSerial(SerialPort* arduino, string& msg); void RcvJsonThread(); bool ComparePlayedNotes(ChordNote note, bool strumNeeded); bool CompareIndividualButton(bool wantedValue, int buttonState); @@ -42,8 +42,9 @@ int GetLedState(); int displayMenu(); bool MenuInitialisation(int& numeroChanson, int& niveauDifficulte, vector repo); + /*---------------------------- Variables globales ---------------------------*/ -SerialPort * arduino; //doit etre un objet global! +SerialPort* arduino; //doit etre un objet global! int LedState = 0; int Fret1 = 0; int Fret2 = 0; @@ -70,12 +71,16 @@ int main() { vector repertoire; //Liste des chansons disponibles: vector songFolders; //Liste des dossiers chansons disponibles: - songFolders.push_back("\\Maynard-Ferguson-Birdland\\"); - //songFolders.push_back("\\Maynard-Ferguson-Country-Road-(James-Taylor-Cover)\\"); - //songFolders.push_back("\\Maynard-Ferguson-Theme-From-Shaft\\"); - //songFolders.push_back("\\Owane-Rock-Is-Too-Heavy\\"); - //songFolders.push_back("\\Stevie-Wonder-Contusion\\"); - //songFolders.push_back("\\Victor-Wooten-and-Steve-Bailey-A-Chick-from-Corea-(Live)\\"); + /*songFolders.push_back("\\Maynard-Ferguson-Birdland\\"); + songFolders.push_back("\\Maynard-Ferguson-Country-Road-(James-Taylor-Cover)\\"); + songFolders.push_back("\\Maynard-Ferguson-Theme-From-Shaft\\"); + songFolders.push_back("\\Owane-Rock-Is-Too-Heavy\\"); + songFolders.push_back("\\Stevie-Wonder-Contusion\\"); + songFolders.push_back("\\Victor-Wooten-and-Steve-Bailey-A-Chick-from-Corea-(Live)\\");*/ + songFolders.push_back("\\Greta-Van-Fleet-Highway-Tune\\"); + songFolders.push_back("\\Joan-Jett-and-the-Blackhearts-I-Love-Rock-_N-Roll-(The-Arrows-Cover)\\"); + songFolders.push_back("\\Santana-Oye-Como-Va-(Tito-Puente-Cover)\\"); + songFolders.push_back("\\Symphony-X-Eve-of-Seduction\\"); string songRoot = "..\\songs"; string chartFile = "notes.chart"; @@ -83,6 +88,7 @@ int main() { repertoire.push_back(Song(songRoot + songFolders[i] + chartFile)); } + cout << "Chargement des chansons" << endl; // Parse all the songs for (int difficulty = 0; difficulty < 4; difficulty++) { @@ -92,7 +98,7 @@ int main() repertoire[i].parseChords(difficulty); repertoire[i].consolidateChords(difficulty); repertoire[i].trim(difficulty); - cout << repertoire[i].getTitle() << " parsed!" << endl; + //cout << repertoire[i].getTitle() << " parsed!" << endl; } } @@ -189,7 +195,7 @@ int main() auto currentTime = chrono::steady_clock::now(); totalDiff = int(std::chrono::duration_cast (currentTime - startTime).count()); - if(totalDiff > endOfSong)//End of song + if (totalDiff > endOfSong)//End of song //if (nextNoteToPlay == song.size()) { isThreadOver = true; @@ -413,8 +419,8 @@ int main() displayString += "Multiplicateur : x" + powerupModifierString.substr(0, powerupModifierString.find(".")) + "\n"; } - string IsShakingString = to_string(IsShaking); - displayString += "IsShaking : " + IsShakingString.substr(0, IsShakingString.find(".")) + "\n"; + //string IsShakingString = to_string(IsShaking); + //displayString += "IsShaking : " + IsShakingString.substr(0, IsShakingString.find(".")) + "\n"; cout << displayString; } @@ -425,196 +431,196 @@ int main() return 0; } - /*---------------------------Definition de fonctions ------------------------*/ - bool SendToSerial(SerialPort *arduino, json j_msg){ - // Return 0 if error - string msg = j_msg.dump(); - bool ret = arduino->writeSerialPort(msg.c_str(), msg.length()); - return ret; - } - - - bool RcvFromSerial(SerialPort *arduino, string &msg){ - // Return 0 if error - // Message output in msg - string str_buffer; - char char_buffer[MSG_MAX_SIZE]; - int buffer_size; - - msg.clear(); // clear string - // Read serialport until '\n' character (Blocking) - - // Version fonctionnel dans VScode, mais non fonctionnel avec Visual Studio - /* - while(msg.back()!='\n'){ - if(msg.size()>MSG_MAX_SIZE){ - return false; - } - - buffer_size = arduino->readSerialPort(char_buffer, MSG_MAX_SIZE); - str_buffer.assign(char_buffer, buffer_size); - msg.append(str_buffer); - } - */ - - // Version fonctionnelle dans VScode et Visual Studio - buffer_size = arduino->readSerialPort(char_buffer, MSG_MAX_SIZE); - str_buffer.assign(char_buffer, buffer_size); - msg.append(str_buffer); - - //msg.pop_back(); //remove '/n' from string - - return true; - } - - void RcvJsonThread() - { - string raw_msg; - json json_recu; - json json_envoye; - while (!isThreadOver) - { - //Envoie message Arduino - json_envoye["led"] = GetLedState(); - if (!SendToSerial(arduino, json_envoye)) { - cerr << "Erreur lors de l'envoie du message. " << endl; - } - // Reception message Arduino - json_recu.clear(); // effacer le message precedent - if (!RcvFromSerial(arduino, raw_msg)) { - cerr << "Erreur lors de la reception du message. " << endl; - } - //cout << "Message : " << raw_msg << endl; - - // Impression du message de l'Arduino si valide - if (raw_msg.size() > 0) { - //cout << "raw_msg: " << raw_msg << endl; // debug - // Transfert du message en json - json_recu = json::parse(raw_msg); - //out << "Message de l'Arduino: " << json_recu << endl; - } - if (json_recu == json::value_t::null) - { - //cout << "DATA_NULL\n"; - } - else - { - //cout << "longueur " << j_msg_rcv.size() <<"\n"; - //cout << "7 " << j_msg_rcv[7] <<"\n"; - Fret1 = json_recu[FRET1]; - Fret2 = json_recu[FRET2]; - Fret3 = json_recu[FRET3]; - Fret4 = json_recu[FRET4]; - Fret5 = json_recu[FRET5]; - /*StrumUp = json_recu[STRUM_UP]; - StrumDown = json_recu[STRUM_DN];*/ - - int tempStrumUP = json_recu[STRUM_UP]; - if (tempStrumUP == 1) - { - if (consecutiveStrumUP > 0) - { - StrumUp = 0; - } - else { - StrumUp = 1; - consecutiveStrumUP++; - isSameStrumUP = false; - } - } - else{ - StrumUp = 0; - consecutiveStrumUP = 0; - } - - int tempStrumDown = json_recu[STRUM_DN]; - if (tempStrumDown == 1) - { - if (consecutiveStrumDN > 0) - { - StrumDown = 0; - } - else { - StrumDown = 1; - consecutiveStrumDN++; - isSameStrumDN = false; - } - } - else { - StrumDown = 0; - consecutiveStrumDN = 0; - } - - JoyDir = json_recu[JOY_DIR]; - IsShaking = json_recu[ACCEL]; - - /*if (IsShaking) - { - cout << "SENSIBILITE BEN TROP BASSE" << endl; - }*/ - } - Sleep(1); - } - } - - bool ComparePlayedNotes(ChordNote note, bool strumNeeded) - { - bool correctlyPlayed = false; - bool* notes = note.getNotes(); - - bool comp1 = CompareIndividualButton(notes[0], Fret1); - bool comp2 = CompareIndividualButton(notes[1], Fret2); - bool comp3 = CompareIndividualButton(notes[2], Fret3); - bool comp4 = CompareIndividualButton(notes[3], Fret4); - bool comp5 = CompareIndividualButton(notes[4], Fret5); - - if (comp1 && comp2 && comp3 && comp4 && comp5) - { - correctlyPlayed = true; - /*if (strumNeeded) - { - bool compDown = CompareIndividualButton(true, StrumDown); - if (isSameStrumDN && compDown) - { - compDown = false; - } - else { - isSameStrumDN = true; - } - bool compUp = CompareIndividualButton(true, StrumUp); - if (isSameStrumUP && compDown) - { - compUp = false; - } - else { - isSameStrumUP = true; - } - - if (!compDown && !compUp) - { - correctlyPlayed = false; - } - }*/ - } - - return correctlyPlayed; - } - - bool CompareStrums() - { - bool correctlyPlayed = false; - - bool compDn = StrumDown; - if (isSameStrumDN) - { - compDn = false; - } - else { - if (compDn) - { - isSameStrumDN = true; - } - } +/*---------------------------Definition de fonctions ------------------------*/ +bool SendToSerial(SerialPort* arduino, json j_msg) { + // Return 0 if error + string msg = j_msg.dump(); + bool ret = arduino->writeSerialPort(msg.c_str(), msg.length()); + return ret; +} + + +bool RcvFromSerial(SerialPort* arduino, string& msg) { + // Return 0 if error + // Message output in msg + string str_buffer; + char char_buffer[MSG_MAX_SIZE]; + int buffer_size; + + msg.clear(); // clear string + // Read serialport until '\n' character (Blocking) + + // Version fonctionnel dans VScode, mais non fonctionnel avec Visual Studio +/* + while(msg.back()!='\n'){ + if(msg.size()>MSG_MAX_SIZE){ + return false; + } + + buffer_size = arduino->readSerialPort(char_buffer, MSG_MAX_SIZE); + str_buffer.assign(char_buffer, buffer_size); + msg.append(str_buffer); + } +*/ + +// Version fonctionnelle dans VScode et Visual Studio + buffer_size = arduino->readSerialPort(char_buffer, MSG_MAX_SIZE); + str_buffer.assign(char_buffer, buffer_size); + msg.append(str_buffer); + + //msg.pop_back(); //remove '/n' from string + + return true; +} + +void RcvJsonThread() +{ + string raw_msg; + json json_recu; + json json_envoye; + while (!isThreadOver) + { + //Envoie message Arduino + json_envoye["led"] = GetLedState(); + if (!SendToSerial(arduino, json_envoye)) { + cerr << "Erreur lors de l'envoie du message. " << endl; + } + // Reception message Arduino + json_recu.clear(); // effacer le message precedent + if (!RcvFromSerial(arduino, raw_msg)) { + cerr << "Erreur lors de la reception du message. " << endl; + } + //cout << "Message : " << raw_msg << endl; + + // Impression du message de l'Arduino si valide + if (raw_msg.size() > 0) { + //cout << "raw_msg: " << raw_msg << endl; // debug + // Transfert du message en json + json_recu = json::parse(raw_msg); + //out << "Message de l'Arduino: " << json_recu << endl; + } + if (json_recu == json::value_t::null) + { + //cout << "DATA_NULL\n"; + } + else + { + //cout << "longueur " << j_msg_rcv.size() <<"\n"; + //cout << "7 " << j_msg_rcv[7] <<"\n"; + Fret1 = json_recu[FRET1]; + Fret2 = json_recu[FRET2]; + Fret3 = json_recu[FRET3]; + Fret4 = json_recu[FRET4]; + Fret5 = json_recu[FRET5]; + /*StrumUp = json_recu[STRUM_UP]; + StrumDown = json_recu[STRUM_DN];*/ + + int tempStrumUP = json_recu[STRUM_UP]; + if (tempStrumUP == 1) + { + if (consecutiveStrumUP > 0) + { + StrumUp = 0; + } + else { + StrumUp = 1; + consecutiveStrumUP++; + isSameStrumUP = false; + } + } + else { + StrumUp = 0; + consecutiveStrumUP = 0; + } + + int tempStrumDown = json_recu[STRUM_DN]; + if (tempStrumDown == 1) + { + if (consecutiveStrumDN > 0) + { + StrumDown = 0; + } + else { + StrumDown = 1; + consecutiveStrumDN++; + isSameStrumDN = false; + } + } + else { + StrumDown = 0; + consecutiveStrumDN = 0; + } + + JoyDir = json_recu[JOY_DIR]; + IsShaking = json_recu[ACCEL]; + + /*if (IsShaking) + { + cout << "SENSIBILITE BEN TROP BASSE" << endl; + }*/ + } + Sleep(1); + } +} + +bool ComparePlayedNotes(ChordNote note, bool strumNeeded) +{ + bool correctlyPlayed = false; + bool* notes = note.getNotes(); + + bool comp1 = CompareIndividualButton(notes[0], Fret1); + bool comp2 = CompareIndividualButton(notes[1], Fret2); + bool comp3 = CompareIndividualButton(notes[2], Fret3); + bool comp4 = CompareIndividualButton(notes[3], Fret4); + bool comp5 = CompareIndividualButton(notes[4], Fret5); + + if (comp1 && comp2 && comp3 && comp4 && comp5) + { + correctlyPlayed = true; + /*if (strumNeeded) + { + bool compDown = CompareIndividualButton(true, StrumDown); + if (isSameStrumDN && compDown) + { + compDown = false; + } + else { + isSameStrumDN = true; + } + bool compUp = CompareIndividualButton(true, StrumUp); + if (isSameStrumUP && compDown) + { + compUp = false; + } + else { + isSameStrumUP = true; + } + + if (!compDown && !compUp) + { + correctlyPlayed = false; + } + }*/ + } + + return correctlyPlayed; +} + +bool CompareStrums() +{ + bool correctlyPlayed = false; + + bool compDn = StrumDown; + if (isSameStrumDN) + { + compDn = false; + } + else { + if (compDn) + { + isSameStrumDN = true; + } + } bool compUp = StrumUp; if (isSameStrumUP) @@ -633,254 +639,255 @@ int main() correctlyPlayed = true; } return correctlyPlayed; - } - - bool CompareIndividualButton(bool wantedValue, int buttonState) - { - return wantedValue == buttonState; - } - - int GetLedState() - { - if (IsInPowerup) - { - LedState++; - if (LedState > 10) - { - LedState = 0; - } - } - else - { - if (NotesCorrectStreak % 1 == 0 && StreakWhenLastSend < NotesCorrectStreak) - { - LedState++; - StreakWhenLastSend = NotesCorrectStreak; - } - if (LedState > 10) - { - LedState = 10; - } - if (BargraphNeedReset) - { - LedState = 0; - BargraphNeedReset = false; - StreakWhenLastSend = 0; - } - } - return LedState; - } - - //bool MenuInitialisation(int& numeroChanson, int& niveauDifficulte, vector repo) { - // //display du Menu - // int repo_size = repo.size(); - // int choix = displayMenu(); - // switch (choix) - // { - // case 1: - // //choisir chanson - // system("CLS"); - // cout << "----------------------------------------------------------------------" << endl; - // cout << "\t\t\tMENU CHOIX DE CHANSON" << endl; - // cout << "----------------------------------------------------------------------\n" << endl; - // cout << " On devra faire un display des chansons disponibles...\n"; - // /* - // for (int i = 0; i < repertoire.size; i++){ - // cout << i+1 << ". " << repertoire[i].song.getTitle() << endl; - // } - // */ - // for (int i = 0; i < repo_size + 1; i++) { - // if (i == repo.size()) - // { - // cout << i + 1 << ". Retour" << endl; - // } - // else { - // cout << i + 1 << ". " << repo[i].getTitle() << endl << " par " << repo[i].getArtist() << endl; - // } - // } - // cout << "\nChoisissez une chanson : "; - // cin >> numeroChanson; - // while (numeroChanson < 1 || numeroChanson > repo.size() + 1) { - // cout << "Entree non valide. Veuillez entrer un numero de chanson valide" << endl; - // cin >> numeroChanson; - // } - // if (numeroChanson == repo.size()) - // { - // MenuInitialisation(numeroChanson, niveauDifficulte, repo); //retourne au display du menu - // } - // numeroChanson -= 1; - - // //choisir niveau de difficulté - // system("CLS"); - // cout << "----------------------------------------------------------------------" << endl; - // cout << "\t\t\tMENU NIVEAU DE DIFFICULTE" << endl; - // cout << "----------------------------------------------------------------------\n" << endl; - - // cout << "1. Easy" << endl; - // cout << "2. Medium" << endl; - // cout << "3. Hard" << endl; - // cout << "4. Expert" << endl; - - // cout << "\nChoisissez le niveau de difficulte : "; - // cin >> niveauDifficulte; - // while (niveauDifficulte < 0 || niveauDifficulte > 4) { - // cout << "Entree non valide. Veuillez entrer un niveau de difficulte valide" << endl; - // cin >> niveauDifficulte; - // } - // MenuInitialisation(numeroChanson, niveauDifficulte, repo); //retourne au display du menu - // niveauDifficulte = -1; - // return true; - // break; - // //case 3: - // // system("CLS"); - // // cout << "Le jeu va debuter...!!\n" << endl; - // // if (*numeroChanson < 1 || *numeroChanson > 4 || *niveauDifficulte < 1 || *niveauDifficulte > 4) { - // // //chanson et difficulte par defaut - // // *numeroChanson = 1; - // // *niveauDifficulte = 1; - // // } - // // cout << "Chanson choisie : " << listeChansons[*numeroChanson - 1] << endl; - // // cout << "Niveau de difficulte : " << listeDifficultes[*niveauDifficulte - 1] << "\n\n"; - // // return true; //debuter le jeu - // // break; - - // case 2: - // system("CLS"); - // cout << "A bientot, KEEP ON ROCKING!!" << endl; - // return false; //quitter le jeu - // break; - - // default: - // break; - // } - //} - - bool MenuInitialisation(int& numeroChanson, int& niveauDifficulte, vector repo) { - //display du Menu - int repo_size = repo.size(); - int choix = 0; - bool madeADecision = false; - bool retour = false; - bool wantToReturn = false; - - while (!madeADecision) - { - choix = displayMenu(); - switch (choix) - { - case 1: - wantToReturn = false; - //choisir chanson - system("CLS"); - cout << "----------------------------------------------------------------------" << endl; - cout << "\t\t\tMENU CHOIX DE CHANSON" << endl; - cout << "----------------------------------------------------------------------\n" << endl; - cout << " On devra faire un display des chansons disponibles...\n"; - /* - for (int i = 0; i < repertoire.size; i++){ - cout << i+1 << ". " << repertoire[i].song.getTitle() << endl; - } - */ - for (int i = 0; i < repo_size + 1; i++) { - if (i == repo.size()) - { - cout << i + 1 << ". Retour" << endl; - } - else { - cout << i + 1 << ". " << repo[i].getTitle() << " par " << repo[i].getArtist() << endl; - } - } - cout << "\nChoisissez une chanson : "; - cin >> numeroChanson; - while (numeroChanson < 1 || numeroChanson > repo.size() + 1) { - cout << "Entree non valide. Veuillez entrer un numero de chanson valide" << endl; - cin >> numeroChanson; - } - numeroChanson -= 1; - if (numeroChanson == repo.size()) - { - wantToReturn = true; - } - - - if (!wantToReturn) - { - //choisir niveau de difficulté - system("CLS"); - cout << "----------------------------------------------------------------------" << endl; - cout << "\t\t\tMENU NIVEAU DE DIFFICULTE" << endl; - cout << "----------------------------------------------------------------------\n" << endl; - - cout << "1. Easy" << endl; - cout << "2. Medium" << endl; - cout << "3. Hard" << endl; - cout << "4. Expert" << endl; - cout << "5. Retour" << endl; - - cout << "\nChoisissez le niveau de difficulte : "; - cin >> niveauDifficulte; - while (niveauDifficulte < 0 || niveauDifficulte > 5) { - cout << "Entree non valide. Veuillez entrer un niveau de difficulte valide" << endl; - cin >> niveauDifficulte; - } - - if (niveauDifficulte == 5) - { - wantToReturn = true; - } - - niveauDifficulte -= 1; - //case 3: - // system("CLS"); - // cout << "Le jeu va debuter...!!\n" << endl; - // if (*numeroChanson < 1 || *numeroChanson > 4 || *niveauDifficulte < 1 || *niveauDifficulte > 4) { - // //chanson et difficulte par defaut - // *numeroChanson = 1; - // *niveauDifficulte = 1; - // } - // cout << "Chanson choisie : " << listeChansons[*numeroChanson - 1] << endl; - // cout << "Niveau de difficulte : " << listeDifficultes[*niveauDifficulte - 1] << "\n\n"; - // return true; //debuter le jeu - // break; - } - - if (!wantToReturn) - { - madeADecision = true; - retour = true; - } - - break; - - case 2: - system("CLS"); - cout << "A bientot, KEEP ON ROCKING!!" << endl; - madeADecision = true; - retour = false; //quitter le jeu - break; - - default: - break; - } - } - return retour; - } - - //Fonction qui presente la premiere section du menu - int displayMenu() { - system("CLS"); - int choix; - cout << "----------------------------------------------------------------------" << endl; - cout << "\t\tMENU GUITAR HERO DEVELISH RELLISH" << endl; - cout << "----------------------------------------------------------------------\n" << endl; - cout << " 1. Debuter le jeu " << endl; - //cout << " 2. Informations " << endl; - cout << " 2. Quitter le jeu \n" << endl; - cout << "Choisissez une option : "; - cin >> choix; - while (choix < 1 || choix > 3) { - cout << "Choix non valide. Veuillez choisir une option valide" << endl; - cin >> choix; - } - return choix; - } \ No newline at end of file +} + +bool CompareIndividualButton(bool wantedValue, int buttonState) +{ + return wantedValue == buttonState; +} + +int GetLedState() +{ + if (IsInPowerup) + { + LedState++; + if (LedState > 10) + { + LedState = 0; + } + } + else + { + if (NotesCorrectStreak % 1 == 0 && StreakWhenLastSend < NotesCorrectStreak) + { + LedState++; + StreakWhenLastSend = NotesCorrectStreak; + } + if (LedState > 10) + { + LedState = 10; + } + if (BargraphNeedReset) + { + LedState = 0; + BargraphNeedReset = false; + StreakWhenLastSend = 0; + } + } + return LedState; +} + +//bool MenuInitialisation(int& numeroChanson, int& niveauDifficulte, vector repo) { +// //display du Menu +// int repo_size = repo.size(); +// int choix = displayMenu(); +// switch (choix) +// { +// case 1: +// //choisir chanson +// system("CLS"); +// cout << "----------------------------------------------------------------------" << endl; +// cout << "\t\t\tMENU CHOIX DE CHANSON" << endl; +// cout << "----------------------------------------------------------------------\n" << endl; +// cout << " On devra faire un display des chansons disponibles...\n"; +// /* +// for (int i = 0; i < repertoire.size; i++){ +// cout << i+1 << ". " << repertoire[i].song.getTitle() << endl; +// } +// */ +// for (int i = 0; i < repo_size + 1; i++) { +// if (i == repo.size()) +// { +// cout << i + 1 << ". Retour" << endl; +// } +// else { +// cout << i + 1 << ". " << repo[i].getTitle() << endl << " par " << repo[i].getArtist() << endl; +// } +// } +// cout << "\nChoisissez une chanson : "; +// cin >> numeroChanson; +// while (numeroChanson < 1 || numeroChanson > repo.size() + 1) { +// cout << "Entree non valide. Veuillez entrer un numero de chanson valide" << endl; +// cin >> numeroChanson; +// } +// if (numeroChanson == repo.size()) +// { +// MenuInitialisation(numeroChanson, niveauDifficulte, repo); //retourne au display du menu +// } +// numeroChanson -= 1; + +// //choisir niveau de difficulté +// system("CLS"); +// cout << "----------------------------------------------------------------------" << endl; +// cout << "\t\t\tMENU NIVEAU DE DIFFICULTE" << endl; +// cout << "----------------------------------------------------------------------\n" << endl; + +// cout << "1. Easy" << endl; +// cout << "2. Medium" << endl; +// cout << "3. Hard" << endl; +// cout << "4. Expert" << endl; + +// cout << "\nChoisissez le niveau de difficulte : "; +// cin >> niveauDifficulte; +// while (niveauDifficulte < 0 || niveauDifficulte > 4) { +// cout << "Entree non valide. Veuillez entrer un niveau de difficulte valide" << endl; +// cin >> niveauDifficulte; +// } +// MenuInitialisation(numeroChanson, niveauDifficulte, repo); //retourne au display du menu +// niveauDifficulte = -1; +// return true; +// break; +// //case 3: +// // system("CLS"); +// // cout << "Le jeu va debuter...!!\n" << endl; +// // if (*numeroChanson < 1 || *numeroChanson > 4 || *niveauDifficulte < 1 || *niveauDifficulte > 4) { +// // //chanson et difficulte par defaut +// // *numeroChanson = 1; +// // *niveauDifficulte = 1; +// // } +// // cout << "Chanson choisie : " << listeChansons[*numeroChanson - 1] << endl; +// // cout << "Niveau de difficulte : " << listeDifficultes[*niveauDifficulte - 1] << "\n\n"; +// // return true; //debuter le jeu +// // break; + +// case 2: +// system("CLS"); +// cout << "A bientot, KEEP ON ROCKING!!" << endl; +// return false; //quitter le jeu +// break; + +// default: +// break; +// } +//} + +bool MenuInitialisation(int& numeroChanson, int& niveauDifficulte, vector repo) { + //display du Menu + int repo_size = repo.size(); + int choix = 0; + bool madeADecision = false; + bool retour = false; + bool wantToReturn = false; + + while (!madeADecision) + { + choix = displayMenu(); + switch (choix) + { + case 1: + wantToReturn = false; + //choisir chanson + system("CLS"); + cout << "----------------------------------------------------------------------" << endl; + cout << "\t\t\tMENU CHOIX DE CHANSON" << endl; + cout << "----------------------------------------------------------------------\n" << endl; + //cout << " On devra faire un display des chansons disponibles...\n"; + /* + for (int i = 0; i < repertoire.size; i++){ + cout << i+1 << ". " << repertoire[i].song.getTitle() << endl; + } + */ + for (int i = 0; i < repo_size + 1; i++) { + if (i == repo.size()) + { + cout << i + 1 << ". Retour" << endl; + } + else { + cout << i + 1 << ". " << repo[i].getTitle() << " par " << repo[i].getArtist() << endl; + } + } + cout << "\nChoisissez une chanson : "; + cin >> numeroChanson; + while (numeroChanson < 1 || numeroChanson > repo.size() + 1) { + cout << "Entree non valide. Veuillez entrer un numero de chanson valide" << endl; + cin >> numeroChanson; + } + numeroChanson -= 1; + if (numeroChanson == repo.size()) + { + wantToReturn = true; + } + + + if (!wantToReturn) + { + //choisir niveau de difficulté + system("CLS"); + cout << "----------------------------------------------------------------------" << endl; + cout << "\t\t\tMENU NIVEAU DE DIFFICULTE" << endl; + cout << "----------------------------------------------------------------------\n" << endl; + + cout << "1. Easy" << endl; + cout << "2. Medium" << endl; + cout << "3. Hard" << endl; + cout << "4. Expert" << endl; + cout << "5. Retour" << endl; + + cout << "\nChoisissez le niveau de difficulte : "; + cin >> niveauDifficulte; + while (niveauDifficulte < 0 || niveauDifficulte > 5) { + cout << "Entree non valide. Veuillez entrer un niveau de difficulte valide" << endl; + cin >> niveauDifficulte; + } + + if (niveauDifficulte == 5) + { + wantToReturn = true; + } + + niveauDifficulte -= 1; + //case 3: + // system("CLS"); + // cout << "Le jeu va debuter...!!\n" << endl; + // if (*numeroChanson < 1 || *numeroChanson > 4 || *niveauDifficulte < 1 || *niveauDifficulte > 4) { + // //chanson et difficulte par defaut + // *numeroChanson = 1; + // *niveauDifficulte = 1; + // } + // cout << "Chanson choisie : " << listeChansons[*numeroChanson - 1] << endl; + // cout << "Niveau de difficulte : " << listeDifficultes[*niveauDifficulte - 1] << "\n\n"; + // return true; //debuter le jeu + // break; + } + + if (!wantToReturn) + { + madeADecision = true; + retour = true; + } + + break; + + case 2: + system("CLS"); + cout << "A bientot, KEEP ON ROCKING!!" << endl; + madeADecision = true; + retour = false; //quitter le jeu + break; + + default: + break; + } + } + return retour; +} + +//Fonction qui presente la premiere section du menu +int displayMenu() { + system("CLS"); + int choix; + cout << "----------------------------------------------------------------------" << endl; + cout << "\t\tMENU GUITAR HERO DEVELISH RELLISH" << endl; + cout << "----------------------------------------------------------------------\n" << endl; + cout << " 1. Debuter le jeu " << endl; + //cout << " 2. Informations " << endl; + cout << " 2. Quitter le jeu \n" << endl; + cout << "Choisissez une option : "; + cin >> choix; + while (choix < 1 || choix > 3) { + cout << "Choix non valide. Veuillez choisir une option valide" << endl; + cin >> choix; + } + return choix; +} + -- cgit v1.2.3