I have a problem with my code. Actually it works, but I want to clean it to make it more proper.
So I have a class Coord which contains a float x and a float y.
The constructor is :
void Coord::Coord (float x,float y)
{
this->x = x;
this->y = y;
}
I create all the points that I need in that way :
Coord pt1(0,1);
Coord pt2(20,0);
...
Coord pt61(12,14); .... `
After I have to make an array of some points , for exemple
the fifth five points will be assigned in an array, 4 other points in another array, 2 other points in another one…
Coord pts_weakhealth[3] = {pt1,pt2,pt3};
This array, I’ll have to give as arguments for the constructor of a class
for example:
Sef health(pts_weakhealth,3);
Sef strength(pts_weak,4);`
I’ll create some Sef in the same way and then make an array of them
Sef spec[2] = {health,strength};
and a class universe will contains some sef :
Universe hlth(spec);
You can imagine that when I have a lot of points, a lot of sef, it’s a lot of dirty code…
How can I improve that? to make my code better…
It’s hard to tell what’s being asked here… but here are a few suggestions that should get you moving in the right direction:
Don’t hard-code the point initializations. Write a routine to
read the points from a configuration or initialization file.
Don’t store them in an array. Build vectors or lists or deques of
points based on information in the configuration file.
Use the configuration file to build up your
Sefs andUniverses from previously defined points.