fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <vector>
  5.  
  6. struct enemy
  7. {
  8. enemy(int x, int y, int power, int life)
  9. : x(x), y(y), power(power), life(life)
  10. {}
  11. int x,y;
  12. int power;
  13. int life;
  14. };
  15.  
  16. std::ostream& operator<<(std::ostream& o, enemy const& e)
  17. {
  18. o << "- Location:";
  19. o << e.x << ", " << e.y << ". ";
  20. o << "Power: " << e.power << ". ";
  21. o << "Life: " << e.life << ". ";
  22. return o;
  23. }
  24.  
  25. std::vector<enemy> createEnemies(int count);
  26.  
  27. int main()
  28. {
  29. srand(static_cast<unsigned int>(time(0)));
  30.  
  31. const int MAX_ENEMIES = 20;
  32.  
  33. auto enemies = createEnemies(MAX_ENEMIES);
  34.  
  35. for (std::size_t i = 0; i < enemies.size(); ++i)
  36. std::cout << "Enemy " << (i + 1) << enemies[i] << std::endl;
  37. }
  38.  
  39. std::vector<enemy> createEnemies(int count)
  40. {
  41. std::vector<enemy> result;
  42. for (int i = 0; i < count; ++i)
  43. result.emplace_back(rand() % 1000, rand() % 1000, 200, 500);
  44. return result;
  45. }
Success #stdin #stdout 0s 3064KB
stdin
Standard input is empty
stdout
Enemy 1- Location:905, 447. Power: 200. Life: 500. 
Enemy 2- Location:458, 862. Power: 200. Life: 500. 
Enemy 3- Location:505, 401. Power: 200. Life: 500. 
Enemy 4- Location:642, 482. Power: 200. Life: 500. 
Enemy 5- Location:734, 686. Power: 200. Life: 500. 
Enemy 6- Location:192, 400. Power: 200. Life: 500. 
Enemy 7- Location:976, 823. Power: 200. Life: 500. 
Enemy 8- Location:827, 218. Power: 200. Life: 500. 
Enemy 9- Location:75, 489. Power: 200. Life: 500. 
Enemy 10- Location:564, 131. Power: 200. Life: 500. 
Enemy 11- Location:888, 422. Power: 200. Life: 500. 
Enemy 12- Location:960, 472. Power: 200. Life: 500. 
Enemy 13- Location:518, 686. Power: 200. Life: 500. 
Enemy 14- Location:72, 438. Power: 200. Life: 500. 
Enemy 15- Location:788, 849. Power: 200. Life: 500. 
Enemy 16- Location:648, 217. Power: 200. Life: 500. 
Enemy 17- Location:432, 46. Power: 200. Life: 500. 
Enemy 18- Location:799, 106. Power: 200. Life: 500. 
Enemy 19- Location:940, 937. Power: 200. Life: 500. 
Enemy 20- Location:975, 442. Power: 200. Life: 500.