Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <time.h>
- #include <math.h>
- #include <windows.h>
- #include <string>
- using namespace std;
- unsigned long long beg, ended, diff; // DEKLARACJA ZMIENNYCH===============================================
- string najw[37];
- int btime[37];
- int q=1,i;
- unsigned long long Losuj(int trudP, int trudK, int pot); // DEKLARACJA FUNKCJI============================================================
- int Konmin(int sekundy);
- int Konsec(int sekundy);
- int IsBest(int time, int dlug, int tryb, int poz);
- void Read();
- void Start();
- void Stop();
- int main() // MAIN============MAIN=================================================
- {
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hConsole, 14);
- int poz, tlp, tlk, tryb; // DEKLARACJA ZMIENNYCH===============================================
- unsigned long long wynik, odp, a, b;
- bool trwa;
- /*
- for (int q = 1; q <= 35; q++)
- {
- cout<<najw[q]<<endl;
- }*/
- srand(time(NULL));
- while(1){
- trwa = true;
- cout<<"Wybierz tryb: "<<endl<<"1. Potegowanie"<<endl<<"2. Mnozenie"<<endl;
- cin>>tryb;
- // Read();
- cout<<"Wybierz ilosc cyfr (1-5): "<<endl;
- cin>>i;
- Read();
- cout<<"Wybierz poziom trydnosci od 1 do 3"<<endl;
- cin>>poz;
- switch(poz)
- {
- case 1:
- tlp = 5;
- tlk = 1;
- break;
- case 2:
- tlp = 4;
- tlk = 3;
- break;
- case 3:
- tlp = 4;
- tlk = 6;
- break;
- default:
- cout<<"Nie ma takiej opcji!"<<endl;
- break;
- }
- a = Losuj(tlp, tlk, i);
- wynik = a * a;
- b=a;
- if (tryb == 2)
- {
- b = Losuj(tlp, tlk, i);
- wynik = a * b;
- }
- cout<<a<<" X "<<b<<" = ";
- Start();
- while(trwa)
- {
- cin>>odp;
- if(odp == wynik)
- {
- Stop();
- trwa=false;
- IsBest(diff, i, tryb, poz);
- }
- else
- {
- cout<<"ZLE!"<<endl;
- }
- }
- }
- return 0;
- }
- int Konsec(int sekundy) CIALA FUNKCJI======================================================================
- {
- return sekundy - 60 * (sekundy/60);
- }
- int Konmin(int sekundy)
- {
- return sekundy/60;
- }
- unsigned long long Losuj(int trudP, int trudK, int pot)
- {
- unsigned long long toret = 0, ilecyfr;
- pot--;
- for(pot; pot>0; pot)
- {
- ilecyfr = pow(10, pot);
- if ( ilecyfr%2 != 0)
- ilecyfr++;
- toret = toret + (rand()%trudP + trudK) * ilecyfr;
- pot--;
- }
- toret = toret + rand()%trudP + trudK;
- return toret;
- }
- void Read()
- {
- ifstream score("score.txt");
- if (score.is_open())
- {
- q=1;
- while( getline (score,najw[q]))
- {
- // cout<<najw[q]<<endl;
- if(q<=35)
- q++;
- }
- score.close();
- }
- else
- {
- cout<<"error"<<endl;
- }
- for (int u=1; u<37; u)
- {
- btime[u] = atoi(najw[u].c_str());
- u++;
- }
- }
- int IsBest(int time, int dlug, int tryb, int poz)
- {
- switch (poz)
- {
- case 2:
- dlug=dlug+5;
- break;
- case 3:
- dlug=dlug+10;
- break;
- }
- if (tryb == 2)
- dlug = dlug + 15;
- if(time<btime[dlug])
- {
- cout<<"POBILES REKORD!"<<endl;
- if(btime[dlug]!= 10000)
- {
- cout<<"Poprzedni rekord wynosil "<<Konmin(btime[dlug])<<" min "<<Konsec(btime[dlug])<<" s"<<endl<<endl;
- }
- btime[dlug] = time;
- ofstream dozapisu ("score.txt");
- if (dozapisu.is_open())
- {
- for (int q = 1; q <= 35; q++)
- {
- dozapisu << btime[q]<<endl;
- }
- }
- else cout << "Unable to open file";
- dozapisu.close();
- }
- }
- void Start()
- {
- // cout<<"START!!"<<endl;
- beg = time(NULL);
- }
- void Stop()
- {
- cout<<endl<<"Udalo ci sie!"<<endl;
- ended = time(NULL);
- diff = ended - beg;
- cout<<"Twoj czas wynosi: "<<Konmin(diff)<<" minut i "<<Konsec(diff)<<" sekund(y)!"<<endl<<endl;
- }
Add Comment
Please, Sign In to add comment