⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ptetrics.java~146~

📁 JBuilder实现的具有单机
💻 JAVA~146~
📖 第 1 页 / 共 5 页
字号:
    // Sound s=new Sound("add.WAV");
    // s.start();

      if (n < 2)return;
      int add=n-1;

       int i;
       for(int nCol=0;nCol<m_nCols;nCol++)
           for(int nRow=m_nRows+3;nRow>add-1;nRow--)
           {
               m_nRivalField[nCol][nRow]=m_nRivalField[nCol][nRow-add];

           }
         for(i=0;i<4;i++)
         {
             c_curPiece[i].m_nRow+=add;
         }


       for(int k=0;k<add;k++){
       //pruduce random line
       int nRandom[] = new int[m_nCols];
       boolean bAllZero=true;
       boolean bNoZero=true;
       for(i=0;i<m_nCols;i++)
       {
           nRandom[i]=(int)(7*Math.random());
           if(nRandom[i]!=0) bAllZero=false;
           else bNoZero=false;
       }
       if(bAllZero)
       {
           nRandom[(int)(m_nCols*Math.random())]=(int)(Math.random()*6+1);
       }
       else if(bNoZero)
       {
           nRandom[(int)(m_nCols*Math.random())]=0;
       }

       //add random line
       for (int nCol = 0; nCol < m_nCols; nCol++)
           m_nRivalField[nCol][k] = nRandom[nCol];
       }

}

     public boolean checklocal(int row,int col)
     {
       if(m_nRivalField[col][row]==0) return false;
       else return true;
     }

     public boolean checkup(int row,int col)
     {
       if(m_nRivalField[col][row+1]==0) return false;
       else return true;
     }

     public boolean checkdown(int row,int col){
       if(row==0) return true;
       else if(m_nRivalField[col][row-1]==0) return false;
       else return true;
     }

    public boolean checkleft(int row,int col)
    {
      if(col==0) return true;
      else if(m_nRivalField[col-1][row]==0) return false;
      else return true;
    }

    public boolean checkright(int row,int col)
    {
      if(col==m_nCols-1) return true;
      else if(m_nRivalField[col+1][row]==0) return false;
      else return true;
    }



     public int getDeep_position(int begain,int d){
      int count=0;
      for(int nCol=begain;nCol<m_nCols;nCol++)
            for(int nRow=0;nRow<m_nRows;nRow++)
            {
              if(checkleft(nRow,nCol)&&checkright(nRow,nCol)) count++;
              if(count==d) return nCol;
            }

      return 0;

    }

    public boolean isDeep_d(int col,int d){
        int count=0;

          for(int nRow=0;nRow<m_nRows;nRow++)
          {
              if(checklocal(nRow,col)&&!check_movedown(col,col,nRow+1))
              {
                count=0;continue;
              }
              else{
                if (checkleft(nRow, col) && checkright(nRow, col)) count++;
              }
              if(count==d) return true;
          }

        return false;

    }


    public boolean isWide_num(int row,int col_begain,int num){
      int count=0;
      for(int nCol=col_begain;nCol<m_nCols;nCol++)
      {
        if(checklocal(row,nCol)) return false;
        else{
          count++;
        }
        if(count==num) return true;
      }

     return false;

    }


    public void move_to_left(int begain,int end){
      int i;
      if(begain<=end) return;
      for(i=begain;i>end;i--){
        cmoveCurPiece( -1, 0, false);
        repaint();
      }
    }

    public void move_to_right(int begain,int end){
      int i;
      if(begain>=end) return;
      for(i=begain;i<end;i++){
        cmoveCurPiece(1, 0, false);
        repaint();
      }

    }

    public boolean check_movedown(int begain_col,int end_col,int begain_row){
      if(begain_col<0&&end_col>9&&begain_col>end_col) return false;
      for(int row=begain_row;row<18;row++)
        for(int col=begain_col;col<=end_col;col++)
         if(m_nRivalField[col][row]!=0) return false;

      return true;
    }

    public boolean check_moveline(int begain_col,int end_col,int row){
      for(int col=0;col<10&&col<begain_col&&col>end_col;col++){
        if(m_nRivalField[col][row]==0) return false;
      }
      return true;

    }


     public  void adjust(int type){
       int nRow,nCol;
      // int mid=m_nCols/2;
       int after_rotate;

       switch(type){

         case 0:

           int d = 0;
           for (nCol = 0; nCol < m_nCols; nCol++)
             if (isDeep_d(nCol, 4)) {
               d = 4;
               break;
             }
           if (d == 4) {
             cmoveCurPiece(0, 0, true);
             repaint();
             after_rotate = this.c_curPiece[0].m_nColumn;
             if (nCol < after_rotate)
               move_to_left(after_rotate, nCol);
             else
               move_to_right(after_rotate, nCol);

             break;

           }

           for (nCol = 0; nCol < m_nCols; nCol++)
             if (isDeep_d(nCol, 3)) {
               d = 3;
               break;
             }
           if (d == 3) {
             cmoveCurPiece(0, 0, true);
             repaint();
             after_rotate = this.c_curPiece[0].m_nColumn;
             if (nCol < after_rotate)
               move_to_left(after_rotate, nCol);
             else
               move_to_right(after_rotate, nCol);

             break;
           }

           for (nCol = 0; nCol < m_nCols; nCol++)
             if (isDeep_d(nCol, 2)) {
               d = 2;
               break;
             }
           if (d == 2) {
             cmoveCurPiece(0, 0, true);
             repaint();
             after_rotate = this.c_curPiece[0].m_nColumn;
             if (nCol < after_rotate)
               move_to_left(after_rotate, nCol);
             else
               move_to_right(after_rotate, nCol);

             break;
           }

           for (nCol = 0; nCol < m_nCols; nCol++)
              if (this.isWide_num(0, nCol, 4)&&check_movedown(nCol,nCol+3,1)) {
               after_rotate = this.c_curPiece[0].m_nColumn;

               if (nCol < after_rotate)
                 move_to_left(after_rotate-1, nCol);
               else
                 move_to_right(after_rotate-1, nCol);
               d=5;
               break;
           }
           if(d==5) break;

           if(m_nRivalField[0][10]==0){
             cmoveCurPiece(0, 0, true);
             repaint();
             after_rotate = this.c_curPiece[0].m_nColumn;
             move_to_left(after_rotate, 0);
           }
           else {
             cmoveCurPiece(0, 0, true);
             repaint();
             after_rotate = this.c_curPiece[0].m_nColumn;
             move_to_right(after_rotate, 9);
           }
          break;

      case 1:
            stop:{
              for (nRow = 0; nRow < m_nRows; nRow++)
                for (nCol = 0; nCol < m_nCols; nCol++)
                   if (nCol < 9 && checklocal(nRow, nCol) &&
                     !checkright(nRow, nCol)&& check_movedown(nCol,nCol+1,nRow+1)
                     &&check_moveline(nCol+1,nCol+1,nRow)&&check_moveline(nCol,nCol+1,nRow+1)) {
                   cmoveCurPiece(0, 0, true);repaint();
                   after_rotate = this.c_curPiece[0].m_nColumn;
                   if (nCol < after_rotate)
                     move_to_left(after_rotate-1, nCol);
                   else
                     move_to_right(after_rotate-1, nCol);

                   break stop;
                 }
                 else if (nCol > 0 && checklocal(nRow, nCol) &&
                 !checkleft(nRow, nCol)&&check_movedown(nCol-1,nCol,nRow+1)
                 &&check_moveline(nCol-1,nCol-1,nRow)&&check_moveline(nCol-1,nCol,nRow+1)) {
                   cmoveCurPiece(0, 0, true);repaint();
                   cmoveCurPiece(0, 0, true);repaint();
                   cmoveCurPiece(0, 0, true);repaint();
                   after_rotate = this.c_curPiece[0].m_nColumn;
                   if (nCol < after_rotate)
                     move_to_left(after_rotate+1, nCol);
                   else
                     move_to_right(after_rotate+1, nCol);

                   break stop;
                 }

                 else if (nCol != 0 && nCol != 9 && checkleft(nRow, nCol) &&
                          !checklocal(nRow, nCol) &&
                          checkright(nRow, nCol)&&check_movedown(nCol-1,nCol+1,nRow+1)
                          &&check_moveline(nCol-1,nCol+1,nRow+1)&&check_moveline(nCol,nCol,nRow)) {
                   cmoveCurPiece(0, 0, true);repaint();
                   cmoveCurPiece(0, 0, true);repaint();
                   after_rotate = this.c_curPiece[0].m_nColumn;
                   if (nCol < after_rotate)
                     move_to_left(after_rotate, nCol);
                   else
                     move_to_right(after_rotate, nCol);

                   break stop;
                 }

                  // if checkdown is false
                  else if (nCol < 9 && checklocal(nRow, nCol) &&
                     !checkright(nRow, nCol)&& check_movedown(nCol,nCol+1,nRow+1)
                     &&checkdown(nRow,nCol+1)) {
                   cmoveCurPiece(0, 0, true);repaint();
                   after_rotate = this.c_curPiece[0].m_nColumn;
                   if (nCol < after_rotate)
                     move_to_left(after_rotate-1, nCol);
                   else
                     move_to_right(after_rotate-1, nCol);

                   break stop;
                 }
                 else if (nCol > 0 && checklocal(nRow, nCol) &&
                 !checkleft(nRow, nCol)&&check_movedown(nCol-1,nCol,nRow+1)
                 &&checkdown(nRow,nCol-1)) {
                   cmoveCurPiece(0, 0, true);repaint();
                   cmoveCurPiece(0, 0, true);repaint();
                   cmoveCurPiece(0, 0, true);repaint();
                   after_rotate = this.c_curPiece[0].m_nColumn;
                   if (nCol < after_rotate)
                     move_to_left(after_rotate+1, nCol);
                   else
                     move_to_right(after_rotate+1, nCol);

                   break stop;
                 }

                 else if (nCol != 0 && nCol != 9 && checkleft(nRow, nCol) &&
                          !checklocal(nRow, nCol) &&
                          checkright(nRow, nCol)&&checkdown(nRow,nCol)
                          &&check_movedown(nCol-1,nCol+1,nRow+1)) {
                   cmoveCurPiece(0, 0, true);repaint();
                   cmoveCurPiece(0, 0, true);repaint();
                   after_rotate = this.c_curPiece[0].m_nColumn;
                   if (nCol < after_rotate)
                     move_to_left(after_rotate, nCol);
                   else
                     move_to_right(after_rotate, nCol);

                   break stop;
                 }


 // if checkdown is true
                  else if (nCol < 9 && checklocal(nRow, nCol) &&
                      !checkright(nRow, nCol)&& check_movedown(nCol,nCol+1,nRow+1)) {
                    cmoveCurPiece(0, 0, true);repaint();
                    after_rotate = this.c_curPiece[0].m_nColumn;
                    if (nCol < after_rotate)
                      move_to_left(after_rotate-1, nCol);
                    else
                      move_to_right(after_rotate-1, nCol);

                    break stop;
                  }
                  else if (nCol > 0 && checklocal(nRow, nCol) &&
                  !checkleft(nRow, nCol)&&check_movedown(nCol-1,nCol,nRow+1)) {
                    cmoveCurPiece(0, 0, true);repaint();
                    cmoveCurPiece(0, 0, true);repaint();
                    cmoveCurPiece(0, 0, true);repaint();
                    after_rotate = this.c_curPiece[0].m_nColumn;
                    if (nCol < after_rotate)
                      move_to_left(after_rotate+1, nCol);
                    else
                      move_to_right(after_rotate+1, nCol);

                    break stop;
                  }

                  else if (nCol != 0 && nCol != 9 && checkleft(nRow, nCol) &&
                           !checklocal(nRow, nCol) &&
                           checkright(nRow, nCol)
                           &&check_movedown(nCol-1,nCol+1,nRow+1)) {
                    cmoveCurPiece(0, 0, true);repaint();
                    cmoveCurPiece(0, 0, true);repaint();
                    after_rotate = this.c_curPiece[0].m_nColumn;
                    if (nCol < after_rotate)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -