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
|
#include <iostream>
#include <windows.h>
#include <ctime>
using namespace std;
enum DIRECTIONS { N, E, S, W };
enum Colour { black, blue, green, cyan, red, purple, yellow, grey, dgrey, hblue, hgreen, hcyan, hred, hpurple, hyellow, white };
// Colours:
void coutc(int color)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, color);
}
// Randomizer:
int Random(int LowEnd, int Range)
{
return (int) rand() % (Range + 0) + LowEnd;
}
// Prototypes:
void PrintMap(char Map[][81], const int MapY, const int MapX);
// MAIN:
int main()
{
srand(time(0));
bool Generating = true;
const int MapY = 22, MapX = 80;
char Map[MapY+1][MapX+1]; // +1 for null
const char TileType[4] = {'W', 'F', 'R', 'T'};
int Direction, CurrentType = 0, NumOfSeeds = 2000, Iterations, Growth = 20, Select;
while(Generating)
{
// Plant Seeds:
for(int i = 0; i < NumOfSeeds; i++)
{
Map[Random(0, MapY)][Random(0, MapX)] = TileType[CurrentType];
}
Iterations = 0;
// Generate Map:
while(Iterations < Growth)
{
for(int y = 0; y < MapY; y++)
{
for(int x = 0; x < MapX; x++)
{
if(Map[y][x] == TileType[CurrentType])
{
Direction = Random(0, 4);
switch(Direction)
{
case N: Map[y-1][x] = TileType[CurrentType]; break;
case E: Map[y][x+1] = TileType[CurrentType]; break;
case S: Map[y+1][x] = TileType[CurrentType]; break;
case W: Map[y][x-1] = TileType[CurrentType]; break;
}
}
}
}
Iterations++;
}
PrintMap(Map, MapY, MapX);
coutc(dgrey); cout << "TYPES : 1 Wall, 2 Floor, 3 Resource, 4 Trap\n";
coutc(white); cout << " : X) Type X) Seeds X) Growth\n";
cout << " > ";
cin >> Select;
if(Select == 0){ Generating = false; continue; }
cin >> NumOfSeeds >> Growth;
CurrentType = Select - 1;
system("cls");
}
}
// Print Map
void PrintMap(char Map[][81], const int MapY, const int MapX)
{
for(int y = 0; y < MapY; y++)
{
for(int x = 0; x < MapX; x++)
{
switch(Map[y][x])
{
case 'W': coutc(red+(green*16)); cout << 'Y'; break;
case 'F': coutc(hgreen+(green*16)); cout << ','; break;
case 'R': coutc(purple+(green*16)); cout << 'o'; break;
case 'T': coutc(cyan+(green*16)); cout << '~'; break;
}
}
}
}
|