/************************************************************************************* * Copyright (C) 2007 by Oscar Martinez * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * *************************************************************************************/ public class Table { private Position startposition; private Position currentposition; private final int COLUMNS=25; private final int ROWS=20; public Cell table[][]=new Cell[ROWS][COLUMNS]; Table() { init(); } Table(int x, int y, Position finals[], Position notfrees[]) { init(); this.setnotfrees(notfrees); this.setfinals(finals); this.setstartposition(x, y); } private void init() { for(int i=0;i=ROWS||y>=COLUMNS) { System.out.println("Not valid final position"); return; } table[x][y].setisfinal(true); table[x][y].setisfree(true); } private void setnotfreeposition(int x, int y) { if (x<0||y<0||x>=ROWS||y>=COLUMNS) { System.out.println("Not valid not free position"); return; } table[x][y].setisfree(false); } public void setfinals(Position x[]) { for (int i=0;i=0;--i) { if (!table[i][y].getisfree()) return new Position(i+1,y); else if (table[i][y].getisfinal()) return new Position(i,y); } return new Position(x,y); } case DOWN: { for(int i=x+1; i=0;--i) { if (!table[x][i].getisfree()) return new Position(x,i+1); else if (table[x][i].getisfinal()) return new Position(x,i); } return new Position(x,y); } case RIGHT: { for(int i=y+1; i