Code:
void DrawMap::Set_Map( int *tile, void *MapBuffer[1][1], int Xcoord, int Ycoord, int Xmax, int Ymax ) {
Xcoord = 0;
Ycoord = 0;
Well, first I think you meant to have that Xcoord and Ycoord variables in the constructor, because with them there you are changing the variables to 0 even if you say put 5 in the Set_Map function when call it, so theres no point in even asking for the xcoord and ycoord in that parameter.
Furthermore if you put a number smaller than 80 in the parameter for Xmax, then the loop would never end, causing quite a fun bug to find. Instead of using this if statement to end it:
Code:
if( Xcoord <= 80 ) {
Ycoord++;
}
I would change the while statement all together to:
Code:
while( Ycoord <= Ymax ) {
Xcoord = 0;
while( Xcoord <= Xmax && Xcoord <= 80 ) {
MapBuffer[Xcoord][Ycoord] = new tile( false, 50, 9, 5 );
// ^^ This line gives me the errors:
// expected ')' before "hardness"
// expected ';' before "hardness"
Xcoord++;
}
Ycoord++;
}
I changed the while statement so it will never go past 80, and made sure when it ends it increments Ycoord.
--------------------------------------------------------------------
On trying to figure out what you wanted your code to do, I remodded your code, and its pretty much my own code now.. completely changed. It works though, check it out and see how its done. Theres no macros in any of my code, theres an alternative for mostly every macro scenario thats safer/better/easier/more clear.
It would have been much easier using a normal 1 dimension array, but since its 2 dimensions you need to know special rules on how 2 dimension arrays work. I read it in Data Structures for Game Programmers myself, great book to start on the basics of how to lat out your classes for games, which basic choices to make, and a good thing to read before learning STL.
To make the 2 dimension array, its simply the first multiplied by the second ([1][1] has 1 spot, [1][2] has 2 spots, see its just multiplied). To access a spot in the 2 dimension array, its the first spot you want to access, multiplied by the highest second spot (in a [10][30] type array, it would be 30), added to the second spot you are trying to access. eg. you want to access spot [4][6] in array [10][20], then the formula is 4 * 20 + 6. Look at the array: m_mapBuffer to see what I mean, thats a 2d array but to use it you have to use that formula instead of the normal [][].
With that said..
Code:
#include <iostream>
enum RAINBOW {red, blue, green, orange, yellow, purple, pink, etc};
struct STile
{
bool hardness;
char symbol;
enum RAINBOW color;
int visibility;
};
class CDraw_Map
{
private:
int m_yMax;
int m_xMax;
int m_xCoord;
int m_yCoord;
STile* m_mapBuffer;
public:
CDraw_Map () {} /* put this version here incase you dont want to give parameters on construction of object */
CDraw_Map (int, int); /* this version allows setting the size of the map on construction */
~CDraw_Map ();
void DrawMap ();
void SetMapSize (int, int); /* alternate way to set map size, used when resizing, or not using the (int, int) constructor. */
void SetTile (int, int, bool, char, enum RAINBOW, int);
void SetAllTiles (bool, char, enum RAINBOW, int);
int ClearAllTiles ();
void CoutTile (int, int); //temporarily used to check if functions worked
};
CDraw_Map::CDraw_Map (int p_yMax, int p_xMax) : m_yMax(p_yMax), m_xMax(p_xMax)
{
m_mapBuffer = new STile[p_yMax * p_xMax];
}
CDraw_Map::~CDraw_Map ()
{
}
void CDraw_Map::SetTile (int p_yCoord, int p_xCoord, bool p_hardness, char p_symbol, enum RAINBOW p_color, int p_visibility)
{
m_mapBuffer[p_yCoord * m_yMax + p_yCoord].hardness = p_hardness;
m_mapBuffer[p_yCoord * m_yMax + p_yCoord].symbol = p_symbol;
m_mapBuffer[p_yCoord * m_yMax + p_yCoord].color = p_color;
m_mapBuffer[p_yCoord * m_yMax + p_yCoord].visibility = p_visibility;
}
void CDraw_Map::SetAllTiles (bool p_hardness, char p_symbol, enum RAINBOW p_color, int p_visibility)
{
for (int i = 0; i < m_yMax; ++i) {
for (int j = 0; j < m_xMax; ++j) {
m_mapBuffer[i * m_yMax + j].hardness = p_hardness;
m_mapBuffer[i * m_yMax + j].symbol = p_symbol;
m_mapBuffer[i * m_yMax + j].color = p_color;
m_mapBuffer[i * m_yMax + j].visibility = p_visibility;
}
}
}
void CDraw_Map::CoutTile (int p_yCoord, int p_xCoord)
{
std::cout << m_mapBuffer[p_yCoord * m_yMax + p_yCoord].hardness << std::endl;
std::cout << m_mapBuffer[p_yCoord * m_yMax + p_yCoord].symbol << std::endl;
std::cout << m_mapBuffer[p_yCoord * m_yMax + p_yCoord].color << std::endl;
std::cout << m_mapBuffer[p_yCoord * m_yMax + p_yCoord].visibility << std::endl;
}
void CDraw_Map::SetMapSize (int p_yMax, int p_xMax)
{
STile* tempBuffer = new STile[p_yMax * p_xMax];
m_mapBuffer = tempBuffer;
/* assign the classes private values to the new values */
m_yMax = p_yMax;
m_xMax = p_xMax;
}
int main ()
{
CDraw_Map Map1(20, 20);
Map1.SetTile(10, 12, 0, 'C', blue, 9);
Map1.CoutTile(10, 12);
Map1.SetAllTiles(1, 'A', red, 5);
Map1.CoutTile(0, 0);
std::cin.get();
}
I included that main () simply for demonstration, along with the method CoutTile ().
I would suggest, when you are beginning, to take things 1 step at a time. I could have written almost this entire thing by simply starting off with a [50][50] array and then worrying about how to resize it and such after (which is exactly what I did actually).