Beispiel #1
0
 /**
 * Initialization
 */
 public void begin(){
   int bx = 0;
   int by = 0;
   int px = 0;
   int py = 0;
   for(int i = 0; i < IMG_NUM; i++){
     
     bx = BOARD_MARGIN_X + SIDE_LENGTH * (i % PIECES_PER_COL);
     by = BOARD_MARGIN_Y + SIDE_LENGTH * (i / PIECES_PER_ROW);
     px = PUZZLE_OFFSET + PUZZLE_SPACING * 
         (i % PIECES_PER_COL + 1) + SIDE_LENGTH * 
         (i % PIECES_PER_COL);
     py = PUZZLE_SPACING * (i / PIECES_PER_ROW + 1) + 
         SIDE_LENGTH * (i / PIECES_PER_ROW);
     //x,y coordination of puzzle & board pieces
     
     img[i] = getImage("p" + i + ".jpg");
     bLocation[i] = new Location(bx, by);
     pLocation[i] = new Location(px, py);
   }
   text = new Text("YOU WIN!!!", TEXT_X,
       bLocation[TEXT_LOCATION].getY(), canvas);
   text.setFontSize(FONT_SIZE);
   text.setBold(true);
   text.setColor(Color.GREEN);
   text.hide();
   
   //pass pieces objects into arrays
   for(int i = 0; i < IMG_NUM; i++){
     bp[i] = new BoardPiece(img[i], i, bLocation[i], canvas);
     pp[i] = getRandomPiece(pLocation[i], canvas);
   }
   
 }
Beispiel #2
0
 /**
  * method that will be called when mouse releases
  * @param point , the point mouse release at
  */
 public void onMouseClick(Location point){
   if(success){
   for(Piece p: bp){
     if(((BoardPiece)p).getImage().contains(point)){
       success = false;
       text.hide();
       
       //remove graphs
       for(int i = 0; i < IMG_NUM; i++){
         ((BoardPiece)bp[i]).removeFromCanvas();
         ((PuzzlePiece)pp[i]).removeFromCanvas();
       }
       
       //reassign Pieces
       bp = new Piece[IMG_NUM];
       pp = new Piece[IMG_NUM];
       for(int i = 0; i < IMG_NUM; i++){
         hasPP[i] = false;
       }
       for(int i = 0; i < IMG_NUM; i++){
         bp[i] = new BoardPiece
             (img[i], i, bLocation[i], canvas);
         pp[i] = getRandomPiece(pLocation[i], canvas);
         lockedBP[i] = false;
       }
       break;
     }
   }
   }
 }