for (int i=0; i<size; i++)
{
b[i]=bug(initMaxX,initMaxY);
//cout<<b[i].getX()<<","<<b[i].getY()<<">>";
temp.getX()==b[i].getX();
temp.getY()==b[i].getY();
b[i].move();
while (b[i].getX()==temp.getX() && b[i].getY()==temp.getY())
b[i].move();
//cout<<b[i].getX()<<","<<b[i].getY()<<endl;
}
this code loops through an array of size=size, initializing each instance of the array with random x and y values. these instances move randomly in one of 8 possible directions. Following is the class function "bug::move()"
void bug::move(){
int xMove, yMove, bMove;
xMove=rand()%3;
yMove=rand()%3;
if (alive=true){
{
if (xMove==0 && x-1>0)
x--;
if (xMove==2 && x+1<maxX)
x++;
else
x=x;
}
{
if (yMove==0 && y-1>0)
y--;
if (yMove==2 && y+1<maxY)
y++;
else
y=y;
}
}
this code works pretty well (the bugs stay in valid range), but i keep getting instances in which a bug will not move (by random chance, the values just dont change). I'm not detecting, logically, what is causing this. that is why i put in a while loop after b[i].move() to move again if the values are both the same. Which also poses a problem of my bug moving more than once (i have no code to reset the values to their previous state, i believe that re-initializing them with random values isnt an option).