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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
|
#include <iostream>
#include <ctime>
#include <vector>
#include <Windows.h>
using namespace std;
void setColor(unsigned short color)
{
HANDLE hConCol = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConCol, color);
/*
HEX COLOUR CODES
0 = Black
1 = Blue
2 = Green
3 = Aqua
4 = Red
5 = Purple
6 = Yellow
7 = White
8 = Gray
9 = Light Blue
A = Light Green 10
B = Light Aqua 11
C = Light Red 12
D = Light Purple 13
E = Light Yellow 14
F = Bright White 15
*/
}
void SetWindow(int Width, int Height) // (X CHARACTERS, Y LINES)
{
_COORD coord;
coord.X = Width;
coord.Y = Height;
_SMALL_RECT Rect;
Rect.Top = 0;
Rect.Left = 0;
Rect.Bottom = Height - 1;
Rect.Right = Width - 1;
HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE); // Get Handle
SetConsoleScreenBufferSize(Handle, coord); // Set Buffer Size
SetConsoleWindowInfo(Handle, TRUE, &Rect); // Set Window Size
}
struct Coordinate
{
unsigned int x;
unsigned int y;
};
struct Room
{
Coordinate RoomPosition;
int MapExit;
int MapStart;
int PlaceHolder;
int Visited;
};
int main()
{
srand((unsigned int)time(NULL));
SetWindow(100, 50);
//int numbera; //roomcounter
int roomcount = 0;
unsigned int tempX = 9;
unsigned int tempY = 9;
unsigned int inputLevel;
unsigned int difficulty;
inputLevel = 9;
difficulty = (inputLevel * 2) + 1;
vector <vector <Room> > GlobalMap(difficulty, vector<Room>(difficulty));
GlobalMap[inputLevel][inputLevel].MapStart = 1;
for (unsigned int indexY = 0; indexY < difficulty; indexY++) //ALLOCATE VECTOR COORINATES FOR MAP
{
for (unsigned int indexX = 0; indexX < difficulty; indexX++)
{
GlobalMap[indexY][indexX].RoomPosition.x = indexX;
GlobalMap[indexY][indexX].RoomPosition.y = indexY;
}
}
unsigned int doorExit;
unsigned int prevDoorExitCheck;
char door1 = 'N';
char door2 = 'E';
char door3 = 'S';
char door4 = 'W';
int roomEntryDoorLoc;
doorExit = rand() % 4 + 1;
cout << "Map Start: Door Exit Location: ";
setColor(10);
switch (doorExit)
{
case 1:
cout << door1 << endl;
tempY--;
GlobalMap[tempY][tempX].Visited = 1;
break;
case 2:
cout << door2 << endl;
tempX++;
GlobalMap[tempY][tempX].Visited = 1;
break;
case 3:
cout << door3 << endl;
tempY++;
GlobalMap[tempY][tempX].Visited = 1;
break;
case 4:
cout << door4 << endl;
tempX--;
GlobalMap[tempY][tempX].Visited = 1;
break;
}
setColor(7);
prevDoorExitCheck = doorExit;
if (doorExit == 1) // IF PREVIOUS ROOM EXIT DOOR WAS NORTH, CURRENT ROOM ENTRY DOOR IS SOUTH
{
roomEntryDoorLoc = 3;
}
else if (prevDoorExitCheck == 2) // IF PREVIOUS ROOM EXIT DOOR WAS EAST, CURRENT ROOM ENTRY DOOR IS WEST
{
roomEntryDoorLoc = 4;
}
else if (prevDoorExitCheck == 3) // IF PREVIOUS ROOM EXIT DOOR WAS SOUTH, CURRENT ROOM ENTRY DOOR IS NORTH
{
roomEntryDoorLoc = 1;
}
else if (prevDoorExitCheck == 4) // IF PREVIOUS ROOM EXIT DOOR WAS WEST, CURRENT ROOM ENTRY DOOR IS EAST
{
roomEntryDoorLoc = 2;
}
for (unsigned int rolla = 0; rolla < inputLevel; rolla++) //GENERATE ROOMS UP TO LEVEL DIFFICULTY
{
switch (roomEntryDoorLoc) //IF ROOM ENTRY IS
{
case 1: //NORTH
cout << "Room #: " << rolla + 1 << ", Entry Door: ";
cout << door1 << ", Door Exit Location: ";
break;
case 2: //EAST
cout << "Room #: " << rolla + 1 << ", Entry Door: ";
cout << door2 << ", Door Exit Location: ";
break;
case 3: //SOUTH
cout << "Room #: " << rolla + 1 << ", Entry Door: ";
cout << door3 << ", Door Exit Location: ";
break;
case 4: //WEST
cout << "Room #: " << rolla + 1 << ", Entry Door: ";
cout << door4 << ", Door Exit Location: ";
break;
}
if (rolla == inputLevel-1)
{
setColor(12);
cout << "LEVEL MAP EXIT ROOM"; setColor(7);
GlobalMap[tempY][tempX].MapExit = 1;
}
else
{
do
{
doorExit = rand() % 4 + 1;
} while (doorExit == roomEntryDoorLoc); //EXIT DOOR GENERATED IS THE SAME AS THE ENTRY DOOR, REGENERATE //******ADD ALGORITHM SAYING: CHECK IF ROOM IS PLACEHOLDER TO NOT LOOP BACK IN TO ROOM (WILL NEED TO ADD NEW VARIABLE IN VECTOR TO ASSIGN FLAGS)
setColor(9);
switch (doorExit) //IF THE DOOR EXIT IS
{
case 1: //NORTH
cout << door1; //PRINT NORTH
tempY--; //INCREMENT MOVEMENT COUNTER
GlobalMap[tempY][tempX].Visited = 1;
roomEntryDoorLoc = 3; //SET NEW ROOM ENTRY TO SOUTH
break;
case 2:
cout << door2; //EAST
tempX++;
GlobalMap[tempY][tempX].Visited = 1;
roomEntryDoorLoc = 4; //SET NEW ROOM ENTRY TO WEST
break;
case 3:
cout << door3; //SOUTH
tempY++;
GlobalMap[tempY][tempX].Visited = 1;
roomEntryDoorLoc = 1; //SET NEW ROOM ENTRY TO NORTH
break;
case 4:
cout << door4; //WEST
tempX--;
GlobalMap[tempY][tempX].Visited = 1;
roomEntryDoorLoc = 2; //SET NEW ROOM ENTRY TO EAST
break;
}
setColor(7);
}
cout << endl;
}
system("Pause");
cout << endl;
for (unsigned int indexY = 0; indexY < difficulty; indexY++) //PRINT COORDINATES
//cout << "0" << GlobalMap[indexY][indexX].RoomPosition.y << "0" << GlobalMap[indexY][indexX].RoomPosition.x << " ";
{
for (unsigned int indexX = 0; indexX < difficulty; indexX++)
{
if (indexY == 9 && indexX == 9)
{
setColor(10);
}
if (GlobalMap[indexY][indexX].Visited == 1)
{
setColor(9);
}
else
{
setColor(7);
}
if (GlobalMap[indexY][indexX].MapExit == 1)
{
setColor(12);
}
if (GlobalMap[indexY][indexX].MapStart == 1)
{
setColor(10);
}
if (GlobalMap[indexY][indexX].RoomPosition.y <= inputLevel && GlobalMap[indexY][indexX].RoomPosition.x <= inputLevel) //QUAD2
{
cout << "0" << GlobalMap[indexY][indexX].RoomPosition.y << "0" << GlobalMap[indexY][indexX].RoomPosition.x << " ";
}
if (GlobalMap[indexY][indexX].RoomPosition.y > inputLevel && GlobalMap[indexY][indexX].RoomPosition.x > inputLevel) //QUAD4
{
cout << "" << GlobalMap[indexY][indexX].RoomPosition.y << "" << GlobalMap[indexY][indexX].RoomPosition.x << " ";
}
if (GlobalMap[indexY][indexX].RoomPosition.y <= inputLevel && GlobalMap[indexY][indexX].RoomPosition.x > inputLevel) //QUAD1
{
cout << "0" << GlobalMap[indexY][indexX].RoomPosition.y << "" << GlobalMap[indexY][indexX].RoomPosition.x << " ";
}
if (GlobalMap[indexY][indexX].RoomPosition.y > inputLevel && GlobalMap[indexY][indexX].RoomPosition.x <= inputLevel) //QUAD3
{
cout << "" << GlobalMap[indexY][indexX].RoomPosition.y << "0" << GlobalMap[indexY][indexX].RoomPosition.x << " ";
}
}
cout << endl;
}
return 0;
}
|