#include #include #include #include #include #include #include using namespace std; vector pytanie, odpA, odpB, odpC; vector poprawna; void loadQuestions(){ fstream pytania; string loadString; pytania.open("pytania.txt", ios::in); do{ getline(pytania, loadString); pytanie.push_back(loadString); getline(pytania, loadString); poprawna.push_back(loadString); getline(pytania, loadString); odpA.push_back(loadString); getline(pytania, loadString); odpB.push_back(loadString); getline(pytania, loadString); odpC.push_back(loadString); }while(!pytania.eof()); pytania.close(); } void topPlayers(){ fstream topPlik; string loadString; int zamiennyInt; vector topName; vector topPoints; topPlik.open("top.txt", ios::in); do{ getline(topPlik, loadString); topName.push_back(loadString); getline(topPlik, loadString); stringstream geek(loadString); geek >> zamiennyInt; topPoints.push_back(zamiennyInt); }while(!topPlik.eof()); topPlik.close(); cout << " TOP 3 GRACZY" << endl; cout << "1) " << topName[0] << " > " << topPoints[0] << endl; cout << "2) " << topName[1] << " > " << topPoints[1] << endl; cout << "3) " << topName[2] << " > " << topPoints[2] << endl; } void updateTop(string newName, int newPoints){ fstream topPlik; vector topName; vector topPoints; string loadString; int zamiennyInt; topPlik.open("top.txt", ios::in); do{ getline(topPlik, loadString); topName.push_back(loadString); getline(topPlik, loadString); stringstream geek(loadString); geek >> zamiennyInt; topPoints.push_back(zamiennyInt); }while(!topPlik.eof()); topPlik.close(); if(newPoints>topPoints[0]){ topPoints[2] = topPoints[1]; topName[2] = topName[2]; topPoints[1] = topPoints[0]; topName[1] = topName[0]; topPoints[0] = newPoints; topName[0] = newName; }else if(newPoints>topPoints[1]){ topPoints[2] = topPoints[1]; topName[2] = topName[1]; topPoints[1] = newPoints; topName[1] = newName; }else if(newPoints>topPoints[2]){ topPoints[2] = newPoints; topName[2] = newName; } fstream topFile; topFile.open("top.txt", ios::out); topFile << topName[0] << endl << topPoints[0] << endl; topFile << topName[1] << endl << topPoints[1] << endl; topFile << topName[2] << endl << topPoints[2] << endl; topFile.close(); } string ToUpperCase(string s) { locale loc; string ret=""; for (string::size_type i=0; i> podane; podane=ToUpperCase(podane); if(podane=="AUTORZY"){ system("cls"); system("color 0A"); cout << " Tworcy" << endl << endl; cout << "> Damian Hajdas\n> Hubert Piotrowski" << endl; cin >> podane; }else if(podane=="TOP"){ topPlayers(); cin >> podane; }system("cls"); system("color 07"); }while(podane!="START"); system("color 07"); cout << "Podaj swoj nick" << endl; cin >> nick; do{ system("cls"); game = true; life=3; punkty=0; poprzednie=-1; do{ cout << "Twoje punkty: " << punkty << " ||| Zycia: " << life << endl << endl; los = random(pytanie.size()); --los; while(los==poprzednie){ los = random(pytanie.size()); --los; } cout << "\n" << pytanie[los] << endl; cout << "\nA) " << odpA[los] << "\nB) " << odpB[los] << "\nC) " << odpC[los] << endl; cout << "\nPodaj odpowiedz: \"A\", \"B\" lub \"C\""<< endl; cin >> podane; podane = ToUpperCase(podane); while(podane!="A"&&podane!="B"&&podane!="C"){ system("cls"); cout << "Twoje punkty: " << punkty << " | Zycia: " << life << endl; cout << "\n" << pytanie[los] << endl; cout << "\nA) " << odpA[los] << "\nB) " << odpB[los] << "\nC) " << odpC[los] << endl; cout << "\nNie rozpoznano odpowiedzi! Podaj ponownie: \"A\", \"B\" lub \"C\"" << endl; cin >> podane; podane = ToUpperCase(podane); } system("cls"); if(podane==poprawna[los]){ punkty++; poprzednie=los; }else{ cout << "Podano niepoprawna odpowiedz!" << endl; poprzednie=los; life--; } }while(life!=0); cout << "Przegrales!" << endl << "Czy chcesz zagrac ponownie? [T/n]" << endl; cin >> podane; podane = ToUpperCase(podane); while(podane!="T"&&podane!="N"){ system("cls"); cout << "Nie rozpoznano polecenia!\nCzy chcesz zagrac ponownie? [T/n]" << endl; cin >> podane; podane = ToUpperCase(podane); } if(podane=="N"){ game=false; } if(punkty>najwiecej){ najwiecej=punkty; } }while(game); system("cls"); updateTop(nick, najwiecej); cout << "Najwiecej zdobytych punktow w obecnej sesji: " << najwiecej << endl << "Zakonczono prace programu." << endl; // cout << pytanie.size() << endl << los; return 0; }