Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <algorithm>
- #include <windows.h>
- #include <string>
- #include <vector>
- using namespace std;
- enum tileType { emptyTile, floorTile, wallTile };
- enum mapSize { tiny, medium, large }; //20x20, 50x50, 100x100 tiles, respectively
- //Generates a single random integer between the min and max
- int randNumGen(int min, int max) {
- SYSTEMTIME time;
- GetSystemTime(&time);
- LONG time_ms = static_cast<int>((time.wSecond * 1000) + time.wMilliseconds);
- srand(time_ms);
- int n = max - min + 1;
- int remainder = RAND_MAX % n;
- int x;
- do {
- x = rand();
- } while (x >= RAND_MAX - remainder);
- return min + x % n;
- }
- //Generates the map array, given the x and y boundaries
- void generateMap(mapSize size, vector<vector<vector<int>>>& map) {
- int xSize, ySize;
- //Resize Vector Based on Map Size Choice
- if (size == tiny) { xSize = 10; ySize = 10; }
- if (size == medium) { xSize = 30; ySize = 30; }
- if (size == large) { xSize = 50; ySize = 50; }
- map.resize(xSize, vector<vector<int>>(ySize, vector<int>(2)));
- //Generate Map
- for (int x = 0; x < xSize; x++) {
- for (int y = 0; y < ySize; y++) {
- if (x == 0 || x == xSize) map[x][y][0] = wallTile;
- else if (y == 0 || y == ySize) map[x][y][0] = wallTile;
- else map[x][y][0] = tileType::floorTile;
- }
- }
- }
- int main() {
- int position[2]; //x,y coordinates on map
- string userInput;
- mapSize mapSize;
- vector<vector<vector<int>>> map;
- cout << "What size map would you like to play on? [Tiny, Medium, Large]\n";
- //Ask Map Size
- bool repeat;
- do {
- repeat = false;
- cin >> userInput;
- transform(userInput.begin(), userInput.end(), userInput.begin(), tolower);
- if (userInput == "tiny") mapSize = tiny;
- else if (userInput == "medium") mapSize = medium;
- else if (userInput == "large") mapSize = large;
- else {
- cout << "Error: Please enter tiny, medium or large\n";
- repeat = true;
- }
- } while (repeat);
- cout << "Loading " << userInput << " map now!\n";
- int xSize, ySize;
- if (mapSize == tiny) { xSize = 10; ySize = 10; }
- if (mapSize == medium) { xSize = 30; ySize = 30; }
- if (mapSize == large) { xSize = 50; ySize = 50; }
- generateMap(mapSize, map);
- for (int y = 0; y < ySize; y++) {
- for (int x = 0; x < xSize; x++) {
- cout << map[x][y][0];
- }
- cout << endl;
- }
- cout << endl;
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement