The key thing is i need to have an access to each attribute of each point, knowing only its x and y coordinates.
So far, i came up with idea to firstly create structure for points representation.
struct point{
int x; //x coordinate
int y; //y coordinate
char symbol; //either '.'(free) or "*"(blocked)
bool visited = false; // i need this to check whether i have been there or not
};
And then i create a 2-dimensional vector of type point, and successively push back each point. I got the following code:
//n and m are dimensions of my map
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> c;
point p;
p.x = x;
p.y = y;
p.c = c;
line.push_back(p);
}
something.push_back(line);
line.clear();
}
I also need the ability to distinguish points by its symbol. Is it legit to just write like that
if (map_of_something[x][y - 1].c == '*')?
Or should i delete all this rave and switch to another approach?
Aucun commentaire:
Enregistrer un commentaire