Skip to content

Instantly share code, notes, and snippets.

@sims1253
Last active August 29, 2015 14:16
Show Gist options
  • Save sims1253/08dec93f90b1d4e98977 to your computer and use it in GitHub Desktop.
Save sims1253/08dec93f90b1d4e98977 to your computer and use it in GitHub Desktop.
//World.h
struct worldData
{
-int type;
int size;
};
class World
{
private:
...
std::vector<std::vector<std::unique_ptr<worldData>>> worldMap;
public:
...
void worldInitialization(const int villageCount, const int ressourceAmmount);
};
//World.cpp
void World::worldInitialization(const int _villageCount, const int _ressourceAmmount)
{
std::vector<std::vector<std::unique_ptr<worldData>>>
temp(worldSize, std::vector<std::unique_ptr<worldData>>(worldSize));
worldMap = std::move(temp);
for (int i = villageCount; i > 0; i--)
{
//TODO c++14 gives you std::make_unique
auto temp = std::unique_ptr<Village>(new Village(this));
villages.push_back(std::move(temp));
}
srand((unsigned int)time(NULL));
for (int i = 0; i < worldSize; i++)
{
for (int j = 0; j < worldSize; j++)
{
if ((rand() % 100) < ressourceAmmount)
{
worldMap[i][j]->type = rand() % NUMBER_OF_RESSOURCES;
worldMap[i][j]->size = (rand() % 100)+1 ;
}
}
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment