accessing variable from other class after init.

Im currently working on a project, trying to make a basic roquelike mapcreator (or something that comes close). For this purpose, the program start by making a room in a (programmer) specified place with certain x and y values. Thén I want to create a path (this is also a class, just like the room) in a random direction at a random place that is connected to the room. But the problem is that the path-class take the x and y values from before the room x and y values were set. While in the main, the (void) function of the path creating is set after the setup of the room x and y. Can someone help? Ill put the code below, thick lines are the ones im talking about. My code isn't that clean...

Main.cpp:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

#define RoomWidth 10
#define RoomHeight 10

#include "room.h"
#include "path.h"

int MapArray[RoomWidth][RoomHeight];

void ClearMap(){
for(int n=0;n<RoomHeight;n++){
for(int m=0;m<RoomWidth;m++){

MapArray[n][m]=0;

}}}

void DisplayMap(){
for(int n=0;n<RoomHeight;n++){
for(int m=0;m<RoomWidth;m++){

if(MapArray[n][m]==0){cout<<".";}
if(MapArray[n][m]==1){cout<<"*";}
if(MapArray[n][m]==2){cout<<" ";}
if(MapArray[n][m]==3){cout<<",";}
if(MapArray[n][m]==4){cout<<"#";}
//else{cout<<"?";}

}
cout<<endl;}
cout<< endl;}

void MutateMap(){
for(int n=0;n<RoomHeight;n++){
for(int m=0;m<RoomWidth;m++){

if(MapArray[n][m]==0){

int x=rand()%4;
if(x==0){MapArray[n][m]=1;}}

if(MapArray[n][m]==2){

int x=rand()%4;
if(x==0){MapArray[n][m]=3;}}

}}}



int main(){
srand(time(NULL));
ClearMap();
Room* first=new Room();
Path* fpath=new Path();
first->SetValues(3,3);
first->PlaceRoom();
fpath->PlacePath();
//MutateMap();
DisplayMap();
system("PAUSE");
delete first;
delete fpath;
return 0;
}

----

Path.h + Path.cpp:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

#include "room.h"

class Path:public Room{
int x,y,l,nr,d;
public:
Path();
~Path();
void PlacePath();
};

----

#include "path.h"

#define RoomWidth 10
#define RoomHeight 10
extern int MapArray[RoomWidth][RoomHeight];

#define North 0
#define East 1
#define South 2
#define West 3

Path::Path(){}
Path::~Path(){}

void Path::PlacePath(){
int rx=Room::x;
int ry=Room::y;
int rdx=Room::dx;
int rdy=Room::dy;

cout<<"x="<<rx<<" y="<<ry<<" dx="<<rdx<<" dy="<<rdy<<endl<<endl;

int nr=2;//rand()%(rdx+1);
int l=3;//rand()%1+1;
//int d=rand()%4;
int d=0;


if (d==North){
for (int n=0;n<4;n++){
MapArray[n][5]=2;
}}

//if (d==East){
//if (d==South){
//if (d==West){

}

----

Room.h + Room.cpp:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

class Room{
public:
int x,y,dx,dy;
Room();
~Room();
int Getx();
int Gety();
int Getdx();
int Getdy();
void SetValues(int,int);
void PlaceRoom();
};

----

#include "room.h"

#define RoomWidth 10
#define RoomHeight 10
extern int MapArray[RoomWidth][RoomHeight];

Room::Room(){}
Room::~Room(){}

int Room::Getx(){
return x;
}

int Room::Gety(){
return y;
}

int Room::Getdx(){
return dx;
}

int Room::Getdy(){
return dy;
}


void Room::SetValues(int a,int b){
x = a;
y = b;
dx=rand()%2+2;
dy=rand()%2+2;
}

void Room::PlaceRoom(){

for(int n=(y);n<=(y+dy);n++){
for(int m=(x);m<=(x+dx);m++){

MapArray[n][m]=2;

for(int n=(y-1);n<=(y+dy+1);n++){
for(int m=(x-1);m<=(x+dx+1);m++){
if (n<(y)||n>(y+dy)||m<(x)||m>(x+dx)){MapArray[n][m]=4;}

}}}}}
It seems that you don't understand the difference between objects and classes.
¿where do you relate `first' with `fpath'?

Apart:
¿why are you using dynamic allocation?
class Path:public Room ¿a path is a room?
That's true :P
Do you maybe have an idea where I can start learning about this?
Topic archived. No new replies allowed.