Hey guys, about a week ago I started coding a Roguelike.
I've been having structure problems for a while and have sort of been skirting around them.
A feature very central to RLs is the Map drawing, and I have chosen to implement this using Mulid-Dimensional arrays. I also like to keep my Classes in separate files, so most of the Classes that are interaction based or Map based are requiring this array. Basically, I have been swarmed with "'array' was not declared in this scope" errors.
Here's the code:
Main.cpp
1 2 3 4 5 6 7 8 9
|
#include "Map.h"
int main ()
{
Map printMapOb;
printMapOb.generateMap();
printMapOb.drawMap(&GenMap, &M_ROW, &M_COL);
}
|
Map.h
1 2 3 4 5 6 7
|
class Map
{
public:
int generateMap();
int *GenMap[][0];
void drawMap(int mapArray[][0], int M_R, int M_C);
}
|
Map.cpp
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
|
#include "Map.h"
#define TILE_FLOOR 0
int Map::generateMap(){
int *M_COL, *M_ROW;
int row, col;
srand(time(0));
*M_ROW = (rand()%10) + 20;
*M_COL = (rand()%10) + 20;
int *GenMap[*M_ROW][*M_COL];
for (row = 0; row < *M_ROW; row++)
{
GenMap[row][col] = TILE_FLOOR;
for (col = 0; col < *M_COL; col++)
{
GenMap[row][col] = TILE_FLOOR;
}
}
}
|
So basically we've got generateMap() generating a Map, go figure. drawMap() prints the map to the screen, and requires that an array and two ints be passed to it. My problem here is I dont understand how other RLs can have a large amount of functions and classes interacting with the map, when all of those functions and classes are split up between multiple files, and are having to share this one Map.
Current Error:
H:\Code\Roguelike Dev\Ismuth\main.cpp|63|error: 'GenMap' was not declared in this scope|
H:\Code\Roguelike Dev\Ismuth\main.cpp|63|error: 'M_ROW' was not declared in this scope|
H:\Code\Roguelike Dev\Ismuth\main.cpp|63|error: 'M_COL' was not declared in this scope|
Any help much appreciated!
EDIT: I omitted a lot of the code for the sake of simplicity.