Exemple #1
0
 public void paintComponent(Graphics g) {
   Graphics2D gs = (Graphics2D) g;
   // draw the background
   gs.setColor(Color.lightGray);
   gs.fillRect(0, 0, 48, 48);
   for (int i = 0; i < 4; i++) {
     for (int j = 0; j < 4; j++) {
       if (cTetrisBlock.m_blockGrid[i][j] == 1) {
         //// System.out.println(cTetrisBlock.getTetrisCoordinateX() + "  " +
         // cTetrisBlock.getTetrisCoordinateY() );
         // draw the block
         int corX = cTetrisBlock.getTetrisCoordinateX() + 10 * j;
         int corY = cTetrisBlock.getTetrisCoordinateY() + 10 * i;
         gs.setColor(new Color(100, 10, 30));
         gs.fillRect(corX, corY, 10, 10);
         // draw the outline
         gs.setColor(new Color(230, 230, 200));
         gs.drawLine(corX, corY, corX, corY + 10);
         gs.drawLine(corX, corY, corX + 10, corY);
         gs.drawLine(corX + 10, corY + 10, corX, corY + 10);
         gs.drawLine(corX + 10, corY + 10, corX + 10, corY);
       }
     }
   }
 }
Exemple #2
0
 public void dealWithDown() {
   if (!isCoordinateLock) {
     if (!isToEnd(cTetrisBlock.m_blockBottomY))
       cTetrisBlock.setCoordinateXY(
           cTetrisBlock.getTetrisCoordinateX(), cTetrisBlock.getTetrisCoordinateY() + 20);
     cGameDc.repaint();
   }
 }
Exemple #3
0
 public void dealWithRight() {
   if (!isCoordinateLock) {
     if (!isRightToEnd(cTetrisBlock.m_blockRightX))
       cTetrisBlock.setCoordinateXY(
           cTetrisBlock.getTetrisCoordinateX() + 20, cTetrisBlock.getTetrisCoordinateY());
     cGameDc.repaint();
   }
 }
Exemple #4
0
 /** the method for c++ dll */
 public void dealWithLeft() {
   System.out.println("nihaoma");
   if (!isCoordinateLock) {
     if (!isLeftToEnd(cTetrisBlock.m_blockLeftX))
       cTetrisBlock.setCoordinateXY(
           cTetrisBlock.getTetrisCoordinateX() - 20, cTetrisBlock.getTetrisCoordinateY());
     cGameDc.repaint();
   }
 }
Exemple #5
0
 /** @return */
 private boolean isGenerateLegal() {
   // TODO Auto-generated method stub
   for (int j = 0; j < 4; j++) {
     for (int k = 0; k < 4; k++) {
       if (cTetrisBlock.m_blockGrid[j][k] == 1) {
         int corX = cTetrisBlock.getTetrisCoordinateX() + k * 20;
         int corY = cTetrisBlock.getTetrisCoordinateY() + j * 20;
         if (m_blockGrid[corY / 20][corX / 20] == 1) return false;
       }
     }
   }
   return true;
 }
Exemple #6
0
 /**
  * judge whether current block can move to right
  *
  * @param blockRightX
  * @return
  */
 public boolean isRightToEnd(int[] blockRightX) {
   boolean flag = false;
   for (int i = 0; i < 4; i++) {
     int corX = blockRightX[i];
     int corY = cTetrisBlock.getTetrisCoordinateY() + 20 * i;
     if (corX == -1) continue;
     ////////// System.out.println("RightR:" + corX);
     if (corX >= DRAWPANEL_WEIGHT) {
       flag = true;
       break;
     } else if (m_blockGrid[corY / 20][(corX) / 20] == 1) {
       flag = true;
       break;
     }
   }
   return flag;
 }
Exemple #7
0
 /**
  * judge whether current block can move to left
  *
  * @param blockLeftX
  * @return
  */
 public boolean isLeftToEnd(int[] blockLeftX) {
   boolean flag = false;
   for (int i = 0; i < 4; i++) {
     int corX = blockLeftX[i];
     int corY = cTetrisBlock.getTetrisCoordinateY() + 20 * i;
     ////////// System.out.println("leftX:" + corX);
     if (corX == -1) continue;
     if (corX <= 0) {
       flag = true;
       break;
     } else if (m_blockGrid[corY / 20][(corX - 20) / 20] == 1) {
       flag = true;
       break;
     }
   }
   return flag;
 }
Exemple #8
0
  public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    // draw the background
    g2.setColor(Color.BLACK);
    g2.fillRect(0, 0, DRAWPANEL_WEIGHT, DRAWPANEL_HEIGHT);

    for (int j = 0; j < 25; j++)
      for (int k = 0; k < 15; k++)
        if (cTetrisUI.m_blockGrid[j][k] == 1) {
          int corX = 20 * k;
          int corY = 20 * j;
          g2.setColor(Color.DARK_GRAY);
          g2.fillRect(20 * k, 20 * j, BLOCK_SIZE, BLOCK_SIZE);
          g2.setColor(Color.white);
          g2.drawLine(corX, corY, corX, corY + 20);
          g2.drawLine(corX, corY, corX + 20, corY);
          g2.drawLine(corX + 20, corY + 20, corX, corY + 20);
          g2.drawLine(corX + 20, corY + 20, corX + 20, corY);
        }
    // draw the block which's on moving
    /*
    for(int j = 0;j <= 15;j ++)
    {
    	int corX = 20 * j;
    	g2.setColor(Color.white);
    	g2.drawLine(corX, 0, corX, 500);
    }
    for(int j = 0;j <= 25;j ++)
    {
    	int corY = 20*j;
    	g2.setColor(Color.white);
    	g2.drawLine(0,corY,300,corY);
    }
    for(int j = 0;j <= 4;j ++)
    {
    	int corX = cTetrisBlock.getTetrisCoordinateX() + 20 * j;
    	int corY = cTetrisBlock.getTetrisCoordinateY();
    	g2.setColor(Color.BLUE);
    	g2.drawLine(corX , corY, corX, corY + 80);
    }
    for(int j = 0;j <= 4;j ++)
    {
    	int corX = cTetrisBlock.getTetrisCoordinateX();
    	int corY = cTetrisBlock.getTetrisCoordinateY() + 20 * j;
    	g2.setColor(Color.BLUE);
    	g2.drawLine(corX , corY, corX + 80, corY);
    }
    */
    if (cTetrisUI.isGameStart) {
      if (cTetrisUI.isNextReady) {
        cTetrisUI.setNextReady(false);
        Random rdm = new Random();
        cTetrisUI.setBlockStyle(Math.abs(rdm.nextInt()) % 7 + 1);
        cTetrisUI.getNextBlockDC().setNextBlockStyle(cTetrisUI.getBlockStyle());
        //// System.out.println("block style " + cTetrisUI.getBlockStyle());
        cTetrisUI.getNextBlockDC().repaint();
      }
      for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
          if (cTetrisBlock.m_blockGrid[i][j] == 1) {
            g2.setColor(Color.white);
            int corX = cTetrisBlock.getTetrisCoordinateX() + 20 * j;
            int corY = cTetrisBlock.getTetrisCoordinateY() + 20 * i;
            g2.fillRect(corX, corY, 20, 20);
            // outline
            g2.setColor(Color.gray);
            g2.drawLine(corX, corY, corX, corY + 20);
            g2.drawLine(corX, corY, corX + 20, corY);
            g2.drawLine(corX + 20, corY + 20, corX, corY + 20);
            g2.drawLine(corX + 20, corY + 20, corX + 20, corY);
          }
        }
      }
    }
    // g2.fillRect(cTetrisBlock.getTetrisCoordinateX(),cTetrisBlock.getTetrisCoordinateY(),BLOCK_SIZE,BLOCK_SIZE);
  }