"Quadrant", analyze area around the square

0

I have a project and I got into a problem. The project would be a simple simcity 1 done in pure javascript. The problem is that when making crosses and curves I can not detect the next square on my grid. To learn how to solve the problem I wanted you to do the following: If I put a square the square to the left turns green, the right turns yellow, the above turns blue, the below brown and explain how it did if possible. My idea was to click to draw my square and draw 8 others around it to see if it has a square next to it.

Linktothecode: link

    
asked by anonymous 11.08.2014 / 01:37

1 answer

1

If you already know the position of the row and column, it is basic to think that: (row - 1) is in the top line and (column + 1) is in the back column, and so on ...

    dR(grid_x[i],grid_y[n-1],grid_w,grid_h,'#0018FF');
    dR(grid_x[i-1],grid_y[n],grid_w,grid_h,'#218126');
    dR(grid_x[i],grid_y[n+1],grid_w,grid_h,'#815E21');
    dR(grid_x[i+1],grid_y[n],grid_w,grid_h,'#FFC600');
    
11.08.2014 / 04:38