May someone help me with the levels. I don't know how to make and turn different levels
#include<iostream>
#include<windows.h>
using namespace std;
int ok = 1;
bool state;
what are you trying to accomplish isnt trivial, thats a lot of generalization to count. i've developed a class for you, which creates a 'map' object, which you can use to create a vector (see <vector> library) of those 'map' objects
this class constructor takes arguments the length of row and colums and the location of the text file which you want to extract your map
it has a () overloaded operator that means you can use the map type as a 2d array but instead of [] brackets you use () like this myMap(1,1) = 'T' .
it also has a print function which prints the map on screen
myMap.print();
#include<iostream>
#include<windows.h>
#include<fstream>
usingnamespace std;
class MapType
{
public:
MapType(int row, int col, constchar *txt);
MapType(const MapType &m);
~MapType();
void print();
char &operator()(int a, int b);
private:
char **ptr;
int mRow, mCol;
//private data, can't be accesed outside the class
};
MapType::MapType(int row, int col, constchar *txt)
{
//assigns some private data
mRow = row;
mCol = col;
//creates a input file type object
ifstream in(txt);
//allocates a 2D array dinamically
ptr = newchar*[row];
for (int i = 0; i < row; i++)
ptr[i] = newchar[col];
//reads from file
//remember that this method ignores white spaces ' '
//so you better f ill the map free spaces with something then modify print() function
//or replace them with spaces
for (int i = 0; i < mRow; i++)
for (int j = 0; j < mCol; j++)
in >> ptr[i][j];
in.close();
}
//copy constructor, this is applied when you copy a map onto another
MapType::MapType(const MapType &m)
{
mRow = m.mRow;
mCol = m.mCol;
ptr = newchar*[mRow];
for (int i = 0; i < mRow; i++)
ptr[i] = newchar[mCol];
for (int i = 0; i < mRow; i++)
for (int j = 0; j < mCol; j++)
ptr[i][j] = m.ptr[i][j];
}
//overloaded operator (example cout << myMap(10,12))
char & MapType::operator()(int a, int b)
{
return ptr[a][b];
}
//prints map
void MapType::print()
{
for (int i = 0; i < mRow; i++)
{
for (int j = 0; j < mCol; j++)
cout << ptr[i][j];
cout << endl;
}
}
//destructor called when program ends
//it deletes the map from memory
MapType::~MapType()
{
for (int i = 0; i < mRow; i++)
delete[] ptr[i];
delete[] ptr;
}
int main(){
MapType myMap(10, 10, "map1.txt"); //creates a 10x10 map read from map1.txt
vector<MapType> maps; //creates a vector of maps
maps.push_back(myMap); //pushes the map in the back of the vector
maps[0].print(); //prints first map
maps[0](2, 2) = '@'; //accesses the 2x2 element of the first map
maps[0].print();
return 0;
}