Hi everyone I was hoping to possibly get some help with this piece of code I have been having issues with. Sorry for the mess but I have been re-writing this piece over and over looking for solutions. So here is the deal, I am trying to hard code an array inside a class a.k.a "mLevelDesign." So i may pass it to mMapBuffer whenever I need to update the "map". My issue is that feel I am making this much harder on myself then need be, but I have already tried creating a third instance of the array so that I removed mLevelDesign from private in the header and added say mCopyLevel, then pass mLevelDesign into mCopyLevel when Map is constructed, then use mCopyLevel in mLevelDesign's place. Though I seem to have gotten alot of lost memory and other issues running that way. I am just curious if there is some simple way to be able to hard code an array while still keeping it listed in the header file, and even better yet not loosing it in memory? As of right now this code throws error: cannot convert 'brace-enclosed initializer list' to 'int' in assignment.
//Map.h
#ifndef MAP_H
#define MAP_H
class Map
{
public:
Map();
void update();
void drawMap();
private:
int mLevelDesign[100];
int* mMapBuffer;
int mMapX;
int mMapY;
int mPlayerX;
int mPlayerY;
bool mBossDead;
bool mEnemy1Dead;
bool mEnemy2Dead;
bool mTreasureLooted;
};
#endif // MAP_H
//Map.cpp
#include <iostream>
#include "Map.h"
using namespace std;
Map::Map()
{
mMapX = 10;
mMapY = 10;
mPlayerX = 6;
mPlayerY = 10;
mLevelDesign[100] =
/* 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ,10 */
/*1*/ { 0 , 0 , 0 , 0 , 1 ,'D', 1 , 0 , 0 , 0 ,
/*2*/ 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , 0 , 0 ,
/*3*/ 1 , 2 , 2 , 2 , 1 , 0 , 1 , 2 , 1 , 0 ,
/*4*/ 1 ,'T','E', 0 , 0 , 0 , 0 ,'F', 1 , 0 ,
/*5*/ 1 ,'B','E', 0 , 0 , 0 , 0 ,'M', 1 , 0 ,
/*6*/ 1 , 2 , 2 , 2 , 1 , 0 , 1 , 2 , 1 , 0 ,
/*7*/ 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , 0 , 0 ,
/*8*/ 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , 0 , 0 ,
/*9*/ 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , 0 , 0 ,
/*10*/ 0 , 0 , 0 , 0 , 1 ,'D', 1 , 0 , 0 , 0 };
mBossDead = false;
mEnemy1Dead = false;
mEnemy2Dead = false;
mTreasureLooted = false;
}
void Map::update()
{
//Re-draw buffer from map copy
mMapBuffer = new int[0];
int arraySize = mMapX * mMapY;
for(int i = 0; i < arraySize; ++i)
{
mMapBuffer[i] = mLevelDesign[i];
}
//Convert player cooordinates to array standard and draw player to map.
int playerConversion = ((mPlayerY - 1) * mMapY) + (mPlayerX - 1);
mMapBuffer[playerConversion] = 'P';
//Check for changes in map.
if(mBossDead == true)
mMapBuffer[41] = 0;
if(mEnemy1Dead == true)
mMapBuffer[32] = 0;
if(mEnemy2Dead == true)
mMapBuffer[42] = 0;
}
void Map::drawMap()
{
int count = 0;
for(int y = 0; y < mMapY; ++y)
{
for(int x = 0; x < mMapX; ++x)
{
if(mMapBuffer[count] == 0)
{cout << " "; count ++;}
else if(mMapBuffer[count] == 1)
{cout << "| "; count ++;}
else if(mMapBuffer[count] == 2)
{cout << "= "; count ++;}
else if(mMapBuffer[count] == 'X')
{cout << "X "; count ++;}
else if(mMapBuffer[count] == 'D')
{cout << "D "; count ++;}
else if(mMapBuffer[count] == 'T')
{cout << "T "; count ++;}
else if(mMapBuffer[count] == 'P')
{cout << "@ "; count ++;}
else if(mMapBuffer[count] == 'M')
{cout << "$ "; count ++;}
else if (mMapBuffer[count] == 'F')
{cout << "F "; count ++;}
else if (mMapBuffer[count] == 'Q')
{cout << "Q "; count ++;}
else if(mMapBuffer[count] == 'E')
{cout << "E "; count ++;}
else if(mMapBuffer[count] == 'B')
{cout << "B "; count ++;}
else
{cout << " "; count ++;}
}
cout << endl;
}
}