/** * get a unused random piece * @param point upper-left corner of the Piece */ public Piece getRandomPiece (Location point, DrawingCanvas canvas){ int rand = 0; RandomIntGenerator r = new RandomIntGenerator(0, IMG_NUM - 1); do{ rand = r.nextValue(); }while(hasPP[rand] == true); hasPP[rand] = true; //the randth img has been chosen return new PuzzlePiece(img[rand], rand, point, canvas); }
/** test stub for the class */ public static void main(String[] args) { RandomIntGenerator r1 = new RandomIntGenerator(1, 10); RandomIntGenerator r2 = new RandomIntGenerator(0, 1); int i; for (i = 1; i <= 100; i++) System.out.println(r1.draw() + " " + r2.draw()); }