Exemplo n.º 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);
   }
   
 }
Exemplo n.º 2
0
	/**
	 * method that will be called when mouse clicks
	 * @param point , the point mouse click at
	 */
	public void onMouseClick(Location point) {
		if(!isShown){
			mouse = new Deadmau5(point, canvas);
			instr1.hide();
			instr2.hide();
			instr3.hide();
			isShown = true;
		}
	}
Exemplo n.º 3
0
  public void onMouseMove(Location point) {

    if (gameOn) {
      theFish.moveTo(point.getX() - theFish.getWidth() / 2, point.getY());

      lastMouse = point;
      currentScore = theFish.getScore();
      score.setText("Score: " + currentScore);
      score.moveTo((canvas.getWidth() - score.getWidth()) / 2, 50);
    }
  }
Exemplo n.º 4
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;
     }
   }
   }
 }
Exemplo n.º 5
0
 /**
  * method that will be called when mouse releases
  * @param point , the point mouse release at
  */
 public void onMouseRelease(Location point) {
   isGrabbed = false;
   if(!success){
     for(Piece p: bp){
     
       //if correctly matched
       if(p.contains(grabbedPiece.getCenter()) &&
           p.equals(grabbedPiece)){
         grabbedPiece.hide();
         p.show();
         p.showHighlight(Color.GREEN);
         lockedBP[p.getId()] = true;
       
         //check if all pieces are matched
         boolean check = true;
         for(boolean b: lockedBP){
           check = check && b;
         }
         if(check){
           success = true;
           for(Piece piece: bp){
             piece.hideHighlight();
           }
           text.show();
         }
       }
     }
   }
 }
Exemplo n.º 6
0
  // Create a FramedText object displaying the text 'contents'
  // at the position and with the dimensions specified.
  public FramedText(
      String contents, double x, double y, double width, double height, DrawingCanvas canvas) {
    // construct the frame
    super(x, y, width, height, canvas);

    // Construct and appropriately position the message
    message = new Text(contents, x, y, canvas);
    message.setColor(Color.white);
    positionContents();
  }
Exemplo n.º 7
0
  public void startGame() {

    bread.loop();
    gameOn = true;
    yellow.removeFromCanvas();
    pink.removeFromCanvas();
    purple.removeFromCanvas();
    green.removeFromCanvas();
    grey.removeFromCanvas();
    button.removeFromCanvas();
    author.removeFromCanvas();
    title.removeFromCanvas();

    start = new Location(canvas.getWidth() / 2, canvas.getHeight() / 2);
    theFish = new TheFish(fishPic, start, canvas, 50, 25);
    ocean = new Ocean(angryFishPic, angryFishL, bubblePic, canvas, theFish);

    score = new Text("Score: " + currentScore, 0, 0, canvas);
    score.setFontSize(16);
    score.moveTo((canvas.getWidth() - score.getWidth()) / 2, 50);

    bubbles = new Bubbles(dopeBubble, canvas);
  }
Exemplo n.º 8
0
 // settext
 public void setText(String text) {
   message.setText(text);
 }
Exemplo n.º 9
0
 // Change the font size used
 public void setTextSize(int size) {
   message.setFontSize(size);
   positionContents();
 }
Exemplo n.º 10
0
 // Position the message to center it in the frame
 protected void positionContents() {
   message.moveTo(displayLeft(), displayTop());
   message.move(
       (displayWidth() - message.getWidth()) / 2, (displayHeight() - message.getHeight()) / 2);
 }
Exemplo n.º 11
0
	/**
	 * method that will be called when mouse enters the boundary
	 * @param point , the point mouse enter at
	 */
	public void onMouseEnter(Location point){
		instr1.show();
		instr2.show();
		instr3.show();
	}