public class Grid { public static final int NORTH = 0; public static final int EAST = 1; public static final int SOUTH = 2; public static final int WEST = 3; private Square[] squares; private Psycho[] psychos; private int numPsychos; private int rows; private int cols; private int sq_width; private int sq_height; private int buffX; private int buffY; private int init_offX; private int init_offY; private int alphaReduceInc;//on squares private Psycho currPsycho; private int currSquareIndex; public Grid(int r, int c, int sq_wid, int sq_hei, int bX, int bY, int init_offsetX, int init_offsetY, int nP, int alphaInc) { rows = r; cols = c; sq_width = sq_wid; sq_height = sq_hei; buffX = bX; buffY = bY; init_offX = init_offsetX; init_offY = init_offsetY; alphaReduceInc = alphaInc; squares = new Square[rows*cols]; makeGrid(); numPsychos = nP; makePsychos(); currPsycho = psychos[0]; } public void update() { for (int i = 0;i cols-1) { currSquareIndex -= cols; } else { currSquareIndex=currSquareIndex % cols + (cols*(rows-1)); } } else if (direc == EAST) { if ((currSquareIndex % cols) < cols-1) { //println("east col: " + currSquareIndex % cols); currSquareIndex++; } else { currSquareIndex-=(cols-1); } } else if (direc == SOUTH) { if (currSquareIndex < cols * (rows-1)) { currSquareIndex += cols; } else { currSquareIndex = currSquareIndex % cols; } } else if (direc == WEST) { if ((currSquareIndex % cols) > 0) { currSquareIndex--; } else { currSquareIndex+=cols-1; } } return currSquareIndex; } public int setDirection(int compassDirec, boolean left) { //println("...."); //println("compassDirec: " + compassDirec); if (left) { //println("left"); if (compassDirec>0) { compassDirec--; }else { compassDirec = 3; } }else { //println("right"); if (compassDirec<3) { compassDirec++; }else { compassDirec = 0; } } //println("compassDirec: " + compassDirec); //println("...."); return compassDirec; } }