public class Board { private float x, y; private float bWidth,bHeight; private int numTilesX, numTilesY; private float tileSize; private ArrayList pieces; private ArrayList exits; Tile[][] filled; public Board() { this(8,8,width,height); } public Board(int numX, int numY, float widthX, float heightY) { numTilesX = numX; numTilesY = numY; bWidth = widthX; bHeight = heightY; setup(); } private void setup() { float bA = (float) (numTilesX) / (float) (numTilesY); float sA = bWidth/bHeight; float bW = 0; float bH = 0; if (bA>sA) { bW = bWidth; bH = numTilesY*bW/numTilesX; } else { bH = bHeight; bW = numTilesX*bH/numTilesY; } x = (bWidth - bW)/2; y = (bHeight - bH)/2; bHeight = bH; bWidth = bW; tileSize = bWidth/numTilesX; pieces = new ArrayList(); filled = new Tile[numTilesX][numTilesY]; for (int i=0; i=numTilesX*numTilesY) return; while(!empty(x,y)) { x = (int)random(numTilesX); y = (int)random(numTilesY); } addPiece(x,y); } public void addPiece(int x, int y) { addPiece(new Piece(this,x,y), x,y); } public void addPiece(Piece p, int x, int y) { filled[x][y].add(p); p.x = x; p.y = y; pieces.add(p); } public int numPieces() { return pieces.size(); } public boolean inBounds(int x, int y) { return !(x<0 || y<0 || x>=filled.length || y>=filled[0].length); } public boolean empty(int x, int y) { if (!inBounds(x,y)) return false; return (filled[x][y].empty()); } public boolean mouseIn(int bX, int bY) { if (bX<0 || bY<0 || bX>=numTilesX || bY>=numTilesY) return false; return ((mouseX >= getSX(bX)) && (mouseX < getSX(bX+1)) && (mouseY>= getSY(bY)) && (mouseY=filled.length || y>=filled[0].length) return null; return filled[x][y]; } public void movePiece(Piece p, int x, int y) { if ((p.tickLastMoved != ticks) || (p.tickLastMoved == ticks && x == p.ox && y == p.oy)) { filled[p.x][p.y].remove(p); filled[x][y].add(p); if (p.tickLastMoved == ticks) p.tickLastMoved = -1; else { p.ox = p.x; p.oy = p.y; p.tickLastMoved = ticks; } p.x = x; p.y = y; } } public void draw() { drawBoard(); drawPieces(); } public void updateBoard() { Piece p; for (int i=0; i0) { p = (Piece) pieces.get(0); remove(p.x,p.y); } updateBoard(); } public boolean move() { Collections.shuffle(pieces); boolean b = false; Piece p; for (int i=0; i