I am working on a C++ project which is about simulating bees in an ecosystem. We had to code an environment represented via a vector of seeds outside of the class :
Now we must make sure that each of these seeds transmits its nature (Kind : Rock, Water, Grass) to the cell of the one-dimensional array cells_ whose position it occupies. Clearly, if the seed has for position (x,y) and for nature k then the cell at position (x,y) must take the value k, except if it is a water cell (water cells do not change their nature, cannot be covered).
here are the attributs in private (among others) :
enum class Kind : short { Grass, Water, Rock };
std::vector<Kind>cells_;
struct Seed { sf::Vector2i position_;};
std::vector<Seed> seeds_;
int nbCells_; // represents the number of cells per line
// uniform() is a method that attributes random coordinates for a seed
class World {
//...
private:
int nbCells_;
float cell_size_;
//and here is the body of the method we have to code
for (unsigned int i(0); i < nbCells_-1; ++i ) {
position_ = uniform(0, nbCells_-1); }
if (cells_[i] == position_) {
switch Kind::i {
case Kind::Rock:
.cells_[i] = position_;
break;
case Kind::Grass:
.cells_[i] = position_;
break;
};
but I'm struggling with the syntax ... any ideas ? thanks !