Hi All,
after getting the PvP function working under SimpleMud I have decided to take SimpleMuD to the next step and make a multiplayer roguelike out of it. So far the most important stuff works pretty well exept for my dungeon generation algorithm i am working on.
I started a new Cpp and am first trying to get nice dungeons in the console before implementing it to the mud.
My Problem is that when making the rooms of the dungeon for some reason they still are spawning in each other.
To understand my code better i will give some bullet points of how all works or should work :D
1. i fill my 2d array with walls
2. i get me a random position x and y in the map
3. i get a random width and height of the room that should be carved out
4. i check once around the room to see that there are walls
so for example if this should be the room i check the arrows to see that they are walls and so to say not floor.
^------>
|######|
|#1111#|
|######v
<-------
if these are walls then it should spawn
but they are still spawning together and i can't figure out why.
it would be neat if anyone could help me with this :)
here is my code:
#include <iostream>
#include <fstream>
#include "cstdlib"
#include <ctime>
#include <stdio.h>
#include <termios.h>
#include <string>
using namespace std;
int main()
{
const int mapx =22;
const int mapy =82;//69;
const int mapz =10;
char map[mapx][mapy]=
{
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "
};
srand(time(NULL));
const unsigned int maxRooms=5;
unsigned int roomCounter=0;
unsigned int startX=1 +(rand()%(mapx-2));
unsigned int startY=1+(rand()%(mapy-5));
char floor='a';
char door='+';
//char wall='#';
char wall=' ';
int length2;
int randomPosy;
int randomPosx;
int width;
int maxrandomPosy;
int maxrandomPosx;
int checker1=0;
bool check1=false;
int checker2=0;
int check2=false;
int checker3=0;
bool check3=false;
int checker4=0;
bool check4=false;
while(roomCounter<maxRooms)
{
if(roomCounter==0)
{
floor='1';
}
if(roomCounter==1)
{
floor='2';
}
if(roomCounter==2)
{
floor='3';
}
if(roomCounter==3)
{
floor='4';
}
if(roomCounter==4)
{
floor='5';
}
length2=rand()% 5 + 5;
randomPosy=1+rand()% 65;
randomPosx=1+rand()% 14;
width=rand()%3+4;
maxrandomPosy=randomPosy+length2;
maxrandomPosx=randomPosx+width;
for(int a=randomPosy; a<=maxrandomPosy;a++)
{
if(map[randomPosx-1][a]==wall)
{
checker1++;
}
}
if(checker1==maxrandomPosy-randomPosy+1)
{
check1=true;
}
for(int b=randomPosx; b<=maxrandomPosx;b++)
{
if(map[maxrandomPosy+1]==wall)
{
checker2++;
}
}
if(checker2==maxrandomPosx-randomPosx+1)
{
check2=true;
}
for(int c=randomPosy; c<=maxrandomPosy;c++)
{
if(map[maxrandomPosx+1][c]==wall)
{
checker3++;
}
}
if(checker3==maxrandomPosy-randomPosy+1)
{
check3=true;
}
for(int d=randomPosx; d<=maxrandomPosx;d++)
{
if(map[d][randomPosy-1]==wall)
{
checker4++;
}
}
if(checker4==maxrandomPosx-randomPosx+1)
{
check4=true;
}
if(check1==true && check2==true && check3==true && check4 == true)
{
while(randomPosy<maxrandomPosy)
{
for(int c=randomPosx;c< maxrandomPosx;c++)
{
map[c][randomPosy]=floor;
}
randomPosy++;
}
++roomCounter;
}
}
//print map
for(int m=0;m<mapx;m++)
{
cout <<map[m]<<endl;
}
return 0;
}
|