Quemaster

Untitled

Feb 6th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1.  struct player
  2. {
  3.     string name;
  4.     int x;
  5.     int y;
  6.     int hp;
  7. };
  8.  
  9.  
  10.  
  11. void setPosition(vector<player> player)
  12. {
  13.     bool x_check = true;    //Bool sprawdza czy parametry x zostały prawidłowo wpisane, żeby nie prosić o nie ponownie, gdy
  14.                             //parametry y są nieprawidłowe
  15.  
  16.     bool showParameters = true;     //Bool pilnuje żeby ostatecznie wybrane parametry zostały pokazane tylko raz
  17.  
  18.     for(int i = 0;i<player.size();i++)
  19.     {
  20.         showParameters = true;
  21.         if (x_check)
  22.         {
  23.             cout << "Podaj parametr x dla pozycji gracza " << player[i].name << endl;
  24.             cin >> player[i].x;
  25.         }
  26.  
  27.         if(cinfail())
  28.                 i--;
  29.  
  30.         else if (player[i].x<0 || player[i].x>100)
  31.  
  32.         {
  33.             cout << "Wybierz x w zakresie 0-100" << endl;
  34.             i--;
  35.         }
  36.         else
  37.         {
  38.             x_check = false;
  39.             cout << "Podaj parametr y dla pozycji gracza " << player[i].name << endl;
  40.             cin >> player[i].y;
  41.  
  42.             if(cinfail())
  43.                 i--;
  44.  
  45.             else if (player[i].y<0 || player[i].y>100)
  46.             {
  47.                 cout << "Wybierz y w zakresie 0-100" << endl;
  48.                 i--;
  49.             }
  50.             else
  51.             {
  52.                 for(int k = 0;k<i;k++)  //sprawdza czy przypadkiem nie uzyto takich samych parametrow dla dwoch graczy
  53.                 {
  54.                     if(player[i].x == player[k].x && player[i].y == player[k].y)
  55.                     {
  56.                         cout << "Podales takie same parametry jakie ma gracz " << player[k].name << "! Wybierz inne." << endl;
  57.                         i--;
  58.                         x_check = true;
  59.                         showParameters = false;
  60.                     }
  61.  
  62.                 }
  63.                 if(showParameters)
  64.                 {
  65.                     x_check = true;
  66.                 }
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment