Advertisement
Guest User

cpp

a guest
Feb 2nd, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 19.95 KB | None | 0 0
  1. #include "Source.h"
  2. #include <conio.h>
  3. #include <iostream>
  4. #include <ctime>
  5. #include <string>
  6. #include <fstream>
  7. #include <istream>
  8. #include <sstream>
  9. #include <cstdlib>
  10. #include <windows.h>
  11.  
  12. using namespace std;
  13.  
  14. Virus** Global::virus = nullptr;
  15. User** Global::users = nullptr;
  16. int Global::virus_counter = 0;
  17. int Global::active_virus = 0;
  18. int Global::user_counter = 0;
  19. int Global::Userint = 0;
  20.  
  21. // operatory
  22.  
  23. ostream& operator<<(ostream &out, User **users)
  24. {
  25.     for (int i = 0; i < Global::user_counter; i++)
  26.     {
  27.         cout << "Numer uzytkownika: " << i << endl;
  28.         cout << "" << users[i]->getLogin() << endl;
  29.         cout << endl;
  30.     }
  31.     return out;
  32. }
  33.  
  34. istream& operator>>(istream& in, User* usr)
  35. {
  36.     string l, p;
  37.     cout<<"Wpisz login: "<<endl;
  38.     cin >> l;
  39.     cout<<"Wpisz haslo: "<<endl;
  40.     cin>>p;
  41.  
  42.     usr->setLogin(l);
  43.     usr->setPassword(p);
  44.  
  45.     return in;
  46. }
  47.  
  48. // konstruktor kopiujący
  49. Virus::Virus(Virus *virusC)
  50. {
  51.     this->type = virusC->getType();
  52.     this->name = virusC->getName();
  53.     this->size = virusC->getSize();
  54.     this->range = virusC->getRange();
  55.     this->power = new Power(virusC->power->spreadSpeed);
  56. }
  57. //
  58. //konstruktor z wartosciami domyslnymi
  59. Virus::Virus()
  60. {
  61.     power = new Power;
  62.     type = 1;
  63.     name = "Default";
  64.     size = 50;
  65.     range = 0;
  66. }
  67.  
  68. string& Virus::getName()
  69. {
  70.     return name;
  71. }
  72.  
  73. float Virus::getSize()
  74. {
  75.     return size;
  76. }
  77.  
  78. int Virus::getType()
  79. {
  80.     return type;
  81. }
  82.  
  83. float Virus::getRange()
  84. {
  85.     return range;
  86. }
  87.  
  88. void Virus::set(string n, float m)
  89. {
  90. }
  91.  
  92. void Virus::set(string n, float m, float e)
  93. {
  94. }
  95.  
  96. void Virus::set(string n, float m, float e, float u)
  97. {
  98. }
  99.  
  100. void DNA::EpidemicRate()
  101. {
  102.     range = size * (*power)->spreadSpeed; // przeciazona ->
  103.     cout << "Wirus zadziala w promieniu: " << (*power)->spreadSpeed <<"km."<< endl;
  104. }
  105.  
  106. void DNA::set(string n, float m)
  107. {
  108.     name = n;
  109.     size = m;
  110.     type = 1;
  111. }
  112.  
  113. float DNA::getMultiplier2()
  114. {
  115.     return 0;
  116. }
  117.  
  118. void DNA::view()
  119. {
  120.     cout << "Nazwa wirusa: " << getName() << endl;
  121.     cout << "Podaj rozmiar komorki wirusa (1-10): " << getSize() << endl;
  122.     cout << "Typ: wirus DNA" << endl;
  123. }
  124.  
  125. void RNA::EpidemicRate()
  126. {
  127.     range = size * (*power)->spreadSpeed * (multiplier*0.4);
  128.     cout << "Ten wirus wywoluje epidemie w zasiegu: " << range << "km." << endl;
  129. }
  130.  
  131. void RNA::set(string n, float m, float e)
  132. {
  133.     this->name = n;
  134.     this->size = m;
  135.     this->multiplier = e;
  136.     this->type = 2;
  137. }
  138.  
  139. float RNA::getMultiplier()
  140. {
  141.     return multiplier;
  142. }
  143.  
  144. float RNA::getMultiplier2()
  145. {
  146.     return 0;
  147. }
  148.  
  149. void RNA::view()
  150. {
  151.     cout << "Nazwa wirusa: " << getName() << endl;
  152.     cout << "Podaj rozmiar komorki wirusa (1-10): " << getSize() << endl;
  153.     cout << "Podaj mnoznik: " << getMultiplier() << endl;
  154.     cout << "Typ: wirus RNA" << endl;
  155. }
  156.  
  157. float Hybrid::getZone()
  158. {
  159.     return zone;
  160. }
  161.  
  162. float Hybrid::getEnvirons()
  163. {
  164.     return environs;
  165. }
  166.  
  167. void Hybrid::EpidemicRate()
  168. {
  169.     range = size * (*power)->spreadSpeed;
  170.     zone = (multiplier * multiplier2) * (*power)->spreadSpeed;
  171.     environs = size * (*power)->spreadSpeed * (multiplier*0.4);
  172.  
  173.     cout << "Wirus zadziała w promieniu: " << range << "km." << endl;
  174.     cout << "Skazenie utrzyma sie w promieniu: " << zone << "km." << endl;
  175.     cout << "Fauna i flora skazona w promienu: " << environs << "km."<< endl;
  176. }
  177.  
  178. void Hybrid::set(string n, float m, float e, float u)
  179. {
  180.     name = n;
  181.     size = m;
  182.     multiplier = e;
  183.     multiplier2 = u;
  184.     type = 3;
  185. }
  186.  
  187. float Hybrid::getMultiplier()
  188. {
  189.     return type;
  190. }
  191.  
  192. float Hybrid::getMultiplier2()
  193. {
  194.     return multiplier2;
  195. }
  196.  
  197. void Hybrid::view()
  198. {
  199.     cout << "Nazwa: " << getName() << endl;
  200.     cout << "Podaj rozmiar komorki wirusa (1-10): " << getSize() << endl;
  201.     cout << "Mnoznik: " << getMultiplier() << endl;
  202.     cout << "Podaj mnoznik mutagenu: " << getMultiplier2() << endl;
  203.     cout << "Typ: Hybryda" << endl;
  204. }
  205.  
  206. void Global::viewallViruses()
  207. {
  208.     int x;
  209.     for (int i = 0; i < virus_counter; i++)
  210.     {
  211.         cout << "Numer: " << i << endl;
  212.         cout << "Nazwa: " << virus[i]->getName() << endl;
  213.         x = virus[i]->getType();
  214.         switch (x)
  215.         {
  216.         case 1:
  217.             cout << "Typ: DNA." << endl;
  218.             break;
  219.         case 2:
  220.             cout << "Typ: RNA." << endl;
  221.             break;
  222.         case 3:
  223.             cout << "Typ: Hybryda." << endl;
  224.             break;
  225.         }
  226.         cout << endl;
  227.     }
  228. }
  229.  
  230. //++GLOBAL==
  231. //dynamiczne zarządzanie pamięcią
  232. bool Global::insertViruses(int index, int type)
  233. {
  234.     if (index != 0)
  235.     {
  236.         if (index < 0 || virus_counter <= index)
  237.         {
  238.             cout << "Nieprawidlowy indeks" << endl;
  239.             _getch();
  240.             return false;
  241.         }
  242.     }
  243.     Virus **new_virus = new Virus*[virus_counter + 1];
  244.     for (int i = 0; i < virus_counter + 1; i++)
  245.     {
  246.         if (i < index)
  247.             new_virus[i] = virus[i];
  248.         else if (i == index)
  249.             new_virus[i] = VirusCreator::createVirus(type);
  250.         else if (i > index)
  251.             new_virus[i] = virus[i - 1];
  252.     }
  253.     delete[] virus;
  254.     virus = new_virus;
  255.     virus_counter++;
  256.     return true;
  257. }
  258.  
  259. Virus* Global::AddViruses(int type)
  260. {
  261.     Virus **new_virus = new Virus*[virus_counter + 1];
  262.     for (int i = 0; i < virus_counter; i++)
  263.     {
  264.         new_virus[i] = virus[i];
  265.     }
  266.     Virus *new1 = VirusCreator::createVirus(type);
  267.     new_virus[virus_counter] = new1;
  268.     delete[] virus;
  269.     virus = new_virus;
  270.     virus_counter++;
  271.     return new1;
  272. }
  273.  
  274. void Global::DeleteViruses(int index)
  275. {
  276.     int x;
  277.     Virus **new_virus = new Virus*[virus_counter - 1];
  278.  
  279.     int j = 0;
  280.     for (int i = 0; i < virus_counter; i++)
  281.     {
  282.         if (i != index)
  283.         {
  284.             new_virus[j++] = virus[i];
  285.         }
  286.         else
  287.             delete virus[i];
  288.     }
  289.    
  290.     delete[] virus;
  291.     virus = new_virus;
  292.     virus_counter--;
  293. }
  294.  
  295. void Global::viewUsers()
  296. {
  297.     for (int i = 0; i < user_counter; i++)
  298.     {
  299.         cout << "Numer uzytkownika: " << i << endl;
  300.         cout << "" << users[i]->getLogin() << endl;
  301.         cout << endl;
  302.     }
  303. }
  304. //dodawanie użytkowników
  305. void Global::AddUser()
  306. {
  307.     User **new_user = new User*[user_counter + 1];
  308.     for (int i = 0; i < user_counter; i++)
  309.     {
  310.         new_user[i] = users[i];
  311.     }
  312.     new_user[user_counter] = new User;
  313.     delete[] virus;
  314.     users = new_user;
  315.     user_counter++;
  316. }
  317.  
  318. void Global::DeleteUser(int index)
  319. {
  320.     int x;
  321.     User **new_user = new User*[user_counter - 1];
  322.  
  323.     int j = 0;
  324.     for (int i = 0; i < user_counter; i++)
  325.     {
  326.         if (i != index)
  327.         {
  328.             new_user[j++] = users[i];
  329.         }
  330.         else
  331.             delete users[i];
  332.     }
  333.  
  334.     delete[] users;
  335.     users = new_user;
  336.     user_counter--;
  337.     Global::Userint--;
  338. }
  339.  
  340. //usuwanie tablic wskaźników
  341. void Global::destroyVirusesArr()
  342. {
  343.     for (int i = 0; i < virus_counter; i++)
  344.     {
  345.         delete virus[i];
  346.     }
  347.     delete[] virus;
  348. }
  349.  
  350. void Global::destoryUsers()
  351. {
  352.     for (int i = 0; i < user_counter; i++)
  353.     {
  354.         delete users[i];
  355.     }
  356.     delete[] users;
  357. }
  358.  
  359.  
  360. //wczytywanie z pliku
  361. void Global::loadViruses()
  362. {
  363.  
  364.     string name, size, i, multiplier, type, mutagen;
  365.     int Ii, Isize, Imultiplier, Itype, Imutagen;
  366.  
  367.     ifstream file("viruses.txt");
  368.     getline(file, i);
  369.     Ii = atoi(i.c_str());
  370.  
  371.     for (int i = 0; i < Ii; i++)
  372.     {
  373.         getline(file, type);
  374.         Itype = atoi(type.c_str());
  375.  
  376.         switch (Itype)
  377.         {
  378.         case 1:
  379.         {
  380.             getline(file, name, ';') && getline(file, size);
  381.             Isize = atoi(size.c_str());
  382.             AddViruses(1);
  383.             virus[i]->set(name, Isize);
  384.         }
  385.         break;
  386.         case 2:
  387.         {
  388.             getline(file, name, ';') && getline(file, size, ';') && getline(file, multiplier);
  389.             Isize = atoi(size.c_str());
  390.             Imultiplier = atoi(multiplier.c_str());
  391.             AddViruses(2);
  392.             virus[i]->set(name, Isize, Imultiplier);
  393.         }
  394.         break;
  395.         case 3:
  396.         {
  397.             getline(file, name, ';') && getline(file, size, ';') && getline(file, multiplier, ';') && getline(file, mutagen);
  398.             Isize = atoi(size.c_str());
  399.             Imultiplier = atoi(multiplier.c_str());
  400.             Imutagen = atoi(mutagen.c_str());
  401.             AddViruses(3);
  402.             virus[i]->set(name, Isize, Imultiplier, Imutagen);
  403.         }
  404.         break;
  405.         }
  406.  
  407.     }
  408.     file.close();
  409. }
  410. //zapisywanie do pliku
  411. void Global::saveViruses()
  412. {
  413.     int type;
  414.     ofstream file("viruses.txt");
  415.     file << virus_counter << endl;
  416.     for (int i = 0; i < virus_counter; i++)
  417.     {
  418.         type=virus[i]->getType();
  419.         file << type << endl;
  420.  
  421.         switch (type)
  422.         {
  423.         case 1:
  424.         {
  425.             file << virus[i]->getName() << ";" << virus[i]->getSize() << endl;
  426.         }
  427.         break;
  428.         case 2:
  429.         {
  430.             file << virus[i]->getName() << ";" << virus[i]->getSize() << ";" << virus[i]->getMultiplier() << endl;
  431.         }
  432.         break;
  433.         case 3:
  434.         {
  435.             file << virus[i]->getName() << ";" << virus[i]->getSize() << ";" << virus[i]->getMultiplier() << ";" << virus[i]->getMultiplier2() << endl;
  436.         }
  437.         break;
  438.         }
  439.     }
  440.     file.close();
  441.  
  442. }
  443. //zapisywanie do pliku
  444. void Global::saveUsers()
  445. {
  446.     ofstream file("users.txt");
  447.     file << user_counter << endl;
  448.     for (int i = 0; i < user_counter; i++)
  449.     {
  450.         file << users[i]->getLogin() << ";" << users[i]->getPassword() << endl;
  451.     }
  452.  
  453. }
  454. //wczytywanie z pliku
  455. void Global::loadUsers()
  456. {
  457.     string login, pass, i;
  458.     int Ii;
  459.  
  460.     ifstream file("users.txt");
  461.     getline(file, i);
  462.     Ii = atoi(i.c_str());
  463.  
  464.     for (int i = 0; i < Ii; i++)
  465.     {
  466.         getline(file, login, ';') && getline(file, pass);
  467.        
  468.         AddUser();
  469.         users[i]->setLogin(login);
  470.         users[i]->setPassword(pass);
  471.     }
  472.  
  473. }
  474.  
  475. void Global::log_in()
  476. {
  477.     char x;
  478.     int i;
  479.     bool l;
  480.     string log, pass;
  481.     cout << endl << endl << endl;
  482.     do
  483.     {
  484.         system("cls");
  485.         cout << "Logowanie (Z) / Nowy Gracz (R)" << endl;
  486.  
  487.     x =_getch();
  488.  
  489.     switch(x)
  490.     {
  491.    
  492.     case 'z':
  493.     {
  494.        
  495.             system("cls");
  496.             cout << "Podaj Login: " << endl;
  497.             cout << "";
  498.             cin>>log;
  499.             i = findLog(log);
  500.             Global::Userint = i;
  501.             if (i != -1)
  502.             {
  503.                 cout << "Podaj Haslo: " << endl;
  504.                 cout << "";
  505.                 cin >> pass;
  506.  
  507.                 if (users[i]->checkPassword(pass) == true)
  508.                     return;
  509.                 else
  510.                 {
  511.                     cout << "Zle haslo!" << endl;
  512.                     cout << "Nacisnij dowolny klawisz, aby kontynuowac." << endl;
  513.                     _getch();
  514.                 }
  515.             }
  516.             else
  517.             {
  518.                 cout << "Gracz o podanym loginie nie istnieje!" << endl;
  519.                 cout << "Nacisnij dowolny klawisz aby kontynuowac." << endl;
  520.                 _getch();
  521.             }
  522.                
  523.  
  524.     }
  525.     break;
  526.  
  527.     case 'r':
  528.     {
  529.         registration(); // wewnatrz tej metody przeciazony >>
  530.         Global::Userint = user_counter-1;
  531.         saveUsers();
  532.         cout << "Tworzenie gracza zakonczone. Mozna sie logowac." << endl;
  533.         cout << "Nacisnij dowolny przycisk, aby kontynuowac." << endl;
  534.         _getch();
  535.  
  536.     }
  537.     break;
  538.     }
  539.     } while (pass != "e");
  540. }
  541.  
  542. void Global::registration()
  543. {
  544.     /*string login, pass;
  545.     cout << "Podaj nowy login: " << endl;
  546.     cout << "";
  547.     cin >> login;
  548.     cout << "Podaj nowe haslo: " << endl;
  549.     cout << "";
  550.     cin >> pass;*/
  551.  
  552.     AddUser();
  553.     cin>>users[user_counter-1];
  554.     //users[user_counter - 1]->setLogin(login);
  555.     //users[user_counter - 1]->setPassword(pass);
  556. }
  557.  
  558.  
  559. //++MENU++
  560. void Global::menu()
  561. {
  562.     char control;
  563.     int type, x, id;
  564.     //int idC = 0;
  565.     string nazwa;
  566.     Virus* oneVirus;
  567.     float size, mnoznik, mutagen, factor, multiplier;
  568.     for (;;)
  569.     {
  570.  
  571.         system("cls");
  572.         cout << "Gracz: " << users[Userint]->getLogin() << endl<<endl;
  573.         cout << "1 : Obliczanie zasiegu epidemii" << endl;
  574.         cout << "2 : Wirusy" << endl;
  575.         cout << "3 : Baza graczy" << endl;
  576.         cout << "4 : Wyjscie" << endl;
  577.  
  578.         control = _getch();
  579.  
  580.         switch (control)
  581.         {
  582.         case '1':
  583.         {
  584.             if (virus_counter == 0)
  585.             {
  586.                 cout << "Nie ma jeszcze zadnych wirusow!" << endl;
  587.                 _getch();
  588.                 break;
  589.             }
  590.             do
  591.             {
  592.                 system("cls");
  593.                 cout << "Gracz: " << users[Userint]->getLogin() << endl << endl;
  594.                 cout << "1 : wybierz wirus" << endl;
  595.                 cout << "2 : aby obliczyc zniszczenia" << endl;
  596.                 cout << "3 : aby wrocic" << endl;
  597.                 // wywalone wyswietlanie wspolczynnika
  598.                 cout << "Aktualnie wybrany wirus: " << endl << endl;
  599.                 virus[Global::active_virus]->view(); // wyciek pamięci1
  600.  
  601.                 x = _getch();
  602.  
  603.  
  604.                 switch (x)
  605.                 {
  606.                 case '1':
  607.                 {
  608.                     system("cls");
  609.                     cout << "Gracz: " << users[Userint]->getLogin() << endl << endl;
  610.                     if (active_virus >= 0)
  611.                         Global::viewallViruses();
  612.                     else
  613.                         cout << "Brak dostepnych wirusow." << endl;
  614.                     cout << "=========================================" << endl;
  615.                     cout << "Podaj numer wirusa: " << endl;
  616.                     cin >> active_virus;
  617.                     if ((active_virus > virus_counter) || (active_virus < 0))
  618.                     {
  619.                         cout << "Nie ma takiego wirusa." << endl;
  620.                         active_virus = 0;
  621.                         Sleep(500);
  622.                         break;
  623.                     }
  624.                
  625.                 }
  626.                 break;
  627.                 // w tym miejscu wykorzystujemy polimorfizm
  628.                 case '2':
  629.                 {
  630.                     system("cls");
  631.                     cout << "Gracz: " << users[Userint]->getLogin() << endl << endl;
  632.                     virus[active_virus]->EpidemicRate();
  633.                     cout << endl << "Nacisnij dowolny przycisk, aby kontynuowac." << endl;
  634.                     _getch();
  635.                 }
  636.                 break;
  637.                 case '3':
  638.                 {
  639.  
  640.                 }
  641.                 break;
  642.                 }
  643.  
  644.             }while(x != '3');
  645.         }
  646.         break;
  647.  
  648.         case '2': // dynamiczne zarządzanie pamięcią
  649.         {
  650.             do{
  651.  
  652.             system("cls");
  653.             cout << "Zalogowano jako: " <<  (*users[Userint])() << endl << endl; // przeciazony ()
  654.             cout << "Lista istniejacych wirusow: " << endl;
  655.             Global::viewallViruses();
  656.  
  657.             cout << "n - stworz nowy wirus" << endl;
  658.             cout << "u - usun wirus" << endl;
  659.             cout << "i - insert " << endl;
  660.             cout << "b - powrot" << endl;
  661.             cout << "l - statystyki wirusa" << endl;
  662.  
  663.             x =_getch();
  664.  
  665.             switch (x)
  666.             {
  667.             case 'n':
  668.             {
  669.                 cout << endl;
  670.                 cout << "1: DNA" << endl;
  671.                 cout << "2: RNA" << endl;
  672.                 cout << "3: Hybryda" << endl;
  673.                 cout << "Podaj typ wirusa: " << endl;
  674.                 type =_getch();
  675.  
  676.                 switch (type)
  677.                 {
  678.                 case '1':
  679.                 {
  680.                     oneVirus = Global::AddViruses(1);
  681.                     cout << "Podaj nazwe: " << endl;
  682.                     cin >> nazwa;
  683.                     cout << "Podaj rozmiar komorki wirusa (1-10): " << endl;
  684.                     cin >> size;
  685.                     virus[virus_counter - 1]->set(nazwa, size);
  686.                     cout << "Parametry dodanego wirusa" << endl;
  687.                     // podsumowanie parametrow wirusa ()
  688.                     for (int i = 0; i < 3; i++)
  689.                     {
  690.                         cout << (*virus[virus_counter - 1])[i]; // przeciazony []
  691.                         cout << endl;
  692.                     }
  693.                     (*oneVirus) = (*oneVirus); // przeciazony =
  694.                     _getch();
  695.                 }
  696.                 break;
  697.                 case '2':
  698.                 {
  699.                     oneVirus = Global::AddViruses(2);
  700.                     cout << "Podaj nazwe: " << endl;
  701.                     cout << "";
  702.                     cin >> nazwa;
  703.                     cout << "Podaj rozmiar komorki wirusa (1-10): " << endl;
  704.                     cout << "";
  705.                     cin >> size;
  706.                     cout << "Podaj mnoznik: " << endl;
  707.                     cout << "";
  708.                     cin >> multiplier;
  709.                     virus[virus_counter - 1]->set(nazwa, size, multiplier);
  710.                     if (virus_counter > 1)
  711.                     {
  712.                         // sprawdza element przed dodanym elementem i nowododany element
  713.                         if ((*Global::virus[virus_counter - 2]) - (*oneVirus)) // przeciazony -
  714.                             cout << "Wirus na poprzedniej pozycji ma mniejszy rozmiar";
  715.                         else
  716.                             cout << "Wirus na poprzedniej pozycji ma wiekszy rozmiar";
  717.                         _getch();
  718.                     }
  719.                 }
  720.                 break;
  721.                 case '3':
  722.                 {
  723.                     Global::AddViruses(3);
  724.                     cout << "Podaj nazwe: " << endl;
  725.                     cin >> nazwa;
  726.                     cout << "Podaj rozmiar komorki wirusa (1-10): " << endl;
  727.                     cin >> size;
  728.                     cout << "Podaj mnoznik: " << endl;
  729.                     cin >> mnoznik;
  730.                     cout << "Podaj mnoznik mutagenu: " << endl;
  731.                     cin >> mutagen;
  732.                     virus[virus_counter - 1]->set(nazwa, size, mnoznik, mutagen);
  733.                     if (virus_counter > 1)
  734.                     {
  735.                         // sprawdza element przed dodanym elementem i nowododany element
  736.                         if ((*Global::virus[virus_counter - 2]) + (*oneVirus)) // przeciazony +
  737.                             cout << "Wirus na poprzedniej pozycji ma wiekszy zasieg";
  738.                         else
  739.                             cout << "Wirus na poprzedniej pozycji ma mniejszy zasieg";
  740.                         _getch();
  741.                     }
  742.                 }
  743.                 break;
  744.  
  745.                 default:
  746.                 {
  747.                     cout << "brak opcji" << endl;
  748.                     Sleep(700);
  749.                 }
  750.                 } //type
  751.             }
  752.             break;
  753.             case 'l':
  754.             {
  755.                 cout << "Podaj numer wirusa: " << endl;
  756.                 cout << "";
  757.                 cin >> id;
  758.                 if ((virus_counter == 0) || (id >= virus_counter) || (id < 0))
  759.                 {
  760.                     cout << "Nie ma takiego wirusa." << endl;
  761.                     active_virus = 0;
  762.                     Sleep(500);
  763.                     break;
  764.                 }
  765.                 system("cls");
  766.                 //cout << "Zalogowano jako: " << users[Userint]->getLogin() << endl << endl;
  767.                 cout << "Zalogowano jako: " << (*users[Userint])() << endl << endl;
  768.                 virus[id]->view();
  769.                 cout << endl;
  770.                 cout << "Nacisnij dowolny przycisk, aby kontynuowac." << endl;
  771.                 _getch();
  772.             }
  773.             break;
  774.             case 'u':
  775.             {
  776.                 cout << "Podaj numer wirusa: " << endl;
  777.                 cin >> id;
  778.                 if ((virus_counter == 0) || (id >= virus_counter) || (id < 0))
  779.                 {
  780.                     cout << "Nie ma takiego wirusa." << endl;
  781.                     active_virus = 0;
  782.                     Sleep(500);
  783.                     break;
  784.                 }
  785.                 DeleteViruses(id);
  786.             }
  787.             break;
  788.             case 'i':
  789.             {
  790.                 cout << "Podaj numer wirusa: " << endl;
  791.                 cin >> id;
  792.  
  793.                 cout << "1: DNA" << endl;
  794.                 cout << "2: RNA" << endl;
  795.                 cout << "3: Hybryda" << endl;
  796.                 cout << "Podaj typ wirusa: " << endl;
  797.                 type =_getch();
  798.                 system("cls");
  799.                 cout << "Gracz: " << users[Userint]->getLogin() << endl << endl;
  800.                 switch (type)
  801.                 {
  802.                 case '1':
  803.                 {
  804.                     if (Global::insertViruses(id, 1)) // obsluzona wewnatrz weryfikacja wprowadzonego id
  805.                     {
  806.                         cout << "Podaj nazwe wirusa: " << endl;
  807.                         cin >> nazwa;
  808.                         cout << "Podaj rozmiar komorki wirusa (1-10): " << endl;
  809.                         cin >> size;
  810.                         virus[id]->set(nazwa, size);
  811.                     }
  812.                 }
  813.                 break;
  814.                 case '2':
  815.                 {
  816.                     if (Global::insertViruses(id, 2))
  817.                     {
  818.                         cout << "Podaj nazwe wirusa: " << endl;
  819.                         cout << "";
  820.                         cin >> nazwa;
  821.                         cout << "Podaj rozmiar komorki wirusa (1-10): " << endl;
  822.                         cout << "";
  823.                         cin >> size;
  824.                         cout << "Podaj mnoznik: " << endl;
  825.                         cout << "";
  826.                         cin >> mnoznik;
  827.                         virus[id]->set(nazwa, size, mnoznik);
  828.                     }
  829.                 }
  830.                 break;
  831.                 case '3':
  832.                 {
  833.                     if (Global::insertViruses(id, 3))
  834.                     {
  835.                         cout << "Podaj nazwe wirusa: " << endl;
  836.                         cin >> nazwa;
  837.                         cout << "Podaj rozmiar komorki wirusa (1-10): " << endl;
  838.                         cin >> size;
  839.                         cout << "Podaj mnoznik: " << endl;
  840.                         cin >> multiplier;
  841.                         cout << "Podaj mnoznik mutagenu: " << endl;
  842.                         cin >> mutagen;
  843.                         virus[id]->set(nazwa, size, mnoznik, mutagen);
  844.                     }
  845.                 }
  846.                 break;
  847.    
  848.                 default:
  849.                 {
  850.                     cout << "brak opcji" << endl;
  851.                     Sleep(700);
  852.                 }
  853.                 } //type
  854.  
  855.             }
  856.             break;
  857.             break;
  858.             }
  859.         } while (x != 'b');
  860.            
  861.         }
  862.         break;
  863.         case '4':
  864.         {
  865.             return;
  866.         }
  867.         break;
  868.         case '3':
  869.         {
  870.             int deli;
  871.             string pass;
  872.             do
  873.             {
  874.             system("cls");
  875.             cout << "Gracz: " << users[Userint]->getLogin() << endl << endl;
  876.             cout << users;   // przeciążenie ostream
  877.             cout << "b - powrot." << endl;
  878.             cout << "u - usun gracza" << endl;
  879.  
  880.             x =_getch();
  881.  
  882.            
  883.                 switch (x)
  884.                 {
  885.                 case 'u':
  886.                 {
  887.                     cout << "Ktorego uzytkownika chcesz usunac?" << endl;
  888.                     cout << "";
  889.                     cin >> deli;
  890.                     if (deli >= user_counter || deli < 0)
  891.                     {
  892.                         cout << "Nie istnieje taki uzytkownik" << endl;
  893.                         Sleep(800);
  894.                         break;
  895.                     }
  896.                     if (deli == Userint)
  897.                     {
  898.                         cout << "Nie mozesz usunac swojego konta." << endl;
  899.                         Sleep(800);
  900.                         break;
  901.                     }
  902.                     cout << "Aby usunac uzytkownika musisz podac jego haslo: " << endl;
  903.                     cout << "";
  904.                     cin >> pass;
  905.  
  906.                     if (users[deli]->checkPassword(pass) == true)
  907.                     {
  908.                         DeleteUser(deli);
  909.                         cout << "Uzytkownik zostal usuniety!." << endl;
  910.                         Sleep(700);
  911.                     }
  912.                     else
  913.                     {
  914.                         cout << "Niewlasciwe haslo!" << endl;
  915.                         Sleep(700);
  916.                     }
  917.                     break;
  918.                 }
  919.                 break;
  920.  
  921.                 case 'b':
  922.                 {
  923.  
  924.                 }
  925.                 break;
  926.                 }
  927.  
  928.             } while (x != 'b');
  929.            
  930.              
  931.  
  932.         }
  933.         break;
  934.  
  935.         case '5':
  936.         {
  937.             Global::saveViruses();
  938.             Global::saveUsers();
  939.             return;
  940.         }
  941.         break;
  942.         }
  943.     }
  944. }
  945.  
  946. Virus* VirusCreator::createVirus(int type)
  947. {
  948.     if (type == 1)
  949.         return new DNA;
  950.     else if (type == 2)
  951.          return new RNA;
  952.     else if (type == 3)
  953.         return new Hybrid;
  954.     else
  955.         return nullptr;
  956. }
  957.  
  958. User::User()
  959. {
  960.     login = "Entry_level_user";
  961.     password = "secret";
  962. }
  963.  
  964. void User::setLogin(string l)
  965. {
  966.     this->login = l;
  967. }
  968.  
  969. void User::setPassword(string p)
  970. {
  971.     this->password = p;
  972. }
  973.  
  974. string User::getLogin()
  975. {
  976.     return login;
  977. }
  978.  
  979. string User::getPassword()
  980. {
  981.     return password;
  982. }
  983.  
  984. bool User::checkPassword(string pass)
  985. {
  986.     if (pass == password)
  987.         return true;
  988.     else
  989.     return false;
  990. }
  991.  
  992. int Global::findLog(string log)
  993. {
  994.     for (int i = 0; i < Global::user_counter; i++)
  995.     {
  996.         if (log == Global::users[i]->getLogin())
  997.             return i;
  998.     }
  999.     return -1;
  1000. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement