EvanBlack wrote:It didn't seem that a 3x3 area was his main goal. It just seemed like he wanted a small project to begin learning more about how it all works.
Square TopLeftSquare, TopMiddleSquare, TopRightSquare,
CenterLeftSquare, CenterMiddleSquare, CenterRightSquare,
BottomLeftSquare, BottomMiddleSquare, BottomRightSquare;
// Put all the squares into an array for later use.
Square *grid[9] = { &TopLeftSquare, &TopMiddleSquare, &TopRightSquare,
&CenterLeftSquare, &CenterMiddleSquare, &CenterRightSquare,
&BottomLeftSquare, &BottomMiddleSquare, &BottomRightSquare };
int num_columns = 3;
int num_rows = 3;
int
get_cindex (int gx, int gy, int dir)
{
int x_offset = 0;
int y_offset = 0;
switch(dir)
{
case 0: // right
x_offset=(gx+1 < num_columns);
break;
case 1: // up
y_offset=-(gy-1 >= 0);
break;
case 2: // left
x_offset=-(gx-1 >= 0);
break;
case 3: // down
y_offset=(gy+1 < num_rows);
break;
}
if(x_offset+y_offset != 0) // square is valid (would return 0 if square isn't valid)
{
// gets the cloneindex of position (gx,gy)
return ((gy+y_offset)*num_columns + (gx+x_offset));
}
return -1; // does not exist
}
for (i=0;i<j;i++)
{
ThisClone = getclone2("GridSquare",i);
xx=(ThisClone->x-getclone("GridSquare.0")->x)/width; //Grid location
yy=(ThisClone->y-getclone("GridSquare.0")->y)/height;
grid[0]->SquareNumber = ThisClone->cloneindex;
grid[0]->TopSquare= grid[get_cindex (xx,yy,1)];
grid[0]->LeftSquare=grid[get_cindex (xx,yy,2)];
grid[0]->RightSquare= grid[get_cindex (xx,yy,0)];
grid[0]->BottomSquare= grid[get_cindex (xx,yy,3)];
}
Users browsing this forum: No registered users and 1 guest