Código:
#include <iostream>
#include <print>
#include <string>
#include <vector>
class Map
{
public:
Map(const std::string& name, int height, int width, char tile)
: mName(name), mHeight(height), mWidth(width), mTile(tile)
{ }
Map& Initialize()
{
mMap.assign(mHeight, std::vector<char>(mWidth, mTile));
isInitialized = true;
return *this;
}
Map& Draw()
{
if(isInitialized == true)
{
for (size_t column = 0; column < mHeight; ++column)
{
for (size_t row = 0; row < mWidth; ++row)
{
std::print("{} ", mMap[column][row]);
}
std::print("\n");
}
}
else
{
std::print("ERROR: Map is not initialized!");
}
return *this;
}
private:
std::string mName{};
int mHeight{};
int mWidth{};
char mTile{};
bool isInitialized{};
std::vector<std::vector<char>> mMap;
};
int main()
{
Map test("Test", 10, 10, '.');
test.Initialize().Draw();
}