1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <time.h>
using namespace std;
//========================//
//Array Format: Y*Width+X //
//========================//
void Game_Start(int x, int y, char world[]) {
for (int i = 0; i < x*y; i++) {
world[i] = '.';
}
}
void Map_Print(int x, int y, char world[]) {
ofstream map_save;
map_save.open("Map_Save.txt");
for (int i = 0; i < y; i++) {
for (int j = 0; j < x; j++) {
map_save << world[i*x+j];
}
map_save << endl;
}
map_save.close();
}
void Generate_Square_Room_Randomly(int x, int y, char world[]) {
int room_hieght = rand() % 12 + 6;
int room_width = rand() % 12 + 6;
int bottomcorner_x = rand() % x + 19;
int bottomcorner_y = rand() % y + 19;
//Right Wall
for (int i = 0; i < room_hieght; i++) {
world[(bottomcorner_y+i)*x+bottomcorner_x] = '#';
}
//Top Wall
for (int i = 0; i < room_width; i++) {
world[bottomcorner_y*x+(bottomcorner_x-i)] = '#';
}
//Left Wall
for (int i = 0; i < room_hieght; i++) {
world[(bottomcorner_y+i)*x+(bottomcorner_x-room_width)] = '#';
}
//Bottom Wall
for (int i = 0; i < room_width; i++) {
world[(bottomcorner_y+room_hieght-1)*x+(bottomcorner_x-i)] = '#';
}
}
int main(int argc, char *argv[])
{
//=======================================================//
//Naming Convention: X = Left and Right, Y = Up and Down //
//=======================================================//
srand(time(NULL));
int rows = rand() % 40 + 100;
int columns = rand() % 40 + 100;
char world[rows*columns];
Game_Start(rows,columns,world);
Generate_Square_Room_Randomly(rows,columns,world);
Generate_Square_Room_Randomly(rows,columns,world);
Generate_Square_Room_Randomly(rows,columns,world);
Generate_Square_Room_Randomly(rows,columns,world);
Generate_Square_Room_Randomly(rows,columns,world);
Generate_Square_Room_Randomly(rows,columns,world);
Map_Print(rows,columns,world);
system("PAUSE");
return EXIT_SUCCESS;
}
|