Advertisement
uzimane_

OOP Lab_1 (work in progress)

Sep 26th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. class Unit {
  8.     public:
  9.     int x, y;
  10. };
  11.  
  12. class Map {
  13. private:
  14.     int height, width;
  15.     string **mat;
  16.     vector<Unit> Units;
  17.    
  18. public:
  19.     Map (int w, int h) {
  20.        mat = new string*[w];
  21.        for (int i = 0;i < w;i++){
  22.            mat[i] = new string[h];
  23.        }
  24.        for (int i = 0;i < h;i++){
  25.            for (int j = 0;j < w;j++){
  26.                mat[i][j] = " • ";
  27.            }
  28.        }
  29.        height = h;
  30.        width = w;
  31.     }
  32.    
  33.     void printMap () {
  34.         for (int i = 0;i < height;i++) {
  35.             for (int j = 0;j < width;j++){
  36.                cout << mat[i][j];
  37.             }
  38.             cout << endl;
  39.         }
  40.     }
  41.    
  42.     void spawnUnits (int amount) {
  43.         for (int i = 0;i < amount;i++){
  44.             Unit unit;
  45.             unit.x = rand() % width;
  46.             unit.y = rand() % height;
  47.             if (mat[unit.x][unit.y] == " • ") {
  48.                 Units.push_back(unit);
  49.                 mat[unit.x][unit.y] = " ☺ ";
  50.             }
  51.         }
  52.     }
  53.    
  54. };
  55.  
  56. int main()
  57. {
  58.     srand (time(NULL));
  59.    
  60.     Map map(10, 10);
  61.     map.spawnUnits(10);
  62.     map.printMap();
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement