Advertisement
Guest User

mapMaker

a guest
Jan 27th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <algorithm>
  4. #include <windows.h>
  5. #include <string>
  6. #include <vector>
  7. using namespace std;
  8.  
  9. enum tileType { emptyTile, floorTile, wallTile };
  10. enum mapSize { tiny, medium, large }; //20x20, 50x50, 100x100 tiles, respectively
  11.  
  12. //Generates a single random integer between the min and max
  13. int randNumGen(int min, int max) {
  14.     SYSTEMTIME time;
  15.     GetSystemTime(&time);
  16.     LONG time_ms = static_cast<int>((time.wSecond * 1000) + time.wMilliseconds);
  17.     srand(time_ms);
  18.     int n = max - min + 1;
  19.     int remainder = RAND_MAX % n;
  20.     int x;
  21.     do {
  22.         x = rand();
  23.     } while (x >= RAND_MAX - remainder);
  24.     return min + x % n;
  25. }
  26.  
  27. //Generates the map array, given the x and y boundaries
  28. void generateMap(mapSize size, vector<vector<vector<int>>>& map) {
  29.     int xSize, ySize;
  30.     //Resize Vector Based on Map Size Choice
  31.     if (size == tiny) { xSize = 10; ySize = 10; }
  32.     if (size == medium) { xSize = 30; ySize = 30; }
  33.     if (size == large) { xSize = 50; ySize = 50; }
  34.     map.resize(xSize, vector<vector<int>>(ySize, vector<int>(2)));
  35.     //Generate Map
  36.     for (int x = 0; x < xSize; x++) {
  37.         for (int y = 0; y < ySize; y++) {
  38.             if (x == 0 || x == xSize) map[x][y][0] = wallTile;
  39.             else if (y == 0 || y == ySize) map[x][y][0] = wallTile;
  40.             else map[x][y][0] = tileType::floorTile;
  41.         }
  42.     }
  43. }
  44.  
  45. int main() {
  46.     int position[2]; //x,y coordinates on map
  47.     string userInput;
  48.     mapSize mapSize;
  49.     vector<vector<vector<int>>> map;
  50.     cout << "What size map would you like to play on? [Tiny, Medium, Large]\n";
  51.     //Ask Map Size
  52.     bool repeat;
  53.     do {
  54.         repeat = false;
  55.         cin >> userInput;
  56.         transform(userInput.begin(), userInput.end(), userInput.begin(), tolower);
  57.         if (userInput == "tiny") mapSize = tiny;
  58.         else if (userInput == "medium") mapSize = medium;
  59.         else if (userInput == "large") mapSize = large;
  60.         else {
  61.             cout << "Error: Please enter tiny, medium or large\n";
  62.             repeat = true;
  63.         }
  64.     } while (repeat);
  65.     cout << "Loading " << userInput << " map now!\n";
  66.     int xSize, ySize;
  67.     if (mapSize == tiny) { xSize = 10; ySize = 10; }
  68.     if (mapSize == medium) { xSize = 30; ySize = 30; }
  69.     if (mapSize == large) { xSize = 50; ySize = 50; }
  70.     generateMap(mapSize, map);
  71.  
  72.     for (int y = 0; y < ySize; y++) {
  73.         for (int x = 0; x < xSize; x++) {
  74.             cout << map[x][y][0];
  75.         }
  76.         cout << endl;
  77.     }
  78.  
  79.  
  80.     cout << endl;
  81.     return 1;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement