Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- class Unit {
- public:
- int x, y;
- };
- class Map {
- private:
- int height, width;
- string **mat;
- vector<Unit> Units;
- public:
- Map (int w, int h) {
- mat = new string*[w];
- for (int i = 0;i < w;i++){
- mat[i] = new string[h];
- }
- for (int i = 0;i < h;i++){
- for (int j = 0;j < w;j++){
- mat[i][j] = " • ";
- }
- }
- height = h;
- width = w;
- }
- void printMap () {
- for (int i = 0;i < height;i++) {
- for (int j = 0;j < width;j++){
- cout << mat[i][j];
- }
- cout << endl;
- }
- }
- void spawnUnits (int amount) {
- for (int i = 0;i < amount;i++){
- Unit unit;
- unit.x = rand() % width;
- unit.y = rand() % height;
- if (mat[unit.x][unit.y] == " • ") {
- Units.push_back(unit);
- mat[unit.x][unit.y] = " ☺ ";
- }
- }
- }
- };
- int main()
- {
- srand (time(NULL));
- Map map(10, 10);
- map.spawnUnits(10);
- map.printMap();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement